Forked from jondkinney/pivotal_tracker_git_flow.rake
Last active
December 30, 2015 10:09
-
-
Save hadees/7814080 to your computer and use it in GitHub Desktop.
Yet another attempt at Git and Pivotal integration. The twist with this one though is an attempt to work with git-flow. This was inspired by this blog post: http://pivotallabs.com/level-up-your-development-workflow-with-github-pivotal-tracker/ It'll also require https://github.com/petervanderdoes/gitflow once I write the hook.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# gem 'pivotal-tracker' | |
require 'pivotal-tracker' | |
TRACKER_TOKEN = `git config --get pivotal.token` | |
TRACKER_PROJECT_ID = `git config --get pivotal.project-id` | |
PivotalTracker::Client.token = TRACKER_TOKEN | |
PivotalTracker::Client.use_ssl = true | |
def truncate_words(text, length = 5) | |
return if text == nil | |
words = text.split() | |
words = words - %w(feature scenario for in on a an the of so that they be able to are it its with) #remove non critical words (experiment with this) | |
words[0..(length-1)].join(' ') | |
end | |
project = PivotalTracker::Project.find TRACKER_PROJECT_ID | |
conditions = {:state => ["rejected", "started", "unstarted", "finished"]} | |
projects = project.stories.all(conditions) | |
if projects.count > 0 | |
branches = [] | |
projects.each_with_index do |story, index| | |
name = story.name.downcase | |
# remove individual offending chars: single quote, double quote, open | |
# paren, close paren, colon, backslash, forwardslash and replace with | |
# an empty string (aka nothing) | |
name.gsub!(/['"\.\(\):\\\/]/,"") | |
# remove remaining cl.ly links | |
name.gsub!(/httpclly\S*/,"") | |
# remove dash and replace with space | |
name.gsub!(/-/," ") | |
# do the truncate here, after all the removal & before the _ injection | |
name = truncate_words(name) | |
# replace all instances of one or more spaces with _ | |
name.gsub!(/\s+/,"_") | |
# create final display | |
display = "#{name}_#{story.id}" | |
branches[index + 1] = "#{display}" | |
puts "(#{index + 1}) #{display}" | |
end | |
puts "" | |
puts "(0) EXIT WITHOUT ANY ACTION" | |
puts "" | |
puts "For which story do you want to create a new git feature branch?" | |
puts " Note: type 1,hotfix to create a hotfix for the first story" | |
input = STDIN.gets.strip | |
story_num = input.split(",")[0].to_i | |
story_type = input.split(",")[1] | |
story_type ||= "feature" | |
if (1..projects.count).include?(story_num) | |
`git flow #{story_type} start "#{branches[story_num]}"` | |
puts "" | |
puts "Summary of actions:" | |
puts "- A new branch '#{story_type}/#{branches[story_num]}' was created, based on '#{story_type == 'feature' ? 'develop' : 'master'}'" | |
puts "- You are now on branch '#{story_type}/#{branches[story_num]}'" | |
puts "" | |
puts "Now, start committing on your #{story_type}. When done, use:" | |
puts "" | |
puts " git flow #{story_type} finish #{branches[story_num]}" | |
puts "" | |
else | |
exit | |
end | |
else | |
puts "There are no available stories right now!" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------------------------------- | |
// | |
// ==UserScript== | |
// @name Link to Story 2 | |
// @namespace loominate.net | |
// @version 1.4 | |
// @description Used on github.com to convert a story id to a link to the pivotal tracker story. | |
// @include https://github.com/*/commits/* | |
// @include https://github.com/*/commits | |
// @include https://github.com/*/commit/* | |
// @include https://github.com/*/pull/* | |
// ==/UserScript== | |
"use strict"; | |
var regex = /\[[^\]]*#([0-9]{8}).*\]/; | |
function alwaysTrue(x) { return true; } | |
function createLinksToStories(className, elementFilter) | |
{ | |
if (!elementFilter) { | |
elementFilter = alwaysTrue; | |
} | |
var elements = document.getElementsByClassName(className); | |
for (var index in elements) { | |
var element = elements[index]; | |
if (elementFilter(element)) { | |
var matches = regex.exec(element.innerHTML); | |
if (matches) { | |
element.innerHTML = element.innerHTML + "<a href='https://www.pivotaltracker.com/story/show/" + matches[1] + "'><img src='https://www.pivotaltracker.com/favicon.ico'/></a>" | |
} | |
} | |
} | |
} | |
var pullRequestRegex = new RegExp("https://github.com/.*/.*/pull/[0-9]*"); | |
function isPullRequestPage() { | |
return pullRequestRegex.test(document.location); | |
} | |
function isAnchor(element) { | |
return (element.localName === "a"); | |
} | |
createLinksToStories('commit-title'); | |
createLinksToStories('content-title'); | |
if (isPullRequestPage()) { | |
createLinksToStories('message', isAnchor); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Runs at the end of git flow feature finish | |
# | |
#!/bin/sh | |
# | |
# Runs before git flow feature finish | |
# | |
# Positional arguments: | |
# $1 The friendly name of the branch | |
# $2 The origin remote | |
# $3 The full branch name (including the feature prefix) | |
# | |
# The following variables are available as they are exported by git-flow: | |
# | |
# MASTER_BRANCH - The branch defined as Master | |
# DEVELOP_BRANCH - The branch defined as Develop | |
# | |
NAME=$1 | |
ORIGIN=$2 | |
BRANCH=$3 | |
TRACKER_ID=`echo $BRANCH | ruby -ne 'puts $1 if /(\d+)$/'` | |
COMMIT_MSG=`git log $BRANCH -1 --pretty=%s` | |
`git commit --amend -m '$COMMIT_MSG'` | |
# Implement your script here. | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# This hook script will automatically add the Pivotal Tracker ID | |
# to the beginning of the git commit message (in the format of | |
# [#12345678]) if it is not already there. | |
# | |
# The script pulls the ID from the end of the branch name. If | |
# the branch name does not end with the Pivotal Tracker ID, then | |
# this script will do nothing. | |
# | |
# Specifying the Pivotal Tracker ID in the git commit message allows | |
# Pivotal to list all commits associated with a story when the | |
# story is viewed. | |
# | |
# To enble this script, copy it to .git/hooks/prepare-commit-msg | |
# in your repo's directory. | |
# | |
COMMIT_MSG_FILE=$1 | |
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
TRACKER_ID=`echo $CURRENT_BRANCH | ruby -ne 'puts $1 if /(\d+)$/'` | |
# Make sure the branch name starts with what looks like a tracker ID | |
if [ "$TRACKER_ID" != "" ]; then | |
# If we could not find the tracker ID in the commit message in the | |
# proper format, then add it. | |
grep -q "\[#$TRACKER_ID\]" $COMMIT_MSG_FILE | |
if [ $? -eq 1 ]; then | |
sed "1s/^/[#$TRACKER_ID] /" $COMMIT_MSG_FILE > /tmp/tracker_git_commit_msg | |
mv /tmp/tracker_git_commit_msg $COMMIT_MSG_FILE | |
fi | |
fi | |
# Explicitly exit 0 to make sure we don't accidentally abort the commit | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment