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

GODRIVER-3314 Fix handling of failed cherry-pick #483

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
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
32 changes: 17 additions & 15 deletions .evergreen/github_app/backport-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
11 changes: 7 additions & 4 deletions .evergreen/github_app/create_or_modify_comment.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ program
.requiredOption('-m, --body-match <string>', 'The comment body to match')
.requiredOption('-c, --comment-path <path>', 'The path to the comment body file')
.requiredOption('-h, --head-sha <sha>', 'The sha of the head commit')
.option('-s, --status <status>', 'The PR status (defaults to "open")', 'open')
.parse(process.argv);

const options = program.opts();
Expand All @@ -23,7 +24,8 @@ const {
repoName: repo,
bodyMatch,
commentPath,
headSha: targetSha
headSha: targetSha,
status
} = options;
const bodyText = fs.readFileSync(commentPath, { encoding: 'utf8' });

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -55,3 +57,4 @@ if (!comment) {
});

}
console.log(resp.data.html_url)
Loading