Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 68 additions & 14 deletions pkg/registrybroker/skills_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package registrybroker

import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -49,26 +50,46 @@ func (c *RegistryBrokerClient) GetSkillStatusByRepo(
return response, err
}

func (c *RegistryBrokerClient) UploadSkillPreviewFromGithubOIDC(
func (c *RegistryBrokerClient) QuoteSkillPublishPreview(
ctx context.Context,
token string,
report *SkillPreviewReport,
) (SkillPreviewRecord, error) {
if err := ensureNonEmpty(token, "token"); err != nil {
return SkillPreviewRecord{}, err
request *SkillQuotePreviewRequest,
) (SkillQuotePreviewResponse, error) {
if request == nil {
return SkillQuotePreviewResponse{}, fmt.Errorf("request is required")
}
if report == nil {
return SkillPreviewRecord{}, ensureNonEmpty("", "report")
if request.FileCount <= 0 {
return SkillQuotePreviewResponse{}, fmt.Errorf("fileCount must be greater than 0")
}
var response SkillPreviewRecord
if request.TotalBytes <= 0 {
return SkillQuotePreviewResponse{}, fmt.Errorf("totalBytes must be greater than 0")
}
var response SkillQuotePreviewResponse
err := c.requestTypedJSON(
ctx,
http.MethodPost,
"/skills/preview/github-oidc",
report,
map[string]string{
"authorization": "Bearer " + token,
},
"/skills/quote-preview",
request,
nil,
&response,
)
return response, err
}

func (c *RegistryBrokerClient) GetSkillConversionSignalsByRepo(
ctx context.Context,
request SkillPreviewByRepoRequest,
) (SkillConversionSignalsResponse, error) {
query, err := skillPreviewRepoQuery(request)
if err != nil {
return SkillConversionSignalsResponse{}, err
}
var response SkillConversionSignalsResponse
err = c.requestTypedJSON(
ctx,
http.MethodGet,
pathWithQuery("/skills/conversion-signals/by-repo", query),
nil,
nil,
&response,
)
return response, err
Expand Down Expand Up @@ -135,6 +156,39 @@ func (c *RegistryBrokerClient) GetSkillPreviewByID(
return response, err
}

func (c *RegistryBrokerClient) UploadSkillPreviewFromGithubOIDC(
ctx context.Context,
token string,
report *SkillPreviewReport,
) (SkillPreviewRecord, error) {
if err := ensureNonEmpty(token, "token"); err != nil {
return SkillPreviewRecord{}, err
}
if report == nil {
return SkillPreviewRecord{}, ensureNonEmpty("", "report")
}
var response SkillPreviewRecord
err := c.requestTypedJSON(
ctx,
http.MethodPost,
"/skills/preview/github-oidc",
report,
map[string]string{
"authorization": "Bearer " + strings.TrimSpace(token),
},
&response,
)
return response, err
}

func (c *RegistryBrokerClient) UploadSkillPreviewFromGitHubOIDC(
ctx context.Context,
token string,
report *SkillPreviewReport,
) (SkillPreviewRecord, error) {
return c.UploadSkillPreviewFromGithubOIDC(ctx, token, report)
}

func skillPreviewRepoQuery(request SkillPreviewByRepoRequest) (url.Values, error) {
if err := ensureNonEmpty(request.Repo, "repo"); err != nil {
return nil, err
Expand Down
47 changes: 47 additions & 0 deletions pkg/registrybroker/skills_status_live_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package registrybroker

import (
"context"
"os"
"testing"
)

func TestLiveSkillGrowthEndpoints(t *testing.T) {
if os.Getenv("HASHNET_LIVE_TESTS") != "1" {
t.Skip("set HASHNET_LIVE_TESTS=1 to run live registry broker checks")
}

client, err := NewRegistryBrokerClient(RegistryBrokerClientOptions{
BaseURL: "https://hol.org/registry/api/v1",
})
if err != nil {
t.Fatalf("failed to create client: %v", err)
}

quote, err := client.QuoteSkillPublishPreview(context.Background(), &SkillQuotePreviewRequest{
FileCount: 2,
TotalBytes: 3072,
Name: "registry-broker",
Version: "1.2.3",
RepoURL: "https://github.com/hashgraph-online/registry-broker-skill",
SkillDir: ".",
})
if err != nil {
t.Fatalf("quote skill publish preview failed: %v", err)
}
if quote.EstimatedCredits.Min <= 0 || quote.EstimatedCredits.Max <= 0 {
t.Fatalf("unexpected quote response %#v", quote)
}

signals, err := client.GetSkillConversionSignalsByRepo(context.Background(), SkillPreviewByRepoRequest{
Repo: "https://github.com/hashgraph-online/registry-broker-skills",
SkillDir: ".",
Ref: "refs/heads/main",
})
if err != nil {
t.Fatalf("get skill conversion signals by repo failed: %v", err)
}
if signals.TrustTier == "" {
t.Fatalf("expected trust tier in live response")
}
}
Loading
Loading