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

fix: refactor notify triager workflow #3403

Closed
wants to merge 12 commits into from
11 changes: 9 additions & 2 deletions .github/workflows/notify-triager.yml
Copy link
Member

@anshgoyalevil anshgoyalevil Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous implementation of notify traiger workflow, we were getting doc triagers assigned to the PRs that didn't contain any doc changes. This was because of how the workflow was checking for file changes in the PR.

For example, in previous implementation:

  • User A created a PR P1 with code changes. -> Only code triagers assigned to the PR
  • User B created a PR P2 with doc changes. -> Only doc triagers assigned to the PR
  • PR P2 gets merged first.
  • PR P1 is updated to include a merge commit containing PR P2 changes -> Doc traigers also gets assigned to this PR P1. Now this is the part where we are going wrong. Also, this behavior is still ambigious

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was because of MD file changes

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ jobs:
- name: Get commit message
id: commit-message
run: |
# Extract the commit message
commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
commit_message=$(echo "$commit_message" | tr '\n' ' ')
commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
Comment on lines +20 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve commit message extraction robustness and efficiency

The commit message extraction and cleaning can be improved for better robustness and efficiency.

-          commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
-          commit_message=$(echo "$commit_message" | tr '\n' ' ')
-          commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
+          if ! commit_message=$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}"); then
+            echo "::error::Failed to extract commit message"
+            exit 1
+          fi
+          commit_message=$(echo "$commit_message" | tr '\n' ' ' | sed 's/[<>|()[\]]//g' | xargs)
           echo "commit_message=$commit_message" >> $GITHUB_OUTPUT

Changes:

  1. Added quotes around GitHub SHA to prevent word splitting
  2. Added error handling for git log command
  3. Combined multiple sed commands into one for better efficiency
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Extract the commit message
commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
commit_message=$(echo "$commit_message" | tr '\n' ' ')
commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
# Extract the commit message
if ! commit_message=$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}"); then
echo "::error::Failed to extract commit message"
exit 1
fi
commit_message=$(echo "$commit_message" | tr '\n' ' ' | sed 's/[<>|()[\]]//g' | xargs)
echo "commit_message=$commit_message" >> $GITHUB_OUTPUT

echo "commit_message=$commit_message" >> $GITHUB_OUTPUT

- name: Check if last commit is a merge commit
Expand All @@ -41,6 +44,7 @@ jobs:
files: |
**.md


- name: Check PR Changes for non-.md files
id: non-md-pr-changes
uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11 # version 42.1.0 https://github.com/tj-actions/changed-files/releases/tag/v42.1.0
Expand Down Expand Up @@ -68,8 +72,9 @@ jobs:
echo "codeTriagers=$codeTriagers" >> $GITHUB_ENV

- name: Add Reviewers for code files
if: steps.check-merge-branch.outputs.isMergeCommit == 'false' && steps.non-md-pr-changes.outputs.any_changed == 'true'
if: steps.non-md-pr-changes.outputs.any_changed == 'true'
run: |
echo "Hello1"
IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
reviewers=$(printf ', "%s"' "${codeTriagers[@]}")
reviewers=[${reviewers:2}]
Expand All @@ -83,8 +88,9 @@ jobs:
}"

- name: Add Reviewers for doc files
if: steps.check-merge-branch.outputs.isMergeCommit == 'false' && steps.md-pr-changes.outputs.any_changed == 'true'
if: steps.md-pr-changes.outputs.any_changed == 'true'
run: |
echo "Hello"
IFS=' ' read -r -a docTriagers <<< "${{ env.docTriagers }}"
reviewers=$(printf ', "%s"' "${docTriagers[@]}")
reviewers=[${reviewers:2}]
Expand All @@ -96,3 +102,4 @@ jobs:
-d "{
\"reviewers\": $reviewers
}"

18 changes: 9 additions & 9 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# The last matching pattern has the most precedence.
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.

# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
* @derberg @akshatnema @magicmatatjahu @anshgoyalevil @mayaleeeee @asyncapi-bot-eve
# # The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
# * @derberg @akshatnema @magicmatatjahu @anshgoyalevil @mayaleeeee @asyncapi-bot-eve

# All .md files
*.md @quetzalliwrites @asyncapi-bot-eve
# # All .md files
# *.md @quetzalliwrites @asyncapi-bot-eve

markdown/blog/*.md @thulieblack @quetzalliwrites
markdown/community/*.md @thulieblack @quetzalliwrites
# markdown/blog/*.md @thulieblack @quetzalliwrites
# markdown/community/*.md @thulieblack @quetzalliwrites

README.md @quetzalliwrites @derberg @akshatnema @magicmatatjahu @mayaleeeee @asyncapi-bot-eve
#docTriagers: TRohit20 BhaswatiRoy VaishnaviNandakumar J0SAL
#codeTriagers: sambhavgupta0705 devilkiller-ag
# README.md @quetzalliwrites @derberg @akshatnema @magicmatatjahu @mayaleeeee @asyncapi-bot-eve
#docTriagers: palakgupta2712
#codeTriagers: sambhavgupta0705
Loading