diff --git a/.github/workflows/daily-file-diet.lock.yml b/.github/workflows/daily-file-diet.lock.yml index d45972f966..b2a6de59a0 100644 --- a/.github/workflows/daily-file-diet.lock.yml +++ b/.github/workflows/daily-file-diet.lock.yml @@ -10572,6 +10572,7 @@ jobs: options { id name + color } } } @@ -10667,8 +10668,8 @@ jobs: if (!option) { try { const allOptions = [ - ...field.options.map(o => ({ name: o.name, description: "" })), - { name: String(fieldValue), description: "" }, + ...field.options.map(o => ({ name: o.name, description: "", color: o.color || "GRAY" })), + { name: String(fieldValue), description: "", color: "GRAY" }, ]; const createOptionResult = await github.graphql( `mutation($fieldId: ID!, $fieldName: String!, $options: [ProjectV2SingleSelectFieldOptionInput!]!) { diff --git a/.github/workflows/go-file-size-reduction.campaign.g.lock.yml b/.github/workflows/go-file-size-reduction.campaign.g.lock.yml index 0a4c933860..29ee83b8c7 100644 --- a/.github/workflows/go-file-size-reduction.campaign.g.lock.yml +++ b/.github/workflows/go-file-size-reduction.campaign.g.lock.yml @@ -8129,6 +8129,7 @@ jobs: options { id name + color } } } @@ -8224,8 +8225,8 @@ jobs: if (!option) { try { const allOptions = [ - ...field.options.map(o => ({ name: o.name, description: "" })), - { name: String(fieldValue), description: "" }, + ...field.options.map(o => ({ name: o.name, description: "", color: o.color || "GRAY" })), + { name: String(fieldValue), description: "", color: "GRAY" }, ]; const createOptionResult = await github.graphql( `mutation($fieldId: ID!, $fieldName: String!, $options: [ProjectV2SingleSelectFieldOptionInput!]!) { diff --git a/pkg/workflow/js/update_project.cjs b/pkg/workflow/js/update_project.cjs index d069e1d8be..99008ef3e6 100644 --- a/pkg/workflow/js/update_project.cjs +++ b/pkg/workflow/js/update_project.cjs @@ -609,6 +609,7 @@ async function updateProject(output) { options { id name + color } } } @@ -718,8 +719,8 @@ async function updateProject(output) { try { // Build options array with existing options plus the new one const allOptions = [ - ...field.options.map(o => ({ name: o.name, description: "" })), - { name: String(fieldValue), description: "" }, + ...field.options.map(o => ({ name: o.name, description: "", color: o.color || "GRAY" })), + { name: String(fieldValue), description: "", color: "GRAY" }, ]; const createOptionResult = await github.graphql( diff --git a/pkg/workflow/js/update_project.test.cjs b/pkg/workflow/js/update_project.test.cjs index 904f75f23b..9a7d2214cb 100644 --- a/pkg/workflow/js/update_project.test.cjs +++ b/pkg/workflow/js/update_project.test.cjs @@ -408,6 +408,73 @@ describe("updateProject", () => { expect(updateCall).toBeDefined(); }); + it("creates a new option in single select field with colors for existing options", async () => { + const projectUrl = "https://github.com/orgs/testowner/projects/60"; + const output = { + type: "update_project", + project: projectUrl, + content_type: "issue", + content_number: 16, + fields: { Status: "Closed - Not Planned" }, + }; + + queueResponses([ + repoResponse(), + viewerResponse(), + orgProjectV2Response(projectUrl, 60, "project-status"), + linkResponse, + issueResponse("issue-id-16"), + existingItemResponse("issue-id-16", "item-status"), + fieldsResponse([ + { + id: "field-status", + name: "Status", + options: [ + { id: "opt-todo", name: "Todo", color: "GRAY" }, + { id: "opt-in-progress", name: "In Progress", color: "YELLOW" }, + { id: "opt-done", name: "Done", color: "GREEN" }, + { id: "opt-closed", name: "Closed", color: "PURPLE" }, + ], + }, + ]), + // Response for updateProjectV2Field mutation + { + updateProjectV2Field: { + projectV2Field: { + id: "field-status", + options: [ + { id: "opt-todo", name: "Todo" }, + { id: "opt-in-progress", name: "In Progress" }, + { id: "opt-done", name: "Done" }, + { id: "opt-closed", name: "Closed" }, + { id: "opt-closed-not-planned", name: "Closed - Not Planned" }, + ], + }, + }, + }, + updateFieldValueResponse(), + ]); + + await updateProject(output); + + // Find the updateProjectV2Field mutation call + const updateFieldCall = mockGithub.graphql.mock.calls.find(([query]) => query.includes("updateProjectV2Field")); + expect(updateFieldCall).toBeDefined(); + + // Verify that the mutation includes color for all options + const options = updateFieldCall[1].options; + expect(options).toHaveLength(5); // 4 existing + 1 new + + // Check that all existing options have their colors preserved + expect(options[0]).toEqual({ name: "Todo", description: "", color: "GRAY" }); + expect(options[1]).toEqual({ name: "In Progress", description: "", color: "YELLOW" }); + expect(options[2]).toEqual({ name: "Done", description: "", color: "GREEN" }); + expect(options[3]).toEqual({ name: "Closed", description: "", color: "PURPLE" }); + + // Check that the new option has a default color + expect(options[4]).toEqual({ name: "Closed - Not Planned", description: "", color: "GRAY" }); + }); + it("warns when a field cannot be created", async () => { const projectUrl = "https://github.com/orgs/testowner/projects/60"; const output = {