Skip to content

fix: fail gracefully on private non pro #423

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

Merged
Changes from all 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
82 changes: 44 additions & 38 deletions script/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ function successSpinnerBlock(blockText) {

async function withSpinner(
callback,
{ startText, successText, stopText, errorText }
{ startText, successText, stopText, errorText, warnText }
) {
s.start(startText);

try {
await callback();

s.stop(chalk.green("✅ " + successText));
const success = await callback();
if (success === false) s.stop(chalk.yellow("⚠️ " + warnText));
else s.stop(chalk.green("✅ " + successText));
} catch (error) {
s.stop(chalk.red("❌ " + stopText));

Expand Down Expand Up @@ -275,7 +275,7 @@ try {
let user;
try {
user = JSON.parse((await $`gh api user`).stdout).login;
} catch (err) {
} catch (error) {
Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, heh, this is unused... +1 to calling it error over err. I suppose we should enable https://eslint.org/docs/latest/rules/no-unused-vars#caughterrors... I'll file a separate issue to do that as a followup.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.warn(
chalk.gray(
`Couldn't authenticate GitHub user, falling back to the provided owner name '${owner}'`
Expand Down Expand Up @@ -574,45 +574,51 @@ try {
// Note: keep this inline script in sync with .github/workflows/release.yml!
// Todo: it would be nice to not have two sources of truth...
// https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/145
await octokit.request(
`PUT /repos/${owner}/${repository}/branches/main/protection`,
{
allow_deletions: false,
allow_force_pushes: true,
allow_fork_pushes: false,
allow_fork_syncing: true,
block_creations: false,
branch: "main",
enforce_admins: false,
owner,
repo: repository,
required_conversation_resolution: true,
required_linear_history: false,
required_pull_request_reviews: null,
required_status_checks: {
checks: [
{ context: "build" },
{ context: "compliance" },
{ context: "knip" },
{ context: "lint" },
{ context: "markdown" },
{ context: "package" },
{ context: "packages" },
{ context: "prettier" },
{ context: "spelling" },
{ context: "test" },
],
strict: false,
},
restrictions: null,
}
);
try {
await octokit.request(
`PUT /repos/${owner}/${repository}/branches/main/protection`,
{
allow_deletions: false,
allow_force_pushes: true,
allow_fork_pushes: false,
allow_fork_syncing: true,
block_creations: false,
branch: "main",
enforce_admins: false,
owner,
repo: repository,
required_conversation_resolution: true,
required_linear_history: false,
required_pull_request_reviews: null,
required_status_checks: {
checks: [
{ context: "build" },
{ context: "compliance" },
{ context: "knip" },
{ context: "lint" },
{ context: "markdown" },
{ context: "package" },
{ context: "packages" },
{ context: "prettier" },
{ context: "spelling" },
{ context: "test" },
],
strict: false,
},
restrictions: null,
}
);
} catch (error) {
if (error.status === 403) return false;
throw error;
}
},
{
startText: `Hydrating branch protection settings...`,
successText: `Hydrated branch protection settings.`,
stopText: `Error hydrating branch protection settings.`,
errorText: `Could not hydrate branch protection settings. `,
warnText: `Could not hydrate branch protection settings: private repositories require GitHub Pro for that API.`,
}
);

Expand Down