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

Ignore commit messages if they match regular expression #17

Closed

Conversation

ulyssesrex
Copy link

@ulyssesrex ulyssesrex commented Aug 20, 2020

Addresses #14.

See the README diff for a user-facing explanation of the changes in this PR, starting with "Ignoring commits." It includes details on how to configure poper settings to ignore certain commit messages.

Purpose

Some commit messages are automatically generated. From this very repository, we have an example:

Merge pull request #8 from BaneOfSerenity/config-fix

That commit message summary has 52 characters.

If poper runs either of the following checks on that commit, it may fail:

  • character_limit
  • summary_character_limit

Merge commit messages (for example) are automatically generated by concatenating several strings, one of which is the name of the merged branch. Since the branch name may be arbitrarily large, each time you merge a branch into yours and generate a merge commit, you run the risk of that commit failing a poper check.

There may be reasons why someone would want to keep the long merge commit messages in the repository as-is, while also enforcing length limits on commit messages which developers have directly authored.

Approach

This PR adds related settings to Poper::ConfigFile::EMPTY. Rules may then access these settings via methods that are dynamically created and callable on the @config instance variable.

The settings themselves provide strings that can be passed to the Ignore::MatchingPattern interface, which can be included in any Rule. This interface provides a should_ignore? method which may be used to return early from a check if it returns true.

I felt Rule::Ignore::MatchingPattern deserved its own folder because there could be reasons to ignore a rule check other than a commit message matching a pattern.

A Regexp descendant class has been created to parse non-String values that could be passed to the Rules from the user configuration.

Hopefully this approach provides room for future expansion of regular expression matching capabilities (enforcing that a commit message does match a pattern), as well as expanding which rules may be ignored in certain circumstances.

Further considerations

No pre-existing poper configurations should be affected by these changes.

@jbielick
Copy link

Hi @mmozuras , we maintain a Github Action that (optionally) uses poper to review commits and pull requests—adwerx/pronto-ruby. We were hoping you could take a look at this PR since using poper in Github workflows means the possibility of merge commits that are exception cases to the summary length rule.

@ulyssesrex
Copy link
Author

I'm going to close this PR for now. Let me know if there's any interest in re-opening it.

@ulyssesrex ulyssesrex closed this Nov 19, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants