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

Classify type of PR based on Diff file path rules #186

Open
jthegedus opened this issue Jun 27, 2022 · 0 comments
Open

Classify type of PR based on Diff file path rules #186

jthegedus opened this issue Jun 27, 2022 · 0 comments

Comments

@jthegedus
Copy link

jthegedus commented Jun 27, 2022

What

I would like to configure and assert errors of specific types/scopes to code changes in the PR diff.

For instance, if I have a PR with docs: as the type/scope I want to ensure this is only applied when the PR contains changes only to the documentation, that is, a list of files or dirs.

Why

Users will create PRs with fix: type, but really they're updating some CI, Tests or Docs which should be captured under ci:, tests: or docs: types. This is important with Changelogs generated from semantic commits, helping stop erroneous Changelog entries. It would be useful to assert these types of requirements to remove human error when approving PRs with incorrect semantic types. I often make mistakes when reviewing simple PRs, only noticing my mistakes afterwards 😅

Example

An example of what this would look like in configuration:

name: Lint PR
on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize
jobs:
  semantic-pr:
    runs-on: ubuntu-latest
    steps:
      - uses: amannn/action-semantic-pull-request@v4.5.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          validateSingleCommit: true
          typeWhenOnlyPaths:
             - docs:
               - docs/*
               - README.md
             - ci:
               - .github/*
             - tests:
               - tests/*

So from this config, PRs with changes only in docs/* or README.md can then only have the docs: type applied. If it has a different type it errors, or if it has changes in the specified paths and elsewhere it is up to the Reviewer to validate the semantic type.

Success PR:

Title/commit: "docs: changing just docs"
Files changed:
- README.md
- docs/index.md

Failure PR:

Title/commit: "fix: typo in docs"
Files changed:
- docs/index.md

Wrong type for changes in Paths. Should have type of docs:, found fix:

Failure PR:

Title/commit: "fix: typo in ci pipeline"
Files changed:
- .github/workflows/test.yml

Wrong type for changes in Paths. Should have Type of ci:, found fix:

More changes detected

If changes occur in more than one of the typeWhenOnlyPaths then the rules are ignored, they only apply when ONLY those paths are present.

Success PR:

Title/commit: "fix: typo in ci pipeline"
Files changed:
- .github/workflows/test.yml
- docs/index.md

No rules under typeWhenOnlyPaths match, so the fix: type cannot be asserted by this configuration. Now we must rely on humans.

Caveats

This is useful for avoiding simple issues, but doesn't help classify changes to multiple areas of the code at once. More complex changes generally must be reviewed more thoroughly, so complex changes aren't subject to the same simple errors I would like to capture with this type of feature.

Urgency

Nice to have.


Thanks for the great GitHub Action 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant