diff --git a/.evergreen/github_app/backport-pr.sh b/.evergreen/github_app/backport-pr.sh index 4e56f592..c7ce8ab5 100755 --- a/.evergreen/github_app/backport-pr.sh +++ b/.evergreen/github_app/backport-pr.sh @@ -61,7 +61,7 @@ old_title=$(git --no-pager log $target_sha --pretty=%B | head -n 1) title="${old_title} [${target_branch}]" body="Cherry-pick of $target_sha to $target_branch" status=0 -git cherry-pick -x -m1 $target_sha || { +git cherry-pick -x -m1 $target_sha > /dev/null 2>&1 || { status=$? } if [ $status == 0 ]; then @@ -78,47 +78,49 @@ if [ $status == 0 ]; then --url https://api.github.com/repos/$owner/$repo/pulls) echo $resp | jq '.html_url' echo "Creating the PR... done." + popd else # If the cherry-pick fails, make a comment. echo "Creating the cherry-pick... failed!" echo "Creating the PR comment..." + popd message="Sorry, unable to cherry-pick to $target_branch" - cat << EOF >> comment.txt + cat << EOF > comment.txt $message, please backport manually. Here are approximate instructions: 1. Checkout backport branch and update it. -``` -git checkout ${target_branch} -git pull -``` +\`\`\` +git checkout -b ${branch} ${target_branch} + +git fetch origin ${target_sha} +\`\`\` 2. Cherry pick the first parent branch of the this PR on top of the older branch: -``` +\`\`\` git cherry-pick -x -m1 ${target_sha} -``` +\`\`\` 3. You will likely have some merge/cherry-pick conflicts here, fix them and commit: -``` +\`\`\` git commit -am {message} -``` +\`\`\` 4. Push to a named branch: -``` -git push origin ${target_branch}:{remote_submit_branch} -``` +\`\`\` +git push origin ${branch} +\`\`\` 5. Create a PR against branch ${target_branch}. I would have named this PR: > "$title" EOF - node create_or_modify_comment.sh -o $owner -n $repo -m $message -c comment.txt -h $target_sha + node create_or_modify_comment.mjs -o $owner -n $repo -m $message -c comment.txt -h $target_sha -s "closed" rm comment.txt echo "Creating the PR comment... done." fi -popd rm -rf $dirname popd diff --git a/.evergreen/github_app/create_or_modify_comment.mjs b/.evergreen/github_app/create_or_modify_comment.mjs index f5b06fef..28de5a86 100644 --- a/.evergreen/github_app/create_or_modify_comment.mjs +++ b/.evergreen/github_app/create_or_modify_comment.mjs @@ -15,6 +15,7 @@ program .requiredOption('-m, --body-match ', 'The comment body to match') .requiredOption('-c, --comment-path ', 'The path to the comment body file') .requiredOption('-h, --head-sha ', 'The sha of the head commit') + .option('-s, --status ', 'The PR status (defaults to "open")', 'open') .parse(process.argv); const options = program.opts(); @@ -23,7 +24,8 @@ const { repoName: repo, bodyMatch, commentPath, - headSha: targetSha + headSha: targetSha, + status } = options; const bodyText = fs.readFileSync(commentPath, { encoding: 'utf8' }); @@ -34,10 +36,10 @@ const headers = { }; // Find a matching comment. -const {comment, issue_number } = await findComment(octokit, owner, repo, targetSha, bodyMatch, "open"); +const {comment, issue_number } = await findComment(octokit, owner, repo, targetSha, bodyMatch, status); if (!comment) { // create comment. - await octokit.request("POST /repos/{owner}/{repo}/issues/{issue_number}/comments", { + var resp = await octokit.request("POST /repos/{owner}/{repo}/issues/{issue_number}/comments", { owner, repo, issue_number, @@ -46,7 +48,7 @@ if (!comment) { }); } else { // update comment. - await octokit.request("PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", { + resp = await octokit.request("PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", { owner, repo, body: bodyText, @@ -55,3 +57,4 @@ if (!comment) { }); } +console.log(resp.data.html_url)