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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)