validate the css validate the xhtml

HackerMoJo.com


Ceci n'est pas une blog
by Glenn Franxman, Django Developer / Stunt Programmer.

Harnessing the Power of an LLM for Git Commit Messages

posted: 2023-08-18 14:22:33

The integration of intelligent systems into developer workflows has always been a topic of great interest. With the evolution of the GPT series and similar language models, there are innumerable opportunities to automate and enhance various aspects of software engineering. One of these is generating commit messages. Have you ever found yourself pausing for a bit too long, thinking about the ideal way to phrase a commit? Enter the Language Model!

In this post, we'll explore an ingenious use of an LLM (Large Language Model) to automatically draft the first version of your git commit messages.

REL_NOTES_RAW=`git diff --staged | llm -s "release notes" 2>/dev/null`
REL_NOTES_RAW=$(echo "$REL_NOTES_RAW" | sed 's/^#/* /')
echo RAW: $REL_NOTES_RAW

#on bsd style systems, like OSX, sed is sentitive to newlines so back to awk:
REL_NOTES_ESCAPED=$(echo "$REL_NOTES_RAW" | awk '{print $0 "\\n"}')

# on GNU based systems
#REL_NOTES_ESCAPED=$(echo "$REL_NOTES_RAW" | sed ':a;N;$!ba;s/\n/\\n/g')

echo ESCAPED: $REL_NOTES_ESCAPED

REL_NOTES=$(echo "$REL_NOTES" | sed 's/^/# /')

# prepend to commit msg file
# if you want the rel notes as comments
#awk -v r="$REL_NOTES" 'NR==1 {print r} {print}' "$COMMIT_MSG_FILE" > tmpfile && mv tmpfile "$COMMIT_MSG_FILE"
# or ready to go:
awk -v r="$REL_NOTES_RAW" 'NR==1 {print r} {print}' "$COMMIT_MSG_FILE" > tmpfile && mv tmpfile "$COMMIT_MSG_FILE"

It took many revisions to get that working. My local version looks much worse, so I asked Chat-GPT to break it down for me and here's what I got:


Of course! Let's break down the provided code snippet step-by-step.

1. Capture Staged Changes for Release Notes:


REL_NOTES_RAW=`git diff --staged | llm -s "release notes" 2>/dev/null`

This command captures the changes you've staged for the next commit and sends them to the llm (which presumably stands for a Large Language Model) for processing. The goal is to get a summarized "release notes" version of the changes. Any errors in the process are discarded with 2>/dev/null.

2. Transform Release Notes Formatting:


REL_NOTES_RAW=$(echo "$REL_NOTES_RAW" | sed 's/^#/* /')
echo RAW: $REL_NOTES_RAW

If the LLM prefixes any lines with #, this command replaces them with bullet points (*). The transformed release notes are then printed to the console.

3. Escape Newlines for Different Systems:
For BSD-style Systems (like OSX):


REL_NOTES_ESCAPED=$(echo "$REL_NOTES_RAW" | awk '{print $0 "\\n"}')

On BSD systems, sed is sensitive to newline characters, so we use awk to escape them properly.

For GNU-based Systems:


#REL_NOTES_ESCAPED=$(echo "$REL_NOTES_RAW" | sed ':a;N;$!ba;s/\n/\\n/g')

On GNU systems, you'd use this sed command to escape newline characters. It's commented out because it's an alternative to the BSD-style command above.

After the appropriate newline escaping, the formatted release notes are printed:


echo ESCAPED: $REL_NOTES_ESCAPED

4. Optional Step to Prefix Each Line with #:


REL_NOTES=$(echo "$REL_NOTES" | sed 's/^/# /')

This is an optional step if you want each line of the release notes to be commented out (perhaps for manual review before finalizing the commit message).

5. Prepend Processed Notes to Commit Message:

If you want the release notes as comments:


#awk -v r="$REL_NOTES" 'NR==1 {print r} {print}' "$COMMIT_MSG_FILE" > tmpfile && mv tmpfile "$COMMIT_MSG_FILE"

This command uses awk to insert the commented-out release notes at the top of the commit message file. It's commented out because you would use one of the two awk commands based on your preference.

If you want the release notes ready to go:


awk -v r="$REL_NOTES_RAW" 'NR==1 {print r} {print}' "$COMMIT_MSG_FILE" > tmpfile && mv tmpfile "$COMMIT_MSG_FILE"

This command inserts the raw release notes (without the # prefix) at the beginning of your commit message file.

In both cases, the changes are written to a temporary file (tmpfile), which then replaces the original commit message file. This ensures that the original file isn't lost if something goes wrong during the process.

Conclusion:

The script captures the diff of your staged changes, processes them with an LLM to get a summarized "release notes" style output, formats this output, and then prepends it to your commit message. This can be particularly handy for automating commit messages based on the content of the changes you've made.


That's amazing. That's exactly the kind of clarity I wanted for my commit messages.

- And once installed in your prepare_commit_msg hook you're good to go.

- No more need to ponder over how to describe the commit. Let the model summarize it for you.

- Get standardized commit messages, especially useful if multiple developers are collaborating.

- The LLM provides clear notes, making it easier to understand the intent and content of the commit.

Automation in software engineering doesn't just pertain to CI/CD pipelines or testing. As demonstrated, with the power of an LLM, even tasks as seemingly trivial as drafting a commit message can be automated, saving time and ensuring consistency.

However, it's worth noting that while LLMs are powerful, they are not infallible. Always review the generated commit messages to ensure they accurately represent your changes.

Happy coding, and may your commit messages always be clear and concise!

Am I full of shit? Tell me why. [ 1 remarks ]


A note from the author

HackerMojo.com is using a fluid layout based upon work by Dave Reeder. I'm trying to take CSS a little more seriously; but I'm having a hard time because of all of the bad syntax, browser compatibility hacks, and non-fluid layouts. If any of the other technology I used were like CSS, I'd have to set myself on fire and jump off of a cliff.

Lab Sites

* denotes django powered sites.

Django Admin ordered how you like

posted: 2023-05-08 17:55:15

I got so tired and irritated by Django's alphabetical sorting of apps and models in the admin.

Read More [ 1 remarks ]

Local Sites

* denotes sites I'm associated with.

Polars vs Pandas

posted: 2023-02-05 12:26:28

How to choose between Pandas and Polars for python data projects.

Read More [ 1 remarks ]

Delta VS Iceberg

posted: 2023-02-05 11:36:05

Delta tables and Iceberg are both technologies that enable big data management on distributed systems such as Apache Spark, but there are several key differences between the two.

Read More

Building a medallion style delta lake with Databricks

posted: 2023-02-05 11:30:46

This is the simplest recipe for getting started with a medallion style delta lake with Databricks.

The steps/commands can be summarized as:

Read More

FitBit Found!

posted: 2012-09-03 12:51:44

As part of a corporate fitness program I received a fitbit. It loved it so much that I bought a second one for my wife. Then, one day, it happened. I lost my fitbit.

Read More [ 1416 remarks ]

Mo betta spam

posted: 2012-09-03 11:48:58

What made me look at this blog for the first time in quite a while was hearing my wife talk about changes to the comment system on gawker. When I looked at my own blog spam, I saw something interesting...

Read More [ 2620 remarks ]

Long time, no blog

posted: 2012-09-03 11:00:37

Man, it has been about 2 years since I gave this blog any love. Clearly it needs to be updated. Maybe during some upcoming vacation time it. The real reasons that this bog has died:

Read More [ 674 remarks ]

DropBox

posted: 2010-03-22 14:18:29

You need DropBox and I need some extra dropbox space. If you use this link then we both win and we both get free extra space! You know what to do.

Leave a Comment [ 842 remarks ]

There are 286 entries like these. Check 'em out

Copyright © 2003,2004,2005,2006,2007,2008 GFranxman. All Rights Reserved


hosting: slicehost.com. powered by: django. written in: python. controlled by: bzr. monsters by: monsterID.