Read more

Bookmarklet to generate a commit message with Pivotal Tracker story ID and title

Henning Koch
November 15, 2010Software engineer at makandra GmbH

For clarity and traceability, your commit messages should include the ID and title of the Pivotal Tracker story you're working on. For example:

[#12345] Add Google Maps to user profiles
Optional further commit messages in the body
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Also see Howto: Write a proper git commit message

To quickly generate such commit messages, add a new link "Commit" to your bookmarks and use the following Javascript as the link URL:

javascript:(function() { 
  let storyTitles = [];
  let stories = Array.from(document.querySelectorAll('.story[data-selected="true"]')).map((element) => element.closest('.story'));
  let collapsed = true;
  
  if (stories.length == 0) { stories = Array.from(document.querySelectorAll('.story .details')).map((element) => element.closest('.story')); collapsed = false; } 
  stories.forEach((story) => {
    let title = (collapsed ? story.querySelector('[data-aid="StoryPreviewItem__title"]').innerText : story.querySelector('[name="story[name]"]').value);
    let id = story.dataset.id;
    if (id && title) { let gitptTitle = '[#' + id + '] ' + title; if (storyTitles.indexOf(gitptTitle) == -1) { storyTitles.push(gitptTitle); } }
   });
   
   if (storyTitles.length > 0) { prompt('Your commit message:', storyTitles.join('; ')); } else { alert("Please select the stories first."); } 
 })();

When you now open one or more stories in Pivotal Tracker and hit the bookmarklet, it will display a prompt with a commit message. You can also select the stories using the blue box next to them.

To add the bookmarklet to Firefox first add a new bookmark then right click the bookmark and open properties. Paste your code snippet in the location field.

We also have a shell script for this.

Posted by Henning Koch to makandra dev (2010-11-15 15:07)