Skip to content

Commit

Permalink
Update a brand new PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ntluong95 committed Oct 29, 2024
1 parent 0670a27 commit 69e2f38
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions .github/workflows/create_pr_on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,27 @@ jobs:
continue
fi
# TODO: Remove - Get the date of the latest commit on the english branch
# latest_commit_date=$(git show -s --format=%ci ${EN_BRANCH})
echo "Changed files: $changed_files"
# echo "Commits on the English branch that were made after the latest commit on the translation branch at $latest_commit_date"
# latest_commit_en_branch=$(git show --format=%H -s ${EN_BRANCH})
# latest_commit_info=$(git log ${EN_BRANCH} --since="$latest_commit_date" --format="%H %s" --reverse)
# commit_messages=$(echo "$latest_commit_info" | cut -d' ' -f2-)
# latest_commit_main=$(git show --format=%H -s origin/main)
# echo $latest_commit_en_branch
# echo $latest_commit_main
# echo $latest_commit_info
# # Check if there are new commits
# if [ "$latest_commit_en_branch" == "$latest_commit_main" ]; then
# echo "No new commits to include in PR for ${TRANSLATION_BRANCH}"
# continue
# fi
# TODO: Remove
#! Get the date of the latest commit on the english branch
latest_commit_date=$(git show -s --format=%ci ${EN_BRANCH})
echo "Commits on the English branch that were made after the latest commit on the translation branch at $latest_commit_date"
latest_commit_en_branch=$(git show --format=%H -s ${EN_BRANCH})
latest_commit_info=$(git log ${EN_BRANCH} --since="$latest_commit_date" --format="%H %s" --reverse)
commit_messages=$(echo "$latest_commit_info" | cut -d' ' -f2-)
latest_commit_main=$(git show --format=%H -s origin/master)
echo $latest_commit_en_branch
echo $latest_commit_main
echo $latest_commit_info
#! Check if there are new commits
if [ "$latest_commit_en_branch" == "$latest_commit_main" ]; then
echo "No new commits to include in PR for ${TRANSLATION_BRANCH}"
continue
fi
#! Check if a PR already exists for this branch
PR_EXISTS=$(gh pr list --head "${TRANSLATION_BRANCH}" --state open --json number --jq length)
Expand All @@ -93,34 +95,39 @@ jobs:
fi
echo "Pull Request Number: $PR_NUMBER"
#! Initialize new PR body
new_pr_body="# Automated pull request for $lang handbook version ${VERSION_SUFFIX/_en/}"
#! Add new commits as checkboxes to the PR description
IFS=$'\n' # Change the Internal Field Separator to newline for correct iteration over lines
checkboxes=""
for file in $changed_files; do
commits=$(git log --oneline "${EN_BRANCH}" -- "$file" | awk '{print "#"$1}' | paste -s -d ', ' -)
checkboxes="$checkboxes- [ ] Chapter \`$file\` has new changes in the following commit(s) ($commits)."
#! Mention a user in the PR description
case "$lang" in
"vn") checkboxes="$checkboxes @ntluong95, please review changes and check the box when you finish" ;;
"fr") checkboxes="$checkboxes @oliviabboyd, please review changes and check the box when you finish" ;;
"es") checkboxes="$checkboxes @amateo250, please review changes and check the box when you finish" ;;
"jp") checkboxes="$checkboxes @hitomik723, please review changes and check the box when you finish" ;;
"tr") checkboxes="$checkboxes @ntluong95, please review changes and check the box when you finish" ;;
"pt") checkboxes="$checkboxes @Luccan97, please review changes and check the box when you finish" ;;
"ru") checkboxes="$checkboxes @ntluong95, please review changes and check the box when you finish" ;;
esac
checkboxes="$checkboxes\n"
#! List only new commits compared with the main branch, tail -n +2 to skip the first line of output from git log, the latest commit will not be added into the message
list_commits=$(git log origin/main..${TRANSLATION_BRANCH} --follow --pretty=format:"%H" -- $file | tail -n +2 | paste -sd, - | sed 's/,/, /g')
for commit in $latest_commit_en_branch; do
checkboxes="$checkboxes- [ ] Chapter [\`$file\`](https://github.com/${{ github.repository }}/pull/$PR_NUMBER/files?file-filters%5B%5D=.qmd&show-viewed-files=true) has new changes in the following commit(s): $list_commits. "
#! Mention a user in the PR description
case "$lang" in
"vn") checkboxes="$checkboxes @ntluong95, please review changes and check the box when you finish" ;;
"fr") checkboxes="$checkboxes @oliviabboyd, please review changes and check the box when you finish" ;;
"es") checkboxes="$checkboxes @amateo250, please review changes and check the box when you finish" ;;
"jp") checkboxes="$checkboxes @hitomik723, please review changes and check the box when you finish" ;;
"tr") checkboxes="$checkboxes @ntluong95, please review changes and check the box when you finish" ;;
"pt") checkboxes="$checkboxes @Luccan97, please review changes and check the box when you finish" ;;
"ru") checkboxes="$checkboxes @ntluong95, please review changes and check the box when you finish" ;;
esac
checkboxes="$checkboxes"$'\n'"$checkbox"
done
done
# Retrieve the current PR description
current_pr_body=$(gh pr view $PR_NUMBER --json body --jq '.body')
# Append checkboxes to the current PR description
new_pr_body=$(printf "%s\n%s" "$current_pr_body" "$checkboxes")
if [ -n "$checkboxes" ]; then
# Append the checkboxes to the new PR body
new_pr_body="$new_pr_body"$'\n'"$checkboxes"
fi
gh api repos/${{ github.repository }}/issues/$PR_NUMBER --method PATCH --field body="$new_pr_body"
Expand Down

0 comments on commit 69e2f38

Please sign in to comment.