thehanimo / pr-title-checker

An action to automatically check if pull request titles conform to Contribution Guidelines
MIT License
106 stars 36 forks source link

I want to use conventional-changelog/commitlint for PR title check #31

Closed Neeraj-swarnkar closed 1 year ago

Neeraj-swarnkar commented 1 year ago

Hi Team,

I am using your Action/Workflow, Thanks for the great effort, I need your help, I want to use https://www.conventionalcommits.org/en/v1.0.0/#examples conventional-changelog/commitlint for PR title check

Can we use some regex for this, or if this action support this already how to use it ?

Please guide. I am sharing my json and yml code below. Thanks.

JSON file -

{
    "LABEL": {
        "name": "title needs formatting",
        "color": "EEEEEE"
    },
    "CHECKS": {
        "prefixes": ["build: ", "chore: ", "ci: ", "docs: ", "feat: ", "fix: ", "perf: ", "refactor: ", "revert: ", "test: "],
        "regexp": "docs\\(v[0-9]\\): ",
        "regexpFlags": "i",
        "ignoreLabels": ["dont-check-PRs-with-this-label", "meta"]
    },
    "MESSAGES": {
        "success": "All OK",
        "failure": "Failing CI test",
        "notice": ""
    }
}

YML file -


# This workflow/action checks if PR titles conform to the Contribution Guidelines
# For more information see: https://github.com/webex/pr-title-checker

name: pr-title-checker
on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize
      - labeled
      - unlabeled
    branches:
      - main
      - dev
      - beta
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - name: Check PR title
        uses: webex/pr-title-checker@main
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          pass_on_octokit_error: false
          configuration_path: .github/pr-title-checker-config.json

prefixes in JSON is totally working fine for commits title, but there could be some other examples like fix(parser):, feat(feature-name):, breaking change, !, etc. Can we use regexp for commitlint for PR title or something.

I don't want to switch to another action, so I am asking for solution.

@thehanimo, @feychenie, @jcw-

jcw- commented 1 year ago

Yes, you should be able to do this via a regex. I'm not aware of one offhand, but it would involve using the | character to OR together the different prefixes.

thehanimo commented 1 year ago

@Neeraj-swarnkar you would need to use a regexp with a | between formats you'd like to support (like @jcw- mentioned). In your JSON file under the "CHECKS" field, you already have support for a regexp (not sure if it was intentional) where you are allowing PR title of the format docs(vx) where x is a number between 0-9. If you want to support multiple such regexps, use something like so:

"regexp": "(feat\\(.*\\))|(fix\\(.*\\)):",

which supports fix(parser): and feat(feature-name): like you mentioned. But it also accepts fix(): and feat():. You can tailor this regexp to your need.

Neeraj-swarnkar commented 1 year ago

@thehanimo , @jcw- Thanks to both of you for suggetions,

"regexp": "(?<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|test)(?<scope>(?:/([^()\r\n]*/)|/()?(?<breaking>!)?:)(?<subject>:.*)?",

I will be trying to use this, I hope this looks good. https://regex101.com/r/vmBkEe/1

Thanks for your help..

thehanimo commented 1 year ago

That's a complex regex and needs a really good look into it. I'm not sure why you need \r or \n in the scope capture group. But that's a different discussion to be had. I'm not an expert when it comes to regex so I'd suggest testing it out thoroughly just in case :)

Hope this was helpful! Closing this issue.

Neeraj-swarnkar commented 1 year ago

Sure, Thanks for the help..