Skip to content

Commit

Permalink
[BUGFIX] Don't deactivate already inactive deployments (#104)
Browse files Browse the repository at this point in the history
#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 <[email protected]>
  • Loading branch information
paullarsen-unlikely and bobheadxi authored Jun 22, 2022
1 parent cc8bbd0 commit 9d4477f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions src/lib/deactivate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,37 @@ async function deactivateEnvironment(
log.info(
`${environment}.${deployment.id}: setting deployment (${deployment.sha}) state to "${deactivatedState}"`
);
const res = await github.rest.repos.createDeploymentStatus({

// Check existing status, to avoid setting it to the already current value.
// See https://github.com/bobheadxi/deployments/issues/92.
const getStatusRes = await github.rest.repos.listDeploymentStatuses({
owner,
repo,
deployment_id: deployment.id,
per_page: 1, // we only need the latest status
});

// If a previous status exists, and it is inactive, then we don't need to update it.
if (
getStatusRes.data.length === 1 &&
getStatusRes.data[0].state === deactivatedState
) {
log.debug(
`${environment}.${deployment.id} is already ${deactivatedState}; skipping.`
);
continue;
}

// Otherwise, set the deployment to "inactive".
const createStatusRes = await github.rest.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.id,
state: deactivatedState,
});
log.debug(`${environment}.${deployment.id} updated`, {
state: res.data.state,
url: res.data.url,
state: createStatusRes.data.state,
url: createStatusRes.data.url,
});
}

Expand Down

0 comments on commit 9d4477f

Please sign in to comment.