git-pivotal-tracker-integration 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -1
  3. data/bin/git-finish +16 -2
  4. data/bin/git-release +19 -0
  5. data/bin/git-start +16 -2
  6. data/lib/git-pivotal-tracker-integration/command/base.rb +47 -0
  7. data/lib/git-pivotal-tracker-integration/{base.rb → command/command.rb} +3 -14
  8. data/lib/git-pivotal-tracker-integration/command/configuration.rb +92 -0
  9. data/lib/git-pivotal-tracker-integration/command/finish.rb +36 -0
  10. data/lib/git-pivotal-tracker-integration/command/prepare-commit-msg.sh +26 -0
  11. data/lib/git-pivotal-tracker-integration/command/release.rb +56 -0
  12. data/lib/git-pivotal-tracker-integration/command/start.rb +64 -0
  13. data/lib/git-pivotal-tracker-integration/util/git.rb +242 -0
  14. data/lib/git-pivotal-tracker-integration/util/shell.rb +36 -0
  15. data/lib/git-pivotal-tracker-integration/util/story.rb +128 -0
  16. data/lib/git-pivotal-tracker-integration/util/util.rb +20 -0
  17. data/lib/git-pivotal-tracker-integration/version-update/gradle.rb +64 -0
  18. data/lib/git-pivotal-tracker-integration/version-update/version_update.rb +20 -0
  19. data/lib/git_pivotal_tracker_integration.rb +18 -0
  20. data/spec/git-pivotal-tracker-integration/command/base_spec.rb +38 -0
  21. data/spec/git-pivotal-tracker-integration/command/configuration_spec.rb +91 -0
  22. data/spec/git-pivotal-tracker-integration/command/finish_spec.rb +45 -0
  23. data/spec/git-pivotal-tracker-integration/command/release_spec.rb +57 -0
  24. data/spec/git-pivotal-tracker-integration/command/start_spec.rb +50 -0
  25. data/spec/git-pivotal-tracker-integration/util/git_spec.rb +239 -0
  26. data/spec/git-pivotal-tracker-integration/util/shell_spec.rb +52 -0
  27. data/spec/git-pivotal-tracker-integration/util/story_spec.rb +137 -0
  28. data/spec/git-pivotal-tracker-integration/version-update/gradle_spec.rb +74 -0
  29. metadata +104 -21
  30. data/lib/git-pivotal-tracker-integration/finish.rb +0 -106
  31. data/lib/git-pivotal-tracker-integration/pivotal_configuration.rb +0 -90
  32. data/lib/git-pivotal-tracker-integration/prepare-commit-msg.sh +0 -12
  33. data/lib/git-pivotal-tracker-integration/start.rb +0 -167
@@ -1,106 +0,0 @@
1
- # Git Pivotal Tracker Integration
2
- # Copyright (c) 2013 the original author or authors.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- require "git-pivotal-tracker-integration/base"
17
-
18
- class Finish < Base
19
-
20
- def run
21
- development_branch = current_branch
22
- merge_target_branch = PivotalConfiguration.merge_target
23
- merge_remote = PivotalConfiguration.merge_remote
24
- story_id = PivotalConfiguration.story_id
25
-
26
- check_trivial_merge development_branch, merge_target_branch, merge_remote
27
- merge_branch development_branch, merge_target_branch, story_id
28
- delete_branch development_branch
29
- push merge_remote
30
- end
31
-
32
- private
33
-
34
- def check_trivial_merge(development_branch, merge_target_branch, merge_remote)
35
-
36
- print "Checking for trivial merge from #{development_branch} to #{merge_target_branch}... "
37
- `git fetch #{merge_remote}`
38
- if $?.to_i != 0
39
- abort "FAIL"
40
- end
41
-
42
- remote_tip = `git rev-parse #{merge_remote}/#{merge_target_branch}`
43
- if $?.to_i != 0
44
- abort "FAIL"
45
- end
46
-
47
- local_tip = `git rev-parse #{merge_target_branch}`
48
- if $?.to_i != 0
49
- abort "FAIL"
50
- end
51
-
52
- if remote_tip != local_tip
53
- abort "FAIL"
54
- end
55
-
56
- common_ancestor = `git merge-base #{merge_target_branch} #{development_branch}`
57
- if $?.to_i != 0
58
- abort "FAIL"
59
- end
60
-
61
- if local_tip != common_ancestor
62
- abort "FAIL"
63
- else
64
- puts "OK"
65
- end
66
-
67
- end
68
-
69
- def merge_branch(development_branch, merge_target_branch, story_id)
70
- print "Merging #{development_branch} to #{merge_target_branch}... "
71
-
72
- `git checkout --quiet #{merge_target_branch}`
73
- if $?.to_i != 0
74
- abort "FAIL"
75
- end
76
-
77
- `git merge --quiet --no-ff --m "Merge #{development_branch} to #{merge_target_branch}\n\n[Completes ##{story_id}]" #{development_branch}`
78
- if $?.to_i != 0
79
- abort "FAIL"
80
- else
81
- puts "OK"
82
- end
83
-
84
- end
85
-
86
- def delete_branch(development_branch)
87
- print "Deleting #{development_branch}... "
88
-
89
- `git branch -D #{development_branch}`
90
- if $?.to_i != 0
91
- abort "FAIL"
92
- else
93
- puts "OK"
94
- end
95
- end
96
-
97
- def push(merge_remote)
98
- print "Pushing to #{merge_remote}... "
99
- `git push --quiet #{merge_remote}`
100
- if $?.to_i != 0
101
- abort "FAIL"
102
- else
103
- puts "OK"
104
- end
105
- end
106
- end
@@ -1,90 +0,0 @@
1
- # Git Pivotal Tracker Integration
2
- # Copyright (c) 2013 the original author or authors.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- require "highline/import"
17
- require "pivotal-tracker"
18
-
19
- class PivotalConfiguration
20
-
21
- def self.api_token
22
- api_token = `git config #{@@KEY_API_TOKEN}`
23
-
24
- if api_token.nil? || api_token.empty?
25
- api_token = ask("Pivotal API Key (found at https://www.pivotaltracker.com/profile): ")
26
- `git config --global #{@@KEY_API_TOKEN} #{api_token}`
27
- puts
28
- end
29
-
30
- api_token.strip
31
- end
32
-
33
- def self.merge_remote
34
- `git config branch.#{merge_target}.#{@@KEY_REMOTE}`.strip
35
- end
36
-
37
- def self.merge_target
38
- `git config branch.#{branch_name}.#{@@KEY_MERGE_TARGET}`.strip
39
- end
40
-
41
- def self.merge_target=(value)
42
- `git config --local branch.#{branch_name}.#{@@KEY_MERGE_TARGET} #{value}`
43
- $? != 0
44
- end
45
-
46
- def self.story_id
47
- `git config branch.#{branch_name}.#{@@KEY_STORY_ID}`.strip
48
- end
49
-
50
- def self.story_id=(value)
51
- `git config --local branch.#{branch_name}.#{@@KEY_STORY_ID} #{value}`
52
- $? != 0
53
- end
54
-
55
- def self.project_id
56
- project_id = `git config #{@@KEY_PROJECT_ID}`
57
-
58
- if project_id.nil? || project_id.empty?
59
- project_id = choose do |menu|
60
- menu.prompt = "Choose project associated with this repository: "
61
-
62
- PivotalTracker::Project.all.sort_by { |project| project.name }.each do |project|
63
- menu.choice(project.name) { project.id }
64
- end
65
- end
66
-
67
- `git config --local #{@@KEY_PROJECT_ID} #{project_id}`
68
- puts
69
- end
70
-
71
- project_id.strip
72
- end
73
-
74
- private
75
-
76
- @@KEY_API_TOKEN = "pivotal.api-token"
77
-
78
- @@KEY_MERGE_TARGET = "pivotal-merge-target"
79
-
80
- @@KEY_PROJECT_ID = "pivotal.project-id"
81
-
82
- @@KEY_REMOTE = "remote"
83
-
84
- @@KEY_STORY_ID = "pivotal-story-id"
85
-
86
- def self.branch_name
87
- `git branch`.scan(/\* (.*)/)[0][0]
88
- end
89
-
90
- end
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- CURRENT_BRANCH=$(git branch | grep "*" | sed "s/* //")
4
- STORY_ID=$(git config branch.$CURRENT_BRANCH.pivotal-story-id)
5
-
6
- if [[ -n $STORY_ID ]]; then
7
- ORIG_MSG_FILE="$1"
8
- TEMP=$(mktemp /tmp/git-XXXXX)
9
-
10
- (printf "\n\n[#$STORY_ID]" ; cat "$1") > "$TEMP"
11
- cat "$TEMP" > "$ORIG_MSG_FILE"
12
- fi
@@ -1,167 +0,0 @@
1
- # Git Pivotal Tracker Integration
2
- # Copyright (c) 2013 the original author or authors.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- require "git-pivotal-tracker-integration/base"
17
- require "highline/import"
18
-
19
- class Start < Base
20
-
21
- def initialize(args)
22
- super()
23
-
24
- if args[0] =~ /[[:digit:]]/
25
- @story = @project.stories.find(args[0].to_i)
26
- elsif args[0] =~ /[[:alpha:]]/
27
- @story = choose do |menu|
28
- menu.prompt = "Choose story to start: "
29
-
30
- @project.stories.all(
31
- :story_type => args[0],
32
- :current_state => ["unstarted", "unscheduled"],
33
- :limit => 5
34
- ).each do |story|
35
- menu.choice(story.name) { story }
36
- end
37
- end
38
-
39
- puts
40
- else
41
- @story = choose do |menu|
42
- menu.prompt = "Choose story to start: "
43
-
44
- @project.stories.all(
45
- :current_state => ["unstarted", "unscheduled"],
46
- :limit => 5
47
- ).each do |story|
48
- menu.choice("%-7s %s" % [story.story_type.upcase, story.name]) { story }
49
- end
50
- end
51
-
52
- puts
53
- end
54
- end
55
-
56
- def run
57
- print_info @story
58
- branch_name = branch_name @story
59
- create_branch @story, branch_name
60
- add_commit_hook
61
- start_on_tracker @story
62
- end
63
-
64
- private
65
-
66
- @@LABEL_WIDTH = 13
67
-
68
- @@CONTENT_WIDTH = HighLine.new.output_cols - @@LABEL_WIDTH
69
-
70
- def print_info(story)
71
- print_label "Title"
72
- print_value story.name
73
-
74
- print_label "Description"
75
- print_value story.description
76
-
77
- PivotalTracker::Note.all(story).sort_by { |note| note.noted_at }.each_with_index do |note, index|
78
- print_label "Note #{index}"
79
- print_value note.text
80
- end
81
-
82
- puts
83
- end
84
-
85
- def print_label(label)
86
- print "%#{@@LABEL_WIDTH}s" % ["#{label}: "]
87
- end
88
-
89
- def print_value(value)
90
- if value.nil? || value.empty?
91
- puts ""
92
- else
93
- value.scan(/\S.{0,#{@@CONTENT_WIDTH - 2}}\S(?=\s|$)|\S+/).each_with_index do |line, index|
94
- if index == 0
95
- puts line
96
- else
97
- puts "%#{@@LABEL_WIDTH}s%s" % ["", line]
98
- end
99
- end
100
- end
101
- end
102
-
103
- def branch_name(story)
104
- branch = "#{story.id}-" + ask("Enter branch name (#{story.id}-<branch-name>): ")
105
- puts
106
- branch
107
- end
108
-
109
- def create_branch(story, development_branch)
110
- merge_target_branch = current_branch
111
-
112
- print "Pulling #{merge_target_branch}... "
113
- `git pull --quiet --ff-only`
114
- if $?.to_i != 0
115
- abort "FAIL"
116
- else
117
- puts "OK"
118
- end
119
-
120
- print "Creating and checking out #{development_branch}... "
121
- `git checkout --quiet -b #{development_branch}`
122
- if $?.to_i != 0
123
- abort "FAIL"
124
- end
125
-
126
- PivotalConfiguration.merge_target = merge_target_branch
127
- if $?.to_i != 0
128
- abort "FAIL"
129
- end
130
-
131
- PivotalConfiguration.story_id = story.id
132
- if $?.to_i != 0
133
- abort "FAIL"
134
- else
135
- puts "OK"
136
- end
137
- end
138
-
139
- def add_commit_hook
140
- repository_root = File.expand_path Dir.pwd
141
-
142
- until Dir.entries(repository_root).any? { |child| child =~ /.git/ }
143
- repository_root = File.expand_path("..", repository_root)
144
- end
145
-
146
- commit_hook = File.join(repository_root, ".git", "hooks", "prepare-commit-msg")
147
- if !File.exist? commit_hook
148
- print "Creating commit hook... "
149
-
150
- File.open(File.join(File.dirname(__FILE__), "prepare-commit-msg.sh"), "r") do |source|
151
- File.open(commit_hook, "w") do |target|
152
- target.write(source.read)
153
- target.chmod(0755)
154
- end
155
- end
156
-
157
- puts "OK"
158
- end
159
- end
160
-
161
- def start_on_tracker(story)
162
- print "Starting story on Pivotal Tracker... "
163
- story.update(:current_state => "started")
164
- puts "OK"
165
- end
166
-
167
- end