Skip to content

Commit

Permalink
fix(delete-env): proper warning on 404 (#159)
Browse files Browse the repository at this point in the history
When we get a 404 deleting an environment there should be a better
warning than "unexpected error encountered: HttpError: Not Found"
Document in the readme that the user for the PAT must have admin on the
repo, not just write or manage.

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
  • Loading branch information
mtfurlan and bobheadxi authored Mar 26, 2024
1 parent f463011 commit 648679e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dist/* linguist-generated
dist/* linguist-generated -diff
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.

24 changes: 18 additions & 6 deletions src/lib/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,24 @@ async function deleteEnvironment(
log.info(`${environment}: ${existing} deployments deleted`);
}

await github.rest.repos.deleteAnEnvironment({
owner: context.owner,
repo: context.repo,
environment_name: environment,
});
log.info(`${environment}: environment deleted`);
log.info(`deleting environment: "${environment}"`);
try {
await github.rest.repos.deleteAnEnvironment({
owner: context.owner,
repo: context.repo,
environment_name: environment,
});
log.info(`${environment}: environment deleted`);
} catch (error: any) {
if ("status" in error && error.status == 404) {
log.fail(
`got a 404 deleting ${environment}, check that your PAT has repo scope and that the pat user is an admin`
);
} else {
log.fail(`error while deleting ${environment}: ${error}`);
log.debug(error);
}
}
}

export default deleteEnvironment;

0 comments on commit 648679e

Please sign in to comment.