Skip to content

Commit 648679e

Browse files
mtfurlanbobheadxi
andauthored
fix(delete-env): proper warning on 404 (#159)
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 <[email protected]>
1 parent f463011 commit 648679e

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dist/* linguist-generated
1+
dist/* linguist-generated -diff

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/delete.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@ async function deleteEnvironment(
3636
log.info(`${environment}: ${existing} deployments deleted`);
3737
}
3838

39-
await github.rest.repos.deleteAnEnvironment({
40-
owner: context.owner,
41-
repo: context.repo,
42-
environment_name: environment,
43-
});
44-
log.info(`${environment}: environment deleted`);
39+
log.info(`deleting environment: "${environment}"`);
40+
try {
41+
await github.rest.repos.deleteAnEnvironment({
42+
owner: context.owner,
43+
repo: context.repo,
44+
environment_name: environment,
45+
});
46+
log.info(`${environment}: environment deleted`);
47+
} catch (error: any) {
48+
if ("status" in error && error.status == 404) {
49+
log.fail(
50+
`got a 404 deleting ${environment}, check that your PAT has repo scope and that the pat user is an admin`
51+
);
52+
} else {
53+
log.fail(`error while deleting ${environment}: ${error}`);
54+
log.debug(error);
55+
}
56+
}
4557
}
4658

4759
export default deleteEnvironment;

0 commit comments

Comments
 (0)