Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating release notes from git commits

Tags:

git

ruby

rake

I've created the following rake task below to generate our release notes for each sprint.
I'm pulling in all commits to master older than 2 weeks.

The problem is when a branch has been developed on for more than 2-week sprints, the older commits won't be included.

Can anyone suggest a way I can get these commits in?

task :new_release_note do

  puts "Creating new release note"
  puts "..."

  git_log = `git log --since="two weeks ago" --no-merges --format=%B`
  git_log.gsub!(/^$\n/, '')
  git_log.gsub!(/^/, "* ") 

  current_time = DateTime.now 
  current_date = current_time.strftime "%Y-%m-%d"
  current_date_UK = current_time.strftime "%d-%m-%Y"

  template = "__Release Notes__
  =======================
  #{current_date_UK}

  __New Features__
  ----------------

  * -


  __Improvements__
  ----------------

  * -


  __Fixes__
  ---------

  * -


  __Change Log__
  ----------------

  Detailed release notes below, listing all commit messages for this release.


  #{git_log}
  "

  out_file = File.new("./doc/release_notes/release-notes-#{current_date}.md", "w")
  out_file.puts(template)

  if File.exist?(out_file) 
    puts "New release note generated successfully at /doc/release-notes/release-notes-#{current_date}.md"
  else 
    puts "Error - file not generated."
  end 

end
like image 884
s89_ Avatar asked Nov 09 '18 22:11

s89_


2 Answers

Can anyone suggest a way I can get these commits in?

Few options:

  1. git tag
  2. git notes
  3. git whatchanged

git tag

Read this answer on what is git tag and how to use it: What is git tag, How to create tags & How to checkout git remote tag(s)

In short: git tag allows you to mark commit which can be later on to perform your merge. As you know

git pull = git fetch + git merge

So once you have marked your last merge with the tag you can pull out all the changes form the last merge

# "Merge" the last X commits based upon your previous tag
git cherry-pick <tag_name>..master

git notes

git notes allow us to add content to commit without updating the SHA-1 of the commit, meaning we can attach content to the commit while leaving the SHA-1 unmodified.

enter image description here

Now once you have your notes you can find out the last commit which you "merged" previously and grab the changes from this point on using the above cherry-pick.

You can search and find your notes with git log --grep


git whatchanged

Once you what is your referenced commit you can see the list of files which were updated during this time period with the git whatchanged command

# Print out a list of files which was updated/added between the 2 commits
git whatchanged <TAG_NAME>...HEAD

enter image description here

like image 115
CodeWizard Avatar answered Sep 25 '22 04:09

CodeWizard


Consider using git tag and tag your releases with version numbers. What my team does is to create a release branch with a version number for each release i.e. release-2.5.8 and when the release is ready, it gets merged into master. Then we tag that merge commit with a version number i.e. v2.5.8 If you do this, along with squash merges then to see all the related commits it's as easy as doing:

git log v2.5.8...v2.5.9

Which will show you all the commits within those 2 releases.

The reason I recommend squash merging your feature branch is for exactly your use case. You want to know what was done during the dev of that feature, but how can you just by date? You really can't. So when your feature is ready to be merged into your release, if you squash merge, you can keep all the notes in a single commit for the merge of that feature. The idea here is you keep what is relevant and discard what is no longer needed during development.

You might also want to check out Gitflow

like image 30
lacostenycoder Avatar answered Sep 25 '22 04:09

lacostenycoder