Skip to content

Commit

Permalink
update Github Action to show changes in .qmd files only
Browse files Browse the repository at this point in the history
  • Loading branch information
ntluong95 committed Oct 29, 2024
1 parent ddcd5e9 commit 013d232
Showing 1 changed file with 45 additions and 40 deletions.
85 changes: 45 additions & 40 deletions .github/workflows/create_pr_on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# Ensure we have all history
git fetch --all
# Check if the translation branch exists
#! Check if the translation branch exists
if git ls-remote --exit-code --heads origin "${TRANSLATION_BRANCH}"; then
echo "Branch ${TRANSLATION_BRANCH} exists. Checking out and rebasing with ${EN_BRANCH}"
git checkout "${TRANSLATION_BRANCH}"
Expand All @@ -49,68 +49,73 @@ jobs:
git pull origin "${EN_BRANCH#refs/heads/}"
fi
# Force push the changes to the remote repository
#! Force push the changes to the remote repository
git push origin "${TRANSLATION_BRANCH}" --force
# 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/main)
echo $latest_commit_en_branch
echo $latest_commit_main
echo $latest_commit_info
#! Get the list of changed .qmd files
changed_files=$(git diff --name-only "${EN_BRANCH}" | grep '\.qmd$')
# 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}"
if [ -z "$changed_files" ]; then
echo "No .qmd file changes 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})
# Check if a PR already exists for this 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/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
#! Check if a PR already exists for this branch
PR_EXISTS=$(gh pr list --head "${TRANSLATION_BRANCH}" --state open --json number --jq length)
if [ "$PR_EXISTS" -eq 0 ]; then
echo "Creating new PR for ${TRANSLATION_BRANCH}"
PR_URL=$(gh pr create --base deploy-preview --head "$TRANSLATION_BRANCH" --title "Handbook ${VERSION_SUFFIX/_en/} $lang" --body "Automated pull request for $lang handbook version ${VERSION_SUFFIX/_en/}")
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
else
# Get the PR number for the translation branch
#! Get the PR number for the translation branch
echo "PR already exists for ${TRANSLATION_BRANCH}"
PR_NUMBER=$(gh pr list --head "${TRANSLATION_BRANCH}" --state open --json number --jq ".[0].number")
fi
echo "Pull Request Number: $PR_NUMBER"
# Add new commits as checkboxes to the PR description
#! 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 commit_info in $latest_commit_info; do
commit_hash=$(echo "$commit_info" | cut -d' ' -f1)
commit_message=$(echo "$commit_info" | cut -d' ' -f2-)
checkboxes="$checkboxes- [ ] [$commit_message](https://github.com/\${{ github.repository }}/commit/$commit_hash)"
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"
done
# Mention a user in the PR description
case "$lang" in
"vn") checkboxes="$checkboxes @ntluong95, please check the box when you finish" ;;
"fr") checkboxes="$checkboxes @oliviabboyd, please check the box when you finish" ;;
"es") checkboxes="$checkboxes @amateo250, please check the box when you finish" ;;
"jp") checkboxes="$checkboxes @ntluong95, please check the box when you finish" ;;
"tr") checkboxes="$checkboxes @ntluong95, please check the box when you finish" ;;
"pt") checkboxes="$checkboxes @Luccan97, please check the box when you finish" ;;
"ru") checkboxes="$checkboxes @ntluong95, please check the box when you finish" ;;
esac
# Retrieve the current PR description
current_pr_body=$(gh pr view $PR_NUMBER --json body --jq '.body')
Expand Down

0 comments on commit 013d232

Please sign in to comment.