diff --git a/pkg/github/__toolsnaps__/get_label.snap b/pkg/github/__toolsnaps__/get_label.snap index 6cd1ddb6aa..50a2081f5d 100644 --- a/pkg/github/__toolsnaps__/get_label.snap +++ b/pkg/github/__toolsnaps__/get_label.snap @@ -38,11 +38,15 @@ "description": { "type": "string" }, + "id": { + "type": "string" + }, "name": { "type": "string" } }, "required": [ + "id", "name", "color", "description" diff --git a/pkg/github/__toolsnaps__/list_label.snap b/pkg/github/__toolsnaps__/list_label.snap index 80e898b71b..e4c1665e9e 100644 --- a/pkg/github/__toolsnaps__/list_label.snap +++ b/pkg/github/__toolsnaps__/list_label.snap @@ -47,11 +47,15 @@ "description": { "type": "string" }, + "id": { + "type": "string" + }, "name": { "type": "string" } }, "required": [ + "id", "name", "color", "description" diff --git a/pkg/github/typed_governance_outputs.go b/pkg/github/typed_governance_outputs.go index 02952bac0b..d67e5daa2f 100644 --- a/pkg/github/typed_governance_outputs.go +++ b/pkg/github/typed_governance_outputs.go @@ -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"` diff --git a/pkg/github/typed_governance_outputs_test.go b/pkg/github/typed_governance_outputs_test.go index 094de91547..3e22973d16 100644 --- a/pkg/github/typed_governance_outputs_test.go +++ b/pkg/github/typed_governance_outputs_test.go @@ -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"]) @@ -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)