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

chore: label prs based on conventional commit #1121

Conversation

jakobmoellerdev
Copy link
Contributor

What this PR does / why we need it

This makes sure that PR titles pass the conventional commit specification and we add labels based on its conventional context.

The following structure is used for this verification:

// We know this regex looks scary, but it's just to match the Conventional Commit format
// It parses out a Title into several named regex groups, which we can use to extract various semantic patterns:
// - type: The type of change (feat, fix, etc.)
// - scope: The scope of the change (optional and set in brackets)
// - breaking: A flag to indicate a breaking change (!)
// - subject: The subject of the change
// Example: feat(scope)!: add new feature
//          ^^^^ ^^^^^ ^  ^^^^^^^^^^^^^^^
//          type scope    subject
const regex = new RegExp(
`^(((Initial commit)|(Merge [^\\r\\n]+(\\s)[^\\r\\n]+((\\s)((\\s)[^\\r\\n]+)+)*(\\s)?)|^((?<type>${allowedTypes})(\\((?<scope>[\\w\\-]+)\\))?(?<breaking>!?): (?<subject>[^\\r\\n]+((\\s)((\\s)[^\\r\\n]+)+)*))(\\s)?)$)`
´);

Success Example:

Verify that the PR title follows the Conventional Commit format
Type-to-Label Mapping: {
  feat: 'kind/enhancement',
  fix: 'fix',
  chore: 'chore',
  docs: 'kind/documentation',
  test: 'kind/test',
  perf: 'kind/performance'
}
Scope-to-Label Mapping: { deps: 'dependencies' }
Allowed Types: feat|fix|chore|docs|test|perf
PR Title: chore(deps)!: bump the go group across 1 directory with 13 updates
Regex: /^(((Initial commit)|(Merge [^\r\n]+(\s)[^\r\n]+((\s)((\s)[^\r\n]+)+)*(\s)?)|^((?<type>feat|fix|chore|docs|test|perf)(\((?<scope>[\w\-]+)\))?(?<breaking>!?): (?<subject>[^\r\n]+((\s)((\s)[^\r\n]+)+)*))(\s)?)$)/
Match: true
Adding breaking change label
Adding labels: breaking,chore,dependencies

Failure Example:

Verify that the PR title follows the Conventional Commit format
Type-to-Label Mapping: {
  feat: 'kind/enhancement',
  fix: 'fix',
  chore: 'chore',
  docs: 'kind/documentation',
  test: 'kind/test',
  perf: 'kind/performance'
}
Scope-to-Label Mapping: { deps: 'dependencies' }
Allowed Types: feat|fix|chore|docs|test|perf
PR Title: my invalid specification
Regex: /^(((Initial commit)|(Merge [^\r\n]+(\s)[^\r\n]+((\s)((\s)[^\r\n]+)+)*(\s)?)|^((?<type>feat|fix|chore|docs|test|perf)(\((?<scope>[\w\-]+)\))?(?<breaking>!?): (?<subject>[^\r\n]+((\s)((\s)[^\r\n]+)+)*))(\s)?)$)/
Match: false
Invalid PR title format. Make sure you named the PR after the specification at https://www.conventionalcommits.org/en/v1.0.0/#specification. Exiting...

Example runs:

Which issue(s) this PR fixes

This makes sure that our Pull Request Titles are correctly setup via conventional commits and also automatically labelled.

To configure its label settings (which labels to apply) you can use the following env variables

      - uses: actions/github-script@v7
        env:
          TYPE_TO_LABEL: |
            {
              "feat":"kind/enhancement",
              "fix":"fix",
              "chore":"chore",
              "docs":"kind/documentation",
              "test":"kind/test",
              "perf":"kind/performance"
            }
          SCOPE_TO_LABEL: |
            {
              "deps":"dependencies"
            }
          BREAKING_CHANGE_LABEL: "breaking"
          # ...

@jakobmoellerdev jakobmoellerdev requested a review from a team as a code owner November 21, 2024 15:49
@github-actions github-actions bot added component/github-actions Changes on GitHub Actions or within `.github/` directory chore size/m Medium labels Nov 21, 2024
@jakobmoellerdev jakobmoellerdev merged commit a065a76 into open-component-model:main Nov 21, 2024
19 checks passed
@hilmarf hilmarf added the kind/chore chore, maintenance, etc. label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/github-actions Changes on GitHub Actions or within `.github/` directory kind/chore chore, maintenance, etc. size/m Medium
Projects
Status: 🔒Closed
Development

Successfully merging this pull request may close these issues.

3 participants