Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Don't deactivate already inactive deployments #104

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,180 changes: 9,178 additions & 2 deletions 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.

23 changes: 20 additions & 3 deletions src/lib/deactivate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ 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