Imgbot
Imgbot copied to clipboard
Configuration option to set the commit convention
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.
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.
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!
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.
why not .othersconfig?
Hi @MatheusRV thanks for bumping this.
What is .othersconfig
?
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.
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.
hi @keplersj! Thanks for linking to a recent example Re-opening