OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫

Hi Hackers,

About 10 days ago, I came across the #GitHubHack23 post and then I thought: “Hmm… ain’t I got something to contribute?” — squinting my eyes like this 😑

What I Built

Meet OpenCommit as a GitHub Action 🪅

With OpenCommit actio…


This content originally appeared on DEV Community and was authored by Dima Sukharev

Hi Hackers,

About 10 days ago, I came across the #GitHubHack23 post and then I thought: "Hmm... ain't I got something to contribute?" — squinting my eyes like this 😑

What I Built

Meet OpenCommit as a GitHub Action 🪅

With OpenCommit action set in a repository, every commit pushed is automatically improved with a meaningful message about what was changed and the rationale behind those changes.

You can find the Action in the GitHub marketplace here and follow the instructions to set it up in your repository.

Category Submission:

I'm submitting the Action for the 'Maintainer Must-Haves' category as it helps maintainers follow a rational behind the changes contributed by reading clean and meaningful commit messages.

And I'm also submitting the Action for the 'DIY Deployments' category as a custom CI script that improves open-source collaboration experience.

App Link

You can access the Action page here, and the repository here.

Screenshots

OpenCommit comparison png

Description

With the Action set in a repository, all commits are automatically improved with meaningful, clear, and easy-to-follow messages on every push to any branch.

You may exclude branches like main and dev from the Action via a custom setting.

Here's how to set up.

Link to Source Code

Find the source code for the Action here.

Permissive License

OpenCommit is distributed under the MIT License — you can find the license here.

Background

i'am something of a maintainer myself meme

I was inspired to create OpenCommit from my experiences as a maintainer. It's a true joy to review PRs with clean, coherent commit messages that are easy to follow. It's magical to open a PR and follow a trail of meaningful commit messages that tell you what changed and why.

And now if some of the contributions lack clear and concise commit messages — you set OpenCommit GitHub Action to solve this problem.

How I Built It

Wow, it's a long story :)

The journey of creating this GitHub Action started with identifying a problem space in the current GitHub ecosystem: the quality and consistency of commit messages depends on a collaborator. I decided to develop a solution leveraging GitHub Actions and OpenAI's GPT-3 model via OpenCommit functionality to generate enhanced commit messages.

Thanks to @mishmanners explaining that building great things on top of great things is great 💚

The Stack

The Action is built using TypeScript and Node.js, popular choices for GitHub Actions due to their excellent support for asynchronous operations, a crucial requirement considering the multiple I/O operations involved. In the initial setup, I used the actions/toolkit package which provides useful utilities to streamline the creation of GitHub Actions. I picked @actions/core for basic functionalities such as inputs, outputs, and error handling, @actions/github to interact with GitHub's REST API, and @actions/exec to execute shell commands.

The Algorithm

The core function of the action is improving commit messages. I achieved this by combining GitHub's APIs with the openAI's GPT (3.5 model — cheap and powerful). I utilized Octokit, GitHub’s official client library for Node.js, to fetch commit messages from the PR context. These commit messages are then passed as prompts to the openAI API, which then generates an enhanced version of each commit message.

Workflow and Usage

The action is designed to run on push events, specifically when a new commit is pushed to a PR. This triggers the action, which then fetches the commit messages, improves them as per Conventional Commits concept, and finally replaces the original ones.

You may also turn on GitMoji convention if you prefer your messages baked with emojis 🤠

Testing and Refactoring

The initial prototype had some shortcomings; for instance, it did not handle errors and exceptions well, making it less robust. Therefore, a significant amount of time was spent on refactoring the codebase. The action was thoroughly tested across a variety of scenarios to ensure its reliability and robustness.

Challenges and Learnings

Throughout the journey, there were numerous challenges. However, they presented learning opportunities. One significant challenge was ensuring the correct handling of Git commands in different environments. I learned a great deal about GitHub Actions internal workings, and how to manage and manipulate commit histories. Another challenge was working with the GPT API and optimize the calls to make the tool run cheap.

Future Improvements

Building on an already powerful package that offers an array of features was a pivotal part of this GitHub Action. The base package supports more than ten languages, incorporates GitMoji, and offers robust algorithms to manage any-size commit diffs. This, combined with smart prompts for GPT to generate the best commit message results, provides a solid foundation for future enhancements.

Looking ahead, I plan to introduce more customization options, allowing users to specify the level of verbosity and the style of their commit messages with prefixes and postfixes.

Additionally, I aim to enhance language support further, catering to global non-English speaking users, thus broadening the action's reach.

I'm also adding GitHub Codespaces configs to the repo to make open-source collaboration experience easier — you would just click "Run in a Codespace" on the README and instantly create a PR from your browser 🧙

In conclusion, the development of this GitHub Action has been a highly rewarding process, full of valuable learnings about GitHub's ecosystem, CI/CD practices, Git operations, and the power of AI in automating mundane tasks.

Additional Resources/Info

Here are some helpful resources that guided me in this project:

A big thank you to @mishmanners, @github, and dev.to for such a fun 10 days 😅

Feel free to give OpenCommit a try in your projects, and any feedback is welcomed!

I need to get some sleep now

GitHubHack23 🪩


This content originally appeared on DEV Community and was authored by Dima Sukharev


Print Share Comment Cite Upload Translate Updates
APA

Dima Sukharev | Sciencx (2023-05-21T12:02:07+00:00) OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫. Retrieved from https://www.scien.cx/2023/05/21/opencommit-github-action-to-improve-commits-with-meaningful-messages-on-every-git-push-%f0%9f%a4%af%f0%9f%94%ab/

MLA
" » OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫." Dima Sukharev | Sciencx - Sunday May 21, 2023, https://www.scien.cx/2023/05/21/opencommit-github-action-to-improve-commits-with-meaningful-messages-on-every-git-push-%f0%9f%a4%af%f0%9f%94%ab/
HARVARD
Dima Sukharev | Sciencx Sunday May 21, 2023 » OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫., viewed ,<https://www.scien.cx/2023/05/21/opencommit-github-action-to-improve-commits-with-meaningful-messages-on-every-git-push-%f0%9f%a4%af%f0%9f%94%ab/>
VANCOUVER
Dima Sukharev | Sciencx - » OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/05/21/opencommit-github-action-to-improve-commits-with-meaningful-messages-on-every-git-push-%f0%9f%a4%af%f0%9f%94%ab/
CHICAGO
" » OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫." Dima Sukharev | Sciencx - Accessed . https://www.scien.cx/2023/05/21/opencommit-github-action-to-improve-commits-with-meaningful-messages-on-every-git-push-%f0%9f%a4%af%f0%9f%94%ab/
IEEE
" » OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫." Dima Sukharev | Sciencx [Online]. Available: https://www.scien.cx/2023/05/21/opencommit-github-action-to-improve-commits-with-meaningful-messages-on-every-git-push-%f0%9f%a4%af%f0%9f%94%ab/. [Accessed: ]
rf:citation
» OpenCommit: GitHub Action to improve commits with meaningful messages on every `git push` 🤯🔫 | Dima Sukharev | Sciencx | https://www.scien.cx/2023/05/21/opencommit-github-action-to-improve-commits-with-meaningful-messages-on-every-git-push-%f0%9f%a4%af%f0%9f%94%ab/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.