🔄 UpdatePackage
Triggers Packagist to re-crawl metadata for an existing package (without changing the repository URL).
When to use
🔄 After pushing a new tag or releasing a new version, proactively notify Packagist to refresh; ⏱️ manually trigger an update when a webhook fails; 🤖 at the end of a release pipeline, ensure metadata is synced in time.
Signature
func (c *ComposerClient) UpdatePackage(ctx context.Context, request *domain.PackageUpdateRequest) (*domain.PackageUpdateResponse, error)Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | context.Context | Context, used for timeout and cancellation |
request | *domain.PackageUpdateRequest | Request body; the Repository field is the repository URL |
Return value
| Value | Type | Description |
|---|---|---|
| Result | *domain.PackageUpdateResponse | Contains Status and Jobs (the list of triggered crawl job IDs) |
| Error | error | Returned when credentials are missing, on HTTP failure, non-200 status, or JSON parse failure |
Corresponding endpoint (POST): https://packagist.org/api/update-package?username={u}&apiToken={t}.
Example
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/scagogogo/composer-skills/pkg/client"
"github.com/scagogogo/composer-skills/pkg/domain"
)
func main() {
c := client.NewComposerClient(
30*time.Second,
client.WithAPICredentials("your-username", "your-api-token"),
)
req := &domain.PackageUpdateRequest{
Repository: "https://github.com/your-org/your-package",
}
resp, err := c.UpdatePackage(context.Background(), req)
if err != nil {
log.Fatalf("update failed: %v", err)
}
fmt.Printf("Status: %s\n", resp.Status)
for _, job := range resp.Jobs {
fmt.Println("Job:", job)
}
}Advanced
Difference from EditPackage
UpdatePackage uses POST to trigger a re-crawl without changing the repository URL; EditPackage uses PUT to overwrite the repository URL. If you only want to refresh versions, prefer this method.
Credentials required
This method checks username / apiToken before calling and returns an error immediately if either is empty. Configure them via WithAPICredentials.
- 🚀 To register a new package for the first time, use
CreatePackage. - ✏️ To change the repository URL, use
EditPackage. - 📦 To verify the new version after updating, use
GetPackageorGetPackageStats.