Skip to content

Commit

Permalink
Add methods to collapse merge and close sibling paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaurencin committed Oct 22, 2020
1 parent ed137a0 commit 400b0e9
Showing 1 changed file with 52 additions and 59 deletions.
111 changes: 52 additions & 59 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,56 @@ const probotHandler = async (robot: Application) => {
}
};

const handleTropBackportClosed = async (
context: Context,
pr: PullsGetResponse,
change: PRChange,
) => {
const oldPRNumbers = maybeGetManualBackportNumbers(context);
if (change === PRChange.CLOSE) {
robot.log(
`Automatic backport #${pr.number} closed with unmerged commits`,
);
}

if (oldPRNumbers.length > 0) {
if (change === PRChange.MERGE) {
robot.log(`Automatic backport merged for: #${pr.number}`);
robot.log(`Labeling original PR for merged PR: #${pr.number}`);
} else {
robot.log(`Updating label on original PR for closed PR: #${pr.number}`);
}
for (const oldPRNumber of oldPRNumbers) {
await updateManualBackport(context, change, oldPRNumber);
}
await labelClosedPRs(context, pr, change);
}

// Check that the closed PR is trop's own and act accordingly.
if (pr.user.login === getEnvVar('BOT_USER_NAME')) {
if (change === PRChange.MERGE) {
robot.log(`Labeling original PR for merged PR: #${pr.number}`);
} else {
robot.log(`Updating labels for closed PR: #${pr.number}`);
}
await labelClosedPRs(context, pr, change);

robot.log(`Deleting head branch: ${pr.head.ref}`);
try {
await context.github.git.deleteRef(
context.repo({ ref: `heads/${pr.head.ref}` }),
);
} catch (e) {
robot.log('Failed to delete backport branch: ', e);
}
} else {
robot.log(
`Backporting #${pr.number} to all branches specified by labels`,
);
backportAllLabels(context, pr);
}
};

const runCheck = async (context: Context, pr: PullsGetResponse) => {
const allChecks = await context.github.checks.listForRef(
context.repo({
Expand Down Expand Up @@ -327,67 +377,10 @@ const probotHandler = async (robot: Application) => {
// Backport pull requests to labeled targets when PR is merged.
robot.on('pull_request.closed', async (context: Context) => {
const pr: PullsGetResponse = context.payload.pull_request;
const oldPRNumbers = maybeGetManualBackportNumbers(context);
if (pr.merged) {
if (oldPRNumbers.length > 0) {
robot.log(`Automatic backport merged for: #${pr.number}`);
robot.log(`Labeling original PR for merged PR: #${pr.number}`);
for (const oldPRNumber of oldPRNumbers) {
await updateManualBackport(context, PRChange.MERGE, oldPRNumber);
}
await labelClosedPRs(context, pr, PRChange.MERGE);
}

// Check that the closed PR is trop's own and act accordingly.
if (pr.user.login === getEnvVar('BOT_USER_NAME')) {
robot.log(`Labeling original PR for merged PR: #${pr.number}`);
await labelClosedPRs(context, pr, PRChange.MERGE);

robot.log(`Deleting head branch: ${pr.head.ref}`);
try {
await context.github.git.deleteRef(
context.repo({ ref: `heads/${pr.head.ref}` }),
);
} catch (e) {
robot.log('Failed to delete backport branch: ', e);
}
} else {
robot.log(
`Backporting #${pr.number} to all branches specified by labels`,
);
backportAllLabels(context, pr);
}
await handleTropBackportClosed(context, pr, PRChange.MERGE);
} else {
robot.log(
`Automatic backport #${pr.number} closed with unmerged commits`,
);

if (oldPRNumbers.length > 0) {
robot.log(`Updating label on original PR for closed PR: #${pr.number}`);
for (const oldPRNumber of oldPRNumbers) {
await updateManualBackport(context, PRChange.CLOSE, oldPRNumber);
}
await labelClosedPRs(context, pr, PRChange.CLOSE);
}

// Check that the closed PR is trop's own and act accordingly.
if (pr.user.login === getEnvVar('BOT_USER_NAME')) {
robot.log(`Updating labels for closed PR: #${pr.number}`);
await labelClosedPRs(context, pr, PRChange.CLOSE);
robot.log(`Deleting head branch: ${pr.head.ref}`);
try {
await context.github.git.deleteRef(
context.repo({ ref: `heads/${pr.head.ref}` }),
);
} catch (e) {
robot.log('Failed to delete backport branch: ', e);
}
} else {
robot.log(
`Backporting #${pr.number} to all branches specified by labels`,
);
backportAllLabels(context, pr);
}
await handleTropBackportClosed(context, pr, PRChange.CLOSE);
}
});

Expand Down

0 comments on commit 400b0e9

Please sign in to comment.