Skip to content
Open
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
4 changes: 4 additions & 0 deletions pkg/github/__toolsnaps__/get_label.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name",
"color",
"description"
Expand Down
4 changes: 4 additions & 0 deletions pkg/github/__toolsnaps__/list_label.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name",
"color",
"description"
Expand Down
1 change: 1 addition & 0 deletions pkg/github/typed_governance_outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

type MinimalLabel struct {
ID string `json:"id"`
Name string `json:"name"`
Color string `json:"color" jsonschema:"Hex RGB without leading #."`
Description string `json:"description"`
Expand Down
24 changes: 22 additions & 2 deletions pkg/github/typed_governance_outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func assertGovernanceProjection(t *testing.T, tc governanceWireCase, output any)
}
switch tc.tool.Tool.Name {
case "get_label":
assert.JSONEq(t, `{"name":"bug","color":"ff0000","description":"desc"}`, mustMarshalJSON(t, output))
assert.JSONEq(t, `{"id":"L1","name":"bug","color":"ff0000","description":"desc"}`, mustMarshalJSON(t, output))
case "list_label":
assert.JSONEq(t, `{"labels":[{"name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`, mustMarshalJSON(t, output))
assert.JSONEq(t, `{"labels":[{"id":"L1","name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`, mustMarshalJSON(t, output))
case "label_write":
assert.Equal(t, tc.args["method"], object["method"])
assert.Equal(t, tc.text, object["message"])
Expand Down Expand Up @@ -598,6 +598,26 @@ func TestTypedGovernanceLabelRetainsIFCMetadata(t *testing.T) {
}
}

func TestListLabelsOutputPreservesLabelID(t *testing.T) {
t.Parallel()

legacy := []byte(`{"labels":[{"id":"MDExOlB1bGxSZXBvc2l0b3J5TGFiZWwx","name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`)
output, err := decodeGovernanceJSON[ListLabelsOutput](legacy, nil)
require.NoError(t, err)
require.Len(t, output.Labels, 1)

encoded, err := json.Marshal(output)
require.NoError(t, err)
assert.JSONEq(t, string(legacy), string(encoded))

// A payload without an id still decodes.
withoutID := []byte(`{"labels":[{"name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`)
output, err = decodeGovernanceJSON[ListLabelsOutput](withoutID, nil)
require.NoError(t, err)
require.Len(t, output.Labels, 1)
assert.Equal(t, "bug", output.Labels[0].Name)
}

func TestTypedGetLabelToolsetVariant(t *testing.T) {
issuesTool := GetLabel(translations.NullTranslationHelper)
labelsTool := GetLabelForLabelsToolset(translations.NullTranslationHelper)
Expand Down