From 02f1f2713f9e191bd934dc86da420d0edd5b2966 Mon Sep 17 00:00:00 2001 From: dadajian Date: Thu, 29 Oct 2026 09:23:33 -0500 Subject: [PATCH 1/2] feat(notify-pipeline-complete): support custom state input Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + dist/helpers/notify-pipeline-complete.js | 11 +-- dist/helpers/notify-pipeline-complete.js.map | 6 +- src/helpers/notify-pipeline-complete.ts | 11 ++- test/helpers/notify-pipeline-complete.test.ts | 85 +++++++++++++++++++ 5 files changed, 102 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 78c2fb619..460cda407 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,7 @@ Additionally, the following parameters can be used for additional control over t ### [notify-pipeline-complete](.github/workflows/notify-pipeline-complete.yml) - Sets a "pipeline" commit status to green for all open PRs +- Pass `state` (e.g. `failure`) to report a state other than `success` on the deployment and commit statuses. Defaults to `success`. ### [prepare-queued-pr-for-merge](.github/workflows/prepare-queued-pr-for-merge.yml) diff --git a/dist/helpers/notify-pipeline-complete.js b/dist/helpers/notify-pipeline-complete.js index 077f450bd..86bd62127 100644 --- a/dist/helpers/notify-pipeline-complete.js +++ b/dist/helpers/notify-pipeline-complete.js @@ -34,7 +34,8 @@ var notifyPipelineComplete = async ({ description = DEFAULT_PIPELINE_DESCRIPTION, environment = PRODUCTION_ENVIRONMENT, target_url, - merge_queue_enabled + merge_queue_enabled, + state = "success" }) => { const { data: deployments } = await octokit.repos.listDeployments({ environment, @@ -46,7 +47,7 @@ var notifyPipelineComplete = async ({ await octokit.repos.createDeploymentStatus({ environment, deployment_id, - state: "success", + state, description, target_url, ...context.repo @@ -56,7 +57,7 @@ var notifyPipelineComplete = async ({ return import_bluebird.map(mergeQueueCommitHashes, async (sha) => octokit.repos.createCommitStatus({ sha, context: context2, - state: "success", + state, description, target_url, ...context.repo @@ -71,7 +72,7 @@ var notifyPipelineComplete = async ({ return import_bluebird.map(commitHashesForOpenPullRequests, async (sha) => octokit.repos.createCommitStatus({ sha, context: context2, - state: "success", + state, description, target_url, ...context.repo @@ -82,4 +83,4 @@ export { notifyPipelineComplete }; -//# debugId=3D89CC9C798FA26064756E2164756E21 +//# debugId=E4CDF0CE576E1DBD64756E2164756E21 diff --git a/dist/helpers/notify-pipeline-complete.js.map b/dist/helpers/notify-pipeline-complete.js.map index eea71f4f0..102f56dcf 100644 --- a/dist/helpers/notify-pipeline-complete.js.map +++ b/dist/helpers/notify-pipeline-complete.js.map @@ -2,9 +2,9 @@ "version": 3, "sources": ["../src/helpers/notify-pipeline-complete.ts"], "sourcesContent": [ - "/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { getMergeQueueCommitHashes } from '../utils/merge-queue';\n\nexport class NotifyPipelineComplete extends HelperInputs {\n declare context?: string;\n declare description?: string;\n declare environment?: string;\n declare target_url?: string;\n declare merge_queue_enabled?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n environment = PRODUCTION_ENVIRONMENT,\n target_url,\n merge_queue_enabled\n}: NotifyPipelineComplete) => {\n const { data: deployments } = await octokit.repos.listDeployments({\n environment,\n ...githubContext.repo\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (!deployment_id) return;\n await octokit.repos.createDeploymentStatus({\n environment,\n deployment_id,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo\n });\n\n if (merge_queue_enabled === 'true') {\n const mergeQueueCommitHashes = await getMergeQueueCommitHashes();\n return map(mergeQueueCommitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo\n })\n );\n }\n\n const { data: pullRequests } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);\n return map(commitHashesForOpenPullRequests, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo\n })\n );\n};\n" + "/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { DeploymentState, PipelineState } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { getMergeQueueCommitHashes } from '../utils/merge-queue';\n\nexport class NotifyPipelineComplete extends HelperInputs {\n declare context?: string;\n declare description?: string;\n declare environment?: string;\n declare target_url?: string;\n declare merge_queue_enabled?: string;\n declare state?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n environment = PRODUCTION_ENVIRONMENT,\n target_url,\n merge_queue_enabled,\n state = 'success'\n}: NotifyPipelineComplete) => {\n const { data: deployments } = await octokit.repos.listDeployments({\n environment,\n ...githubContext.repo\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (!deployment_id) return;\n await octokit.repos.createDeploymentStatus({\n environment,\n deployment_id,\n state: state as DeploymentState,\n description,\n target_url,\n ...githubContext.repo\n });\n\n if (merge_queue_enabled === 'true') {\n const mergeQueueCommitHashes = await getMergeQueueCommitHashes();\n return map(mergeQueueCommitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\n })\n );\n }\n\n const { data: pullRequests } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);\n return map(commitHashesForOpenPullRequests, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\n })\n );\n};\n" ], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;AAIO,MAAM,+BAA+B,aAAa;AAMzD;AAEO,IAAM,yBAAyB;AAAA,EACpC,oBAAU;AAAA,EACV,cAAc;AAAA,EACd,cAAc;AAAA,EACd;AAAA,EACA;AAAA,MAC4B;AAAA,EAC5B,QAAQ,MAAM,gBAAgB,MAAM,QAAQ,MAAM,gBAAgB;AAAA,IAChE;AAAA,OACG,QAAc;AAAA,EACnB,CAAC;AAAA,EACD,MAAM,gBAAgB,YAAY,KAAK,OAAO,GAAG;AAAA,EACjD,IAAI,CAAC;AAAA,IAAe;AAAA,EACpB,MAAM,QAAQ,MAAM,uBAAuB;AAAA,IACzC;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,OACG,QAAc;AAAA,EACnB,CAAC;AAAA,EAED,IAAI,wBAAwB,QAAQ;AAAA,IAClC,MAAM,yBAAyB,MAAM,0BAA0B;AAAA,IAC/D,OAAO,oBAAI,wBAAwB,OAAM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AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,SACG,QAAc;AAAA,IACnB,CAAC,CACH;AAAA,EACF;AAAA,EAEA,QAAQ,MAAM,iBAAiB,MAAM,QAAQ,MAAM,KAAK;AAAA,IACtD,OAAO;AAAA,IACP,UAAU;AAAA,OACP,QAAc;AAAA,EACnB,CAAC;AAAA,EACD,MAAM,kCAAkC,aAAa,IAAI,iBAAe,YAAY,KAAK,GAAG;AAAA,EAC5F,OAAO,oBAAI,iCAAiC,OAAM,QAChD,QAAQ,MAAM,mBAAmB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,OACG,QAAc;AAAA,EACnB,CAAC,CACH;AAAA;", + "debugId": "E4CDF0CE576E1DBD64756E2164756E21", "names": [] } \ No newline at end of file diff --git a/src/helpers/notify-pipeline-complete.ts b/src/helpers/notify-pipeline-complete.ts index f8f3f1124..aaff3aca8 100644 --- a/src/helpers/notify-pipeline-complete.ts +++ b/src/helpers/notify-pipeline-complete.ts @@ -12,6 +12,7 @@ limitations under the License. */ import { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../constants'; +import { DeploymentState, PipelineState } from '../types/github'; import { HelperInputs } from '../types/generated'; import { context as githubContext } from '@actions/github'; import { map } from 'bluebird'; @@ -24,6 +25,7 @@ export class NotifyPipelineComplete extends HelperInputs { declare environment?: string; declare target_url?: string; declare merge_queue_enabled?: string; + declare state?: string; } export const notifyPipelineComplete = async ({ @@ -31,7 +33,8 @@ export const notifyPipelineComplete = async ({ description = DEFAULT_PIPELINE_DESCRIPTION, environment = PRODUCTION_ENVIRONMENT, target_url, - merge_queue_enabled + merge_queue_enabled, + state = 'success' }: NotifyPipelineComplete) => { const { data: deployments } = await octokit.repos.listDeployments({ environment, @@ -42,7 +45,7 @@ export const notifyPipelineComplete = async ({ await octokit.repos.createDeploymentStatus({ environment, deployment_id, - state: 'success', + state: state as DeploymentState, description, target_url, ...githubContext.repo @@ -54,7 +57,7 @@ export const notifyPipelineComplete = async ({ octokit.repos.createCommitStatus({ sha, context, - state: 'success', + state: state as PipelineState, description, target_url, ...githubContext.repo @@ -72,7 +75,7 @@ export const notifyPipelineComplete = async ({ octokit.repos.createCommitStatus({ sha, context, - state: 'success', + state: state as PipelineState, description, target_url, ...githubContext.repo diff --git a/test/helpers/notify-pipeline-complete.test.ts b/test/helpers/notify-pipeline-complete.test.ts index b27ac2126..c77b9d878 100644 --- a/test/helpers/notify-pipeline-complete.test.ts +++ b/test/helpers/notify-pipeline-complete.test.ts @@ -152,4 +152,89 @@ describe('notify-pipeline-complete', () => { ...context.repo }); }); + + it('should notify with the provided state for open pull requests', async () => { + await notifyPipelineComplete({ state: 'failure' }); + + expect(octokit.repos.createCommitStatus).toHaveBeenCalledTimes(3); + expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({ + sha: 'sha 1', + context: DEFAULT_PIPELINE_STATUS, + state: 'failure', + description, + ...context.repo + }); + expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({ + sha: 'sha 2', + context: DEFAULT_PIPELINE_STATUS, + state: 'failure', + description, + ...context.repo + }); + expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({ + sha: 'sha 3', + context: DEFAULT_PIPELINE_STATUS, + state: 'failure', + description, + ...context.repo + }); + + expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({ + state: 'failure', + environment: PRODUCTION_ENVIRONMENT, + deployment_id: 123, + description, + ...context.repo + }); + }); + + it('should notify with the provided state when merge queue is enabled', async () => { + (octokit.repos.listBranches as unknown as Mock).mockImplementation(async ({ page }: { page: number }) => + page > 1 + ? { data: [] } + : { + data: [ + { + name: 'some-branch', + commit: { sha: 'normal sha 1' } + }, + { + name: 'gh-readonly-queue/default-branch/pr-123-79a5ad2b1a46f6b5d77e02573937667979635f27', + commit: { sha: 'merge queue sha 1' } + }, + { + name: 'gh-readonly-queue/default-branch/pr-456-79a5ad2b1a46f6b5d77e02573937667979635f27', + commit: { sha: 'merge queue sha 2' } + } + ] + } + ); + await notifyPipelineComplete({ merge_queue_enabled: 'true', state: 'failure' }); + + expect(octokit.pulls.list).not.toHaveBeenCalled(); + + expect(octokit.repos.createCommitStatus).toHaveBeenCalledTimes(2); + expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({ + sha: 'merge queue sha 1', + context: DEFAULT_PIPELINE_STATUS, + state: 'failure', + description, + ...context.repo + }); + expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({ + sha: 'merge queue sha 2', + context: DEFAULT_PIPELINE_STATUS, + state: 'failure', + description, + ...context.repo + }); + + expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({ + state: 'failure', + environment: PRODUCTION_ENVIRONMENT, + deployment_id: 123, + description, + ...context.repo + }); + }); }); From 3e30f079259b00cf544589cc1f989259b5246776 Mon Sep 17 00:00:00 2001 From: dadajian Date: Thu, 29 Oct 2026 09:27:30 -0500 Subject: [PATCH 2/2] feat(notify-pipeline-complete): support targeting a deployment by sha Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + dist/helpers/notify-pipeline-complete.js | 6 ++- dist/helpers/notify-pipeline-complete.js.map | 6 +-- src/helpers/notify-pipeline-complete.ts | 5 +- test/helpers/notify-pipeline-complete.test.ts | 47 +++++++++++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 460cda407..4a7d5978d 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,7 @@ Additionally, the following parameters can be used for additional control over t - Sets a "pipeline" commit status to green for all open PRs - Pass `state` (e.g. `failure`) to report a state other than `success` on the deployment and commit statuses. Defaults to `success`. +- Pass `sha` to mark the deployment for that commit instead of the newest deployment in the environment. Commit statuses are still set on open PRs (or merge queue commits when `merge_queue_enabled` is `true`). ### [prepare-queued-pr-for-merge](.github/workflows/prepare-queued-pr-for-merge.yml) diff --git a/dist/helpers/notify-pipeline-complete.js b/dist/helpers/notify-pipeline-complete.js index 86bd62127..d2e54a365 100644 --- a/dist/helpers/notify-pipeline-complete.js +++ b/dist/helpers/notify-pipeline-complete.js @@ -35,9 +35,11 @@ var notifyPipelineComplete = async ({ environment = PRODUCTION_ENVIRONMENT, target_url, merge_queue_enabled, - state = "success" + state = "success", + sha }) => { const { data: deployments } = await octokit.repos.listDeployments({ + sha, environment, ...context.repo }); @@ -83,4 +85,4 @@ export { notifyPipelineComplete }; -//# debugId=E4CDF0CE576E1DBD64756E2164756E21 +//# debugId=3185D1B530D6728564756E2164756E21 diff --git a/dist/helpers/notify-pipeline-complete.js.map b/dist/helpers/notify-pipeline-complete.js.map index 102f56dcf..684ad482f 100644 --- a/dist/helpers/notify-pipeline-complete.js.map +++ b/dist/helpers/notify-pipeline-complete.js.map @@ -2,9 +2,9 @@ "version": 3, "sources": ["../src/helpers/notify-pipeline-complete.ts"], "sourcesContent": [ - "/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { DeploymentState, PipelineState } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { getMergeQueueCommitHashes } from '../utils/merge-queue';\n\nexport class NotifyPipelineComplete extends HelperInputs {\n declare context?: string;\n declare description?: string;\n declare environment?: string;\n declare target_url?: string;\n declare merge_queue_enabled?: string;\n declare state?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n environment = PRODUCTION_ENVIRONMENT,\n target_url,\n merge_queue_enabled,\n state = 'success'\n}: NotifyPipelineComplete) => {\n const { data: deployments } = await octokit.repos.listDeployments({\n environment,\n ...githubContext.repo\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (!deployment_id) return;\n await octokit.repos.createDeploymentStatus({\n environment,\n deployment_id,\n state: state as DeploymentState,\n description,\n target_url,\n ...githubContext.repo\n });\n\n if (merge_queue_enabled === 'true') {\n const mergeQueueCommitHashes = await getMergeQueueCommitHashes();\n return map(mergeQueueCommitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\n })\n );\n }\n\n const { data: pullRequests } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);\n return map(commitHashesForOpenPullRequests, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\n })\n );\n};\n" + "/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { DeploymentState, PipelineState } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { getMergeQueueCommitHashes } from '../utils/merge-queue';\n\nexport class NotifyPipelineComplete extends HelperInputs {\n declare context?: string;\n declare description?: string;\n declare environment?: string;\n declare target_url?: string;\n declare merge_queue_enabled?: string;\n declare state?: string;\n declare sha?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n environment = PRODUCTION_ENVIRONMENT,\n target_url,\n merge_queue_enabled,\n state = 'success',\n sha\n}: NotifyPipelineComplete) => {\n const { data: deployments } = await octokit.repos.listDeployments({\n sha,\n environment,\n ...githubContext.repo\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (!deployment_id) return;\n await octokit.repos.createDeploymentStatus({\n environment,\n deployment_id,\n state: state as DeploymentState,\n description,\n target_url,\n ...githubContext.repo\n });\n\n if (merge_queue_enabled === 'true') {\n const mergeQueueCommitHashes = await getMergeQueueCommitHashes();\n return map(mergeQueueCommitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\n })\n );\n }\n\n const { data: pullRequests } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);\n return map(commitHashesForOpenPullRequests, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\n })\n );\n};\n" ], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;AAIO,MAAM,+BAA+B,aAAa;AAOzD;AAEO,IAAM,yBAAyB;AAAA,EACpC,oBAAU;AAAA,EACV,cAAc;AAAA,EACd,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,MACoB;AAAA,EAC5B,QAAQ,MAAM,gBAAgB,MAAM,QAAQ,MAAM,gBAAgB;AAAA,IAChE;AAAA,OACG,QAAc;AAAA,EACnB,CAAC;AAAA,EACD,MAAM,gBAAgB,YAAY,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D,IAAI,CAAC;AAAA,IAAe;AAAA,EACpB,MAAM,QAAQ,MAAM,uBAAuB;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,OACG,QAAc;AAAA,EACnB,CAAC;AAAA,EAED,IAAI,wBAAwB,QAAQ;AAAA,IAClC,MAAM,yBAAyB,MAAM,0BAA0B;AAAA,IAC/D,OAAO,oBAAI,wBAAwB,OAAM,QACvC,QAAQ,MAAM,mBAAmB;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,SACG,QAAc;AAAA,IACnB,CAAC,CACH;AAAA,EACF;AAAA,EAEA,QAAQ,MAAM,iBAAiB,MAAM,QAAQ,MAAM,KAAK;AAAA,IACtD,OAAO;AAAA,IACP,UAAU;AAAA,OACP,QAAc;AAAA,EACnB,CAAC;AAAA,EACD,MAAM,kCAAkC,aAAa,IAAI,iBAAe,YAAY,KAAK,GAAG;AAAA,EAC5F,OAAO,oBAAI,iCAAiC,OAAM,QAChD,QAAQ,MAAM,mBAAmB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,OACG,QAAc;AAAA,EACnB,CAAC,CACH;AAAA;", + "debugId": "3185D1B530D6728564756E2164756E21", "names": [] } \ No newline at end of file diff --git a/src/helpers/notify-pipeline-complete.ts b/src/helpers/notify-pipeline-complete.ts index aaff3aca8..bfd67adea 100644 --- a/src/helpers/notify-pipeline-complete.ts +++ b/src/helpers/notify-pipeline-complete.ts @@ -26,6 +26,7 @@ export class NotifyPipelineComplete extends HelperInputs { declare target_url?: string; declare merge_queue_enabled?: string; declare state?: string; + declare sha?: string; } export const notifyPipelineComplete = async ({ @@ -34,9 +35,11 @@ export const notifyPipelineComplete = async ({ environment = PRODUCTION_ENVIRONMENT, target_url, merge_queue_enabled, - state = 'success' + state = 'success', + sha }: NotifyPipelineComplete) => { const { data: deployments } = await octokit.repos.listDeployments({ + sha, environment, ...githubContext.repo }); diff --git a/test/helpers/notify-pipeline-complete.test.ts b/test/helpers/notify-pipeline-complete.test.ts index c77b9d878..844254dcb 100644 --- a/test/helpers/notify-pipeline-complete.test.ts +++ b/test/helpers/notify-pipeline-complete.test.ts @@ -237,4 +237,51 @@ describe('notify-pipeline-complete', () => { ...context.repo }); }); + + it('should list deployments without a sha when none is provided', async () => { + await notifyPipelineComplete({}); + + expect(octokit.repos.listDeployments).toHaveBeenCalledWith({ + environment: PRODUCTION_ENVIRONMENT, + ...context.repo + }); + expect(octokit.repos.listDeployments).not.toHaveBeenCalledWith(expect.objectContaining({ sha: expect.anything() })); + }); + + it('should mark the deployment for the provided sha', async () => { + (octokit.repos.listDeployments as unknown as Mock).mockImplementationOnce(async () => ({ + data: [{ id: 456, environment: 'production' }] + })); + await notifyPipelineComplete({ sha: 'target sha', state: 'failure' }); + + expect(octokit.repos.listDeployments).toHaveBeenCalledWith({ + sha: 'target sha', + environment: PRODUCTION_ENVIRONMENT, + ...context.repo + }); + + expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({ + state: 'failure', + environment: PRODUCTION_ENVIRONMENT, + deployment_id: 456, + description, + ...context.repo + }); + + expect(octokit.repos.createCommitStatus).toHaveBeenCalledTimes(3); + expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({ + sha: 'sha 1', + context: DEFAULT_PIPELINE_STATUS, + state: 'failure', + description, + ...context.repo + }); + expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({ + sha: 'target sha', + context: DEFAULT_PIPELINE_STATUS, + state: 'failure', + description, + ...context.repo + }); + }); });