Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
agerauer committed Dec 5, 2023
1 parent 62a6fec commit 371669d
Showing 1 changed file with 8 additions and 48 deletions.
56 changes: 8 additions & 48 deletions src/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { createComment, cleanup } from './lib';
* @arg {object} octokit Github Octokit Rest client
*/
export const groupLabeledPullRequests = async function (octokit) {
//get current pull request number
const splitUrl = context.payload.comment.issue_url.split('/');
const currentIssueNumber = parseInt(splitUrl[splitUrl.length - 1], 10)
//create tempBranchName
const tempBranch = `temp-ci-${context.repo.repo}-${Date.now()}`;
try {
Expand All @@ -19,7 +16,6 @@ export const groupLabeledPullRequests = async function (octokit) {
var comment = '### Going to merge pull requests:\n';
var prLinks = '';
const label = getInput('target-label');
const excludeCurrent = getInput('exclude-current');
//Create search query
const q = `is:pull-request label:${label} repo:${context.repo.owner}/${context.repo.repo} state:open`;
//Call github API through the octokit client
Expand All @@ -28,50 +24,17 @@ export const groupLabeledPullRequests = async function (octokit) {
sort: 'created',
order: 'desc',
});
//Exclude the current branch, so we will build the default.
if(excludeCurrent === "true" && data.total_count <= 0) {
return "default";
}
//Fetch the current pull request
const { data: currentPull } = await octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: currentIssueNumber
});
// Nothing to iterate. Just add the current pull data to merge
if(excludeCurrent !== 'true' && data.total_count <= 0) {
prLinks += `- ${currentPull.html_url}\n`;
comment += prLinks;
await createComment(octokit, currentIssueNumber, comment);
await mergeBranches(octokit, [currentPull], tempBranch);
//comment success in PR if merge is successful.
await createComment(
octokit,
currentIssueNumber,
`:rocket: All pull requests were merged successfully from \`${tempBranch}\` into \`${getInput('integration-branch')}\`.\n\n**Summary:**\n---\n${prLinks}:`,
);
await cleanup(octokit, tempBranch);
setOutput('temp-branch', tempBranch);
return;
}
//iterate over selected PRs
if(data.total_count > 0) {
if(excludeCurrent !== 'true') {
console.log('Pushing current PR to array');
prLinks += `- ${currentPull.html_url}\n`;
pulls.push(currentPull);
}
for (const item of data.items) {
if (item.number !== currentIssueNumber) {
const accPull = await octokit.request(`GET /repos/{owner}/{repo}/pulls/{pull_number}`, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: item.number
});
console.log(`Pushing External PR #${item.number} to array`);
prLinks += `- ${item.html_url}\n`;
pulls.push(accPull.data);
}
const accPull = await octokit.request(`GET /repos/{owner}/{repo}/pulls/{pull_number}`, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: item.number
});
console.log(`Pushing External PR #${item.number} to array`);
prLinks += `- ${item.html_url}\n`;
pulls.push(accPull.data);
}
}

Expand All @@ -85,9 +48,6 @@ export const groupLabeledPullRequests = async function (octokit) {
console.log("Merge conflict error.")
//Add label
}
//comment failure in pr, cleanup and set action as failed.
const message = `:ghost: Merge failed with error:\n\`\`\`shell\n${e.message}\n\`\`\``;
await createComment(octokit, currentIssueNumber, message);
await cleanup(octokit, tempBranch);
setFailed(e.message);
}
Expand Down

0 comments on commit 371669d

Please sign in to comment.