Skip to content

✏️ EditPackage

Edits the repository URL of an existing package on Packagist.

When to use

✏️ Update the source on Packagist after migrating a package to a new repository; 🧹 correct an incorrect repository URL; 🔄 sync the pointer after a repository is renamed.

Signature

go
func (c *ComposerClient) EditPackage(ctx context.Context, packageName string, request *domain.PackageEditRequest) (*domain.PackageEditResponse, error)

Parameters

ParameterTypeDescription
ctxcontext.ContextContext, used for timeout and cancellation
packageNamestringThe package name to edit, e.g. your-org/your-package
request*domain.PackageEditRequestRequest body; the Repository field is the new repository URL

Return value

ValueTypeDescription
Result*domain.PackageEditResponseContains a Status field indicating the operation status
ErrorerrorReturned when credentials are missing, on HTTP failure, non-200 status, or JSON parse failure

Corresponding endpoint (PUT): https://packagist.org/api/packages/{name}?username={u}&apiToken={t}. The SDK URL-encodes packageName.

Example

go
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.PackageEditRequest{
		Repository: "https://github.com/your-org/your-package-new",
	}
	resp, err := c.EditPackage(context.Background(), "your-org/your-package", req)
	if err != nil {
		log.Fatalf("edit failed: %v", err)
	}
	fmt.Printf("Status: %s\n", resp.Status)
}

Advanced

Credentials and permissions

This method requires API credentials (WithAPICredentials), and the current user must be a maintainer of the package, otherwise the server will reject the request. The PUT request overwrites the repository URL field entirely.

  • 🚀 To submit a new package for the first time, use CreatePackage.
  • 🔄 To only trigger a re-crawl (without changing the repository), use UpdatePackage.
  • 📦 To verify after editing, use GetPackage.

Released under the MIT License