Skip to content

Commit 9d4477f

Browse files
[BUGFIX] Don't deactivate already inactive deployments (#104)
#92 Mentions errors regarding deployments having the max number of statuses already set. This PR avoids this from happening, by only setting the status if the status isn't already "inactive". Co-authored-by: Robert Lin <robert@bobheadxi.dev>
1 parent cc8bbd0 commit 9d4477f

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/deactivate.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,37 @@ async function deactivateEnvironment(
2828
log.info(
2929
`${environment}.${deployment.id}: setting deployment (${deployment.sha}) state to "${deactivatedState}"`
3030
);
31-
const res = await github.rest.repos.createDeploymentStatus({
31+
32+
// Check existing status, to avoid setting it to the already current value.
33+
// See https://github.com/bobheadxi/deployments/issues/92.
34+
const getStatusRes = await github.rest.repos.listDeploymentStatuses({
35+
owner,
36+
repo,
37+
deployment_id: deployment.id,
38+
per_page: 1, // we only need the latest status
39+
});
40+
41+
// If a previous status exists, and it is inactive, then we don't need to update it.
42+
if (
43+
getStatusRes.data.length === 1 &&
44+
getStatusRes.data[0].state === deactivatedState
45+
) {
46+
log.debug(
47+
`${environment}.${deployment.id} is already ${deactivatedState}; skipping.`
48+
);
49+
continue;
50+
}
51+
52+
// Otherwise, set the deployment to "inactive".
53+
const createStatusRes = await github.rest.repos.createDeploymentStatus({
3254
owner,
3355
repo,
3456
deployment_id: deployment.id,
3557
state: deactivatedState,
3658
});
3759
log.debug(`${environment}.${deployment.id} updated`, {
38-
state: res.data.state,
39-
url: res.data.url,
60+
state: createStatusRes.data.state,
61+
url: createStatusRes.data.url,
4062
});
4163
}
4264

0 commit comments

Comments
 (0)