GsActions / commit-message-checker

GitHub Action that checks commit messages of pushes and pull request against a regex pattern
MIT License
99 stars 56 forks source link

Check duplicity commit messages #90

Closed codebydant closed 1 year ago

codebydant commented 1 year ago

Code of Conduct

Is there an existing issue for this?

Are you willing to sponsor your idea?

Is your feature request related to a problem? Please describe

Hi folks,

Thanks for this life-saving tool.

I was thinking that could be really cool to provide some checks for duplicity in the commit messages. This is because sometimes new contributor does not take care of the commit messages when developing and uses the same message for all commits.

Describe the solution you'd like

It would be wonderful to have some input parameters to check duplicity such as:

checkDuplicityMessages: "true"

This will take an input commit list and check duplicity.

Run gsactions/commit-message-checker@v[1](https://github.com/user/repo/actions/runs/3837184384/jobs/6532199)
Checking commit messages duplicity...
- OK: "AB#000000 feat: add commit checker"
- OK: "AB#000000 fix: my message 2"
- OK: "AB#000000 docs: update docs"
- failed: "AB#000000 docs: update docs"
- OK: "AB#000000 fix: my message 3"
Error: Error: You have duplicated commit messages

Describe alternatives you've considered

Maybe using a regex pattern, but I don't know how to apply this

Additional context

No response

codebydant commented 1 year ago

I think I have found a way to implement this check without action.

- name: Checkout current repository
  uses: actions/checkout@v3
  with:
    ref: ${{ github.event.pull_request.head.sha }}
    fetch-depth: 0

- name: Check Duplicated Commit Subject
  if: ${{ success() || failure() }}
  run: |
    max_commit=$(git log origin/${{ github.event.pull_request.base.ref }}.. --oneline | cut -c 9- | sort | uniq -c | sort -n | tail -1 | grep -qE '^\s*[1-1]+'; echo $?)
    if [ $max_commit == 0 ]
    then
      echo Hey All commit looks good.
      exit 0
    else
      echo Hey you have duplicated commit messages
      git log origin/${{ github.event.pull_request.base.ref }}.. --oneline | cut -c 9- | sort | uniq -c | sort -n 
      exit 1
    fi
  shell: bash

Screenshot from 2023-01-21 20-51-57

Reference