Skip to content

Commit eb3491a

Browse files
committed
FINERACT-2436: Add github action to enforce one commit per user in a PR
- added github action to check that one commit per user standard is enforced. - also checks for whether user has git email properly configured to one registered in github.
1 parent 1c90880 commit eb3491a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Fineract PR One Commit Per User Check
2+
3+
4+
on:
5+
pull_request:
6+
types: [opened, reopened, synchronize]
7+
8+
9+
permissions:
10+
pull-requests: write
11+
12+
13+
jobs:
14+
verify-commits:
15+
name: Validate One Commit Per User
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 1
18+
steps:
19+
- name: Verify Commit Policy
20+
id: check
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
25+
commits=$(gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits") || { echo "::error::GitHub API request failed"; exit 1; }
26+
27+
if echo "$commits" | jq -e '.[] | select(.author == null)' > /dev/null; then
28+
echo "null_authors=true" >> $GITHUB_OUTPUT
29+
echo "::error::Some commits have a git email that is not linked to a GitHub account. Please ensure your git email matches one of your GitHub Account emails."
30+
exit 1
31+
fi
32+
33+
user_ids=$(echo "$commits" | jq -r '.[] | select(.author.type != "Bot") | .author.id')
34+
if echo "$user_ids" | sort | uniq -d | grep -q .; then
35+
echo "multiple_commits=true" >> $GITHUB_OUTPUT
36+
echo "::error::Multiple commits from the same author have been detected."
37+
exit 1
38+
fi
39+
40+
echo "Success: Each author has exactly one commit."
41+
42+
- name: Comment on PR
43+
if: failure()
44+
env:
45+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: |
47+
48+
if [ "${{ steps.check.outputs.null_authors }}" == "true" ]; then
49+
gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body \
50+
$'**One Commit Per User Check Failed**\n\nSome committers have a git email that does not match their GitHub account. Please ensure your git email matches one of your GitHub Account emails.'
51+
fi
52+
53+
54+
if [ "${{ steps.check.outputs.multiple_commits }}" == "true" ]; then
55+
gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body \
56+
$'**One Commit Per User Check Failed**\n\nEach user may only have one commit per PR. Please squash your commits.'
57+
fi

0 commit comments

Comments
 (0)