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

refactor: improve branch support logic #301

Merged
merged 1 commit into from
Aug 22, 2024
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
52 changes: 26 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,55 +548,55 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
);
for (const branch of branches) {
robot.log(
`Initiating backport to \`${branch}\` from 'backport-to' comment`,
`Attempting backport to \`${branch}\` from 'backport-to' comment`,
);

const pr = (
await context.octokit.pulls.get(
context.repo({ pull_number: issue.number }),
)
).data as WebHookPR;

try {
await context.octokit.repos.getBranch(context.repo({ branch }));
} catch (err) {
await context.octokit.issues.createComment(
context.repo({
body: `The branch you provided \`${branch}\` does not appear to exist.`,
issue_number: issue.number,
}),
);
return true;
}

// Optionally disallow backports to EOL branches
const noEOLSupport = getEnvVar('NO_EOL_SUPPORT', '');
if (noEOLSupport) {
const supported = await getSupportedBranches(context);
if (!supported.includes(branch)) {
robot.log(
`${branch} is no longer supported - no backport will be initiated`,
);
robot.log(`${branch} is EOL - no backport will be initiated`);
await context.octokit.issues.createComment(
context.repo({
body: `\`${branch}\` is no longer supported - no backport will be initiated.`,
body: `Provided branch \`${branch}\` is EOL - no backport will be performed.`,
issue_number: issue.number,
}),
);
return false;
continue;
}
}

try {
await context.octokit.repos.getBranch(context.repo({ branch }));
} catch (err) {
robot.log(
`${branch} does not exist - no backport will be initiated`,
);
await context.octokit.issues.createComment(
context.repo({
body: `Provided branch \`${branch}\` does not appear to exist.`,
issue_number: issue.number,
}),
);
continue;
}

Comment on lines +569 to +583
Copy link
Member

Choose a reason for hiding this comment

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

Why is this block moved under the section flagged by NO_EOL_SUPPORT?

Copy link
Member Author

Choose a reason for hiding this comment

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

getSupportedBranches itself checks branch existence - so in moving it down we save a redundant check in the case the variable is set.

robot.log(
`Initiating manual backport process for #${issue.number} to ${branch}`,
);

await context.octokit.issues.createComment(
context.repo({
body: `The backport process for this PR has been manually initiated - sending your PR to \`${branch}\`!`,
issue_number: issue.number,
}),
);
backportToBranch(robot, context, pr, branch);

const { data: pr } = await context.octokit.pulls.get(
context.repo({ pull_number: issue.number }),
);

backportToBranch(robot, context, pr as WebHookPR, branch);
}
return true;
},
Expand Down