Imgbot icon indicating copy to clipboard operation
Imgbot copied to clipboard

Configuration option to set the commit convention

Open Berkmann18 opened this issue 6 years ago • 8 comments

A variety of repos follows certain commit convention (usually Angular's, ESLint's, ...) which is there to enforce a consistent commit message style e.g. (taken from an actual commit):

Update(Python): Added tests and documentation

Added the documentation, unit tests and added the feature that allows sorting in descending order

BREAKING CHANGE: One more parameter

closes #2

The commit log above uses the ESLINT commit convention (obtained using commitizen i.e. git cz).

This is usually done in repos where an automated changelog build process is in place, say using the following NPM scripts:

"scripts": {
  "changelog": "conventional-changelog -p eslint -i CHANGELOG.md -s -r 0",
  "version": "npm run changelog && git add CHANGELOG.md"
}

With the following package.json config:

"config": {
  "commitizen": {
    "path": "cz-adapter-eslint"
  }
}

So if imgbot was to commit to the branch especially with auto-merging enabled (cf. #231 ), it would be ideal that it respects the commit convention (if there's one in place) thus preventing some inconsistencies and some unnecessary manual changes.

Possible solutions

A. Look in package.json for the "config.commitizen" key and then use that for the commit B. Analyse the commits (maybe like commit-lint would do) and determine the commit convention (assuming there's one) and use that C. Look for a .czrc file (which could be something like { "path": "cz-adapter-eslint" }) and then use it to commit with the correct style D. Have a setting in .imgbotconfig that will instruct imgbot on how to write the commit messages.

Berkmann18 avatar Nov 14 '18 12:11 Berkmann18

If I understood the project's contribution guide, this would be stuff going on CommitMessage.cs and PullRequest.cs right?

I suppose that the file that would be reading a settings file say ./.github/.imgbot.yml should be able to modify KnownGitHubs.cs's CommitMessageTitle field. I suck at C# and haven't really worked on any bots so I'm not sure I'll be able to do this on my own but can help.

Berkmann18 avatar Dec 06 '18 17:12 Berkmann18

Hi @Berkmann18! you're certainly on the right track.

CommitMessage.cs has a parameter that contains the compression result and returns a commit message.

This return of this function typically looks like, for example

[ImgBot] Optimize images

*Total -- 321.19kb -> 123.05kb (7.81%)

/path/image1.png -- 4.19kb -> 0.63kb (4.9%)
/path/image2.png -- 4.19kb -> 0.63kb (84.9%)

where the first line is the tile.

We can keep the constant in KnownGitHubs.cs as a fallback maybe rename it to DefaultCommitMessageTitle

Then I think you would want additional parameter(s) passed in besides the CompressionResult[] to the Create() method to override the first line in the commit message and affect the title.

You can use CommitMessageTests to help develop the algorithm

Once you have that all working, we can figure out how to get the right parameters populated and passed to the function, depending on what it is you end up needing to pull it off.

And finally, when all that is done and working we can update PullRequest.cs to base the title of the pull request on the first line of the commit, so we keep these in sync. We do a similar thing to generate the markdown table in the pull request body.

Let me know how it goes!

dabutvin avatar Dec 06 '18 18:12 dabutvin

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 06 '19 23:02 stale[bot]

why not .othersconfig?

matbrgz avatar Feb 08 '19 15:02 matbrgz

Hi @MatheusRV thanks for bumping this.

What is .othersconfig ?

dabutvin avatar Feb 08 '19 19:02 dabutvin

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 09 '19 20:04 stale[bot]

Can we reopen this? I just encountered this in one of my repos following Conventional Commits: https://github.com/keplersj/cises/pull/125. I used squash and merge to change the commit message, but having it done automatically would be a nice feature to have.

keplersj avatar Aug 05 '19 16:08 keplersj

hi @keplersj! Thanks for linking to a recent example Re-opening

dabutvin avatar Aug 05 '19 17:08 dabutvin