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
18 changes: 18 additions & 0 deletions pkg/github/minimal_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ type MinimalBranch struct {
Protected bool `json:"protected"`
}

// MinimalTag is the trimmed output type for tag objects.
type MinimalTag struct {
Name string `json:"name"`
SHA string `json:"sha"`
}

// MinimalResponse represents a minimal response for all CRUD operations.
// Success is implicit in the HTTP response status, and all other information
// can be derived from the URL or fetched separately if needed.
Expand Down Expand Up @@ -702,6 +708,18 @@ func convertToMinimalBranch(branch *github.Branch) MinimalBranch {
}
}

func convertToMinimalTag(tag *github.RepositoryTag) MinimalTag {
m := MinimalTag{
Name: tag.GetName(),
}

if commit := tag.GetCommit(); commit != nil {
m.SHA = commit.GetSHA()
}

return m
}

// MinimalCheckRun is the trimmed output type for check run objects.
type MinimalCheckRun struct {
ID int64 `json:"id"`
Expand Down
9 changes: 8 additions & 1 deletion pkg/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,14 @@ func ListTags(t translations.TranslationHelperFunc) inventory.ServerTool {
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list tags", resp, body), nil, nil
}

r, err := json.Marshal(tags)
minimalTags := make([]MinimalTag, 0, len(tags))
for _, tag := range tags {
if tag != nil {
minimalTags = append(minimalTags, convertToMinimalTag(tag))
}
}

r, err := json.Marshal(minimalTags)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal response: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/github/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2791,15 +2791,15 @@ func Test_ListTags(t *testing.T) {
textContent := getTextResult(t, result)

// Parse and verify the result
var returnedTags []*github.RepositoryTag
var returnedTags []MinimalTag
err = json.Unmarshal([]byte(textContent.Text), &returnedTags)
require.NoError(t, err)

// Verify each tag
require.Equal(t, len(tc.expectedTags), len(returnedTags))
for i, expectedTag := range tc.expectedTags {
assert.Equal(t, *expectedTag.Name, *returnedTags[i].Name)
assert.Equal(t, *expectedTag.Commit.SHA, *returnedTags[i].Commit.SHA)
assert.Equal(t, *expectedTag.Name, returnedTags[i].Name)
assert.Equal(t, *expectedTag.Commit.SHA, returnedTags[i].SHA)
}
})
}
Expand Down