Skip to content

🚀 CreatePackage

Submits (registers) a new package on Packagist, triggering the first metadata crawl.

When to use

🚀 After releasing a new open-source package, submit it to Packagist so it becomes available via composer require; 🤖 register packages in an automated release pipeline; 🔄 re-submit a package that was previously deleted.

Signature

go
func (c *ComposerClient) CreatePackage(ctx context.Context, request *domain.PackageCreateRequest) (*domain.PackageCreateResponse, error)

Parameters

ParameterTypeDescription
ctxcontext.ContextContext, used for timeout and cancellation
request*domain.PackageCreateRequestRequest body; the Repository field is the repository URL

Return value

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

Corresponding endpoint (POST): https://packagist.org/api/create-package?username={u}&apiToken={t}.

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

Advanced

Credentials required

This method checks username / apiToken before calling and returns an error immediately if either is empty. Configure them via the WithAPICredentials option. The credentials appear as query parameters in the URL, so make sure to redact them in logs.

  • ✏️ To change the repository URL of an existing package, use EditPackage.
  • 🔄 To trigger a re-crawl of an existing package, use UpdatePackage.
  • 📦 To query the status after submission, use GetPackage.

Released under the MIT License