git-pivotal-tracker-integration 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e313260ee2c9f795dcb3f8bcdf33e3c1fbf18be
4
+ data.tar.gz: c5ea1e9bc2986243a7a08fcc972749de53a0696b
5
+ SHA512:
6
+ metadata.gz: 45947162703d4598865b38dfaec580b703ed5db0f17d1a3d6225603645003f721f06c6f06bf5183c3e405f55d91520bb1ece69ff88b0dfe13ef153a307779895
7
+ data.tar.gz: 0e5afb43bb8e57c391c3f9ebfb2d6ab4065bea60f48578ace2ff8c2c3f6b110e19f3b526b3a72a83068b09d8b716c2849b047a16d3ec235146e7eaffd1497ecb
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Git Pivotal Tracker Integration
2
+ Copyright 2013 the original author or authors.
@@ -0,0 +1,135 @@
1
+ # Git Pivotal Tracker Integration
2
+
3
+ `git-pivotal-tracker-integration` provides a set of additional Git commands to help developers when working with [Pivotal Tracker][pivotal-tracker].
4
+
5
+ [pivotal-tracker]: http://www.pivotaltracker.com
6
+
7
+
8
+ ## Installation
9
+ `git-pivotal-tracker-integration` requires at least **Ruby 2.0.0** and **Git 1.8.2.1** in order to run. In order to install it, do the following:
10
+
11
+ ```plain
12
+ $ gem install git-pivotal-tracker-integration
13
+ ```
14
+
15
+
16
+ ## Usage
17
+ `git-pivotal-tracker-integration` is intended to be a very lightweight tool, meaning that it won't affect your day to day workflow very much. To be more specific, it is intended to automate branch creation and destruction as well as story state changes, but will not affect when you commit, when development branches are pushed to origin, etc. The typical workflow looks something like the following:
18
+
19
+ ```plain
20
+ $ git start # Creates branch and starts story
21
+ $ git commit ...
22
+ $ git commit ... # Your existing development process
23
+ $ git commit ...
24
+ $ git finish # Merges and destroys branch, pushes to origin, and finishes story
25
+ ```
26
+
27
+
28
+ ## Configuration
29
+
30
+ ### Git Client
31
+ In order to use `git-pivotal-tracker-integration`, two Git client configuration properties must be set. If these properties have not been set, you will be prompted for them and your Git configuration will be updated.
32
+
33
+ | Name | Description
34
+ | ---- | -----------
35
+ | `pivotal.api-token` | Your Pivotal Tracker API Token. This can be found in [your profile][profile] and should be set globally.
36
+ | `pivotal.project-id` | The Pivotal Tracker project id for the repository your are working in. This can be found in the project's URL and should be set.
37
+
38
+ [profile]: https://www.pivotaltracker.com/profile
39
+
40
+
41
+ ### Git Server
42
+ In order to take advantage of automatic issue completion, the [Pivotal Tracker Source Code Integration][integration] must be enabled. If you are using GitHub, this integration is easy to enable by navgating to your project's 'Service Hooks' settings and configuring it with the proper credentials.
43
+
44
+ [integration]: https://www.pivotaltracker.com/help/integrations?version=v3#scm
45
+
46
+
47
+ ## Commands
48
+
49
+ ### `git start [ type | issue ]`
50
+ This command starts a story by creating a Git branch and changing the story's state to `started`. This command can be run in three ways. First it can be run specifying the issue that you want to start.
51
+
52
+ ```plain
53
+ $ git start 12345678
54
+ ```
55
+
56
+ The second way to run the command is by specyifying the type of story that you would like to start. In this case it will then offer you the first five stories (based on the backlog's order) of that type to choose from.
57
+
58
+ ```plain
59
+ $ git start feature
60
+
61
+ 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit
62
+ 2. Pellentesque sit amet ante eu tortor rutrum pharetra
63
+ 3. Ut at purus dolor, vel ultricies metus
64
+ 4. Duis egestas elit et leo ultrices non fringilla ante facilisis
65
+ 5. Ut ut nunc neque, quis auctor mauris
66
+ Choose story to start:
67
+ ```
68
+
69
+ Finally the command can be run without specifying anything. In this case, it will then offer the first five stories (based on the backlog's order) of any type to choose from.
70
+
71
+ ```plain
72
+ $ git start
73
+
74
+ 1. FEATURE Donec convallis leo mi, dictum ornare sem
75
+ 2. CHORE Sed et magna lectus, sed auctor purus
76
+ 3. FEATURE In a nunc et enim tincidunt interdum vitae et risus
77
+ 4. FEATURE Fusce facilisis varius lorem, at tristique sem faucibus in
78
+ 5. BUG Donec iaculis ante neque, ut tempus augue
79
+ Choose story to start:
80
+ ```
81
+
82
+ Once a story has been selected by one of the three methods, the command then prompts for the name of the branch to create.
83
+
84
+ ```plain
85
+ $ git start 12345678
86
+ Title: Lorem ipsum dolor sit amet, consectetur adipiscing elitattributes
87
+ Description: Ut consequat sapien ut erat volutpat egestas. Integer venenatis lacinia facilisis.
88
+
89
+ Enter branch name (12345678-<branch-name>):
90
+ ```
91
+
92
+ The value entered here will be prepended with the story id such that the branch name is `<project-id>-<branch-name>`. This branch is then created and checked out.
93
+
94
+ If it doesn't exist already, a `prepare-commit-msg` commit hook is added to your repository. This commit hook augments the existing commit messsage pattern by appending the story id to the message automatically.
95
+
96
+ ```plain
97
+
98
+
99
+ [#12345678]
100
+ # Please enter the commit message for your changes. Lines starting
101
+ # with '#' will be ignored, and an empty message aborts the commit.
102
+ # On branch 12345678-lorem-ipsum
103
+ # Changes to be committed:
104
+ # (use "git reset HEAD <file>..." to unstage)
105
+ #
106
+ # new file: dolor.txt
107
+ #
108
+ ```
109
+
110
+ ### `git finish`
111
+ This command finishes a story by merging and cleaning up its branch and then pushing the changes to a remote server. This command can only be run one way.
112
+
113
+ ```plain
114
+ $ git finish
115
+ Checking for trivial merge from 12345678-lorem-ipsum to master... OK
116
+ Merging 12345678-lorem-ipsum to master... OK
117
+ Deleting 12345678-lorem-ipsum... OK
118
+ Pushing to origin... OK
119
+ ```
120
+
121
+ The command checks that it will be able to do a trivial merge from the development branch to the target branch before it does anything. The check has the following constraints
122
+
123
+ 1. The local repository must be up to date with the remote repository (e.g. `origin`)
124
+ 2. The local merge target branch (e.g. `master`) must be up to date with the remote merge target branch (e.g. `origin/master`)
125
+ 3. The common ancestor (i.e. the branch point) of the development branch (e.g. `12345678-lorem-ipsum`) must be tip of the local merge target branch (e.g. `master`)
126
+
127
+ If all of these conditions are met, the development branch will be merged into the target branch with a message of:
128
+
129
+ ```plain
130
+ Merge 12345678-lorem-ipsum to master
131
+
132
+ [Completes #12345678]
133
+ ```
134
+
135
+ After merging, the development branch is deleted and the changes are pushed to the remote repository.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby -U
2
+
3
+ require "git-pivotal-tracker-integration/finish"
4
+
5
+ Finish.new().run
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby -U
2
+
3
+ require "git-pivotal-tracker-integration/start"
4
+
5
+ Start.new(ARGV).run
@@ -0,0 +1,31 @@
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/pivotal_configuration"
17
+ require "pivotal-tracker"
18
+
19
+ class Base
20
+
21
+ def initialize
22
+ PivotalTracker::Client.token = PivotalConfiguration.api_token
23
+ PivotalTracker::Client.use_ssl = true
24
+ @project = PivotalTracker::Project.find PivotalConfiguration.project_id
25
+ end
26
+
27
+ def current_branch
28
+ `git branch`.scan(/\* (.*)/)[0][0]
29
+ end
30
+
31
+ end
@@ -0,0 +1,106 @@
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
@@ -0,0 +1,90 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,162 @@
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
+ @story.update(:current_state => "started")
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
+
160
+ end
161
+
162
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-pivotal-tracker-integration
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Hale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.16
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.16
27
+ - !ruby/object:Gem::Dependency
28
+ name: pivotal-tracker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.10
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.10
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: "# Git Pivotal Tracker Integration\n\n`git-pivotal-tracker-integration`
70
+ provides a set of additional Git commands to help developers when working with [Pivotal
71
+ Tracker][pivotal-tracker].\n\n[pivotal-tracker]: http://www.pivotaltracker.com\n\n\n##
72
+ Installation\n`git-pivotal-tracker-integration` requires at least **Ruby 2.0.0**
73
+ and **Git 1.8.2.1** in order to run. In order to install it, do the following:\n\n```plain\n$
74
+ gem install git-pivotal-tracker-integration\n```\n\n\n## Usage\n`git-pivotal-tracker-integration`
75
+ is intended to be a very lightweight tool, meaning that it won't affect your day
76
+ to day workflow very much. To be more specific, it is intended to automate branch
77
+ creation and destruction as well as story state changes, but will not affect when
78
+ you commit, when development branches are pushed to origin, etc. The typical workflow
79
+ looks something like the following:\n\n```plain\n$ git start # Creates branch
80
+ and starts story\n$ git commit ...\n$ git commit ... # Your existing development
81
+ process\n$ git commit ...\n$ git finish # Merges and destroys branch, pushes
82
+ to origin, and finishes story\n```\n\n\n## Configuration\n\n### Git Client\nIn order
83
+ to use `git-pivotal-tracker-integration`, two Git client configuration properties
84
+ must be set. If these properties have not been set, you will be prompted for them
85
+ and your Git configuration will be updated.\n\n| Name | Description\n| ---- | -----------\n|
86
+ `pivotal.api-token` | Your Pivotal Tracker API Token. This can be found in [your
87
+ profile][profile] and should be set globally.\n| `pivotal.project-id` | The Pivotal
88
+ Tracker project id for the repository your are working in. This can be found in
89
+ the project's URL and should be set.\n\n[profile]: https://www.pivotaltracker.com/profile\n\n\n###
90
+ Git Server\nIn order to take advantage of automatic issue completion, the [Pivotal
91
+ Tracker Source Code Integration][integration] must be enabled. If you are using
92
+ GitHub, this integration is easy to enable by navgating to your project's 'Service
93
+ Hooks' settings and configuring it with the proper credentials.\n\n[integration]:
94
+ https://www.pivotaltracker.com/help/integrations?version=v3#scm\n\n\n## Commands\n\n###
95
+ `git start [ type | issue ]`\nThis command starts a story by creating a Git branch
96
+ and changing the story's state to `started`. This command can be run in three ways.
97
+ \ First it can be run specifying the issue that you want to start.\n\n```plain\n$
98
+ git start 12345678\n```\n\nThe second way to run the command is by specyifying the
99
+ type of story that you would like to start. In this case it will then offer you
100
+ the first five stories (based on the backlog's order) of that type to choose from.\n\n```plain\n$
101
+ git start feature\n\n1. Lorem ipsum dolor sit amet, consectetur adipiscing elit\n2.
102
+ Pellentesque sit amet ante eu tortor rutrum pharetra\n3. Ut at purus dolor, vel
103
+ ultricies metus\n4. Duis egestas elit et leo ultrices non fringilla ante facilisis\n5.
104
+ Ut ut nunc neque, quis auctor mauris\nChoose story to start:\n```\n\nFinally the
105
+ command can be run without specifying anything. In this case, it will then offer
106
+ the first five stories (based on the backlog's order) of any type to choose from.\n\n```plain\n$
107
+ git start\n\n1. FEATURE Donec convallis leo mi, dictum ornare sem\n2. CHORE Sed
108
+ et magna lectus, sed auctor purus\n3. FEATURE In a nunc et enim tincidunt interdum
109
+ vitae et risus\n4. FEATURE Fusce facilisis varius lorem, at tristique sem faucibus
110
+ in\n5. BUG Donec iaculis ante neque, ut tempus augue\nChoose story to start:\n```\n\nOnce
111
+ a story has been selected by one of the three methods, the command then prompts
112
+ for the name of the branch to create.\n\n```plain\n$ git start 12345678\n Title:
113
+ Lorem ipsum dolor sit amet, consectetur adipiscing elitattributes\n Description:
114
+ Ut consequat sapien ut erat volutpat egestas. Integer venenatis lacinia facilisis.\n\nEnter
115
+ branch name (12345678-<branch-name>):\n```\n\nThe value entered here will be prepended
116
+ with the story id such that the branch name is `<project-id>-<branch-name>`. This
117
+ branch is then created and checked out.\n\nIf it doesn't exist already, a `prepare-commit-msg`
118
+ commit hook is added to your repository. This commit hook augments the existing
119
+ commit messsage pattern by appending the story id to the message automatically.\n\n```plain\n\n\n[#12345678]\n#
120
+ Please enter the commit message for your changes. Lines starting\n# with '#' will
121
+ be ignored, and an empty message aborts the commit.\n# On branch 12345678-lorem-ipsum\n#
122
+ Changes to be committed:\n# (use \"git reset HEAD <file>...\" to unstage)\n#\n#\tnew
123
+ file: dolor.txt\n#\n```\n\n### `git finish`\nThis command finishes a story by
124
+ merging and cleaning up its branch and then pushing the changes to a remote server.
125
+ \ This command can only be run one way.\n\n```plain\n$ git finish\nChecking for
126
+ trivial merge from 12345678-lorem-ipsum to master... OK\nMerging 12345678-lorem-ipsum
127
+ to master... OK\nDeleting 12345678-lorem-ipsum... OK\nPushing to origin... OK\n```\n\nThe
128
+ command checks that it will be able to do a trivial merge from the development branch
129
+ to the target branch before it does anything. The check has the following constraints\n\n1.
130
+ \ The local repository must be up to date with the remote repository (e.g. `origin`)\n2.
131
+ \ The local merge target branch (e.g. `master`) must be up to date with the remote
132
+ merge target branch (e.g. `origin/master`)\n3. The common ancestor (i.e. the branch
133
+ point) of the development branch (e.g. `12345678-lorem-ipsum`) must be tip of the
134
+ local merge target branch (e.g. `master`)\n\nIf all of these conditions are met,
135
+ the development branch will be merged into the target branch with a message of:\n\n```plain\nMerge
136
+ 12345678-lorem-ipsum to master\n\n[Completes #12345678]\n```\n\nAfter merging, the
137
+ development branch is deleted and the changes are pushed to the remote repository.\n"
138
+ email: nebhale@nebhale.com
139
+ executables:
140
+ - git-finish
141
+ - git-start
142
+ extensions: []
143
+ extra_rdoc_files:
144
+ - README.md
145
+ - LICENSE
146
+ - NOTICE
147
+ files:
148
+ - LICENSE
149
+ - NOTICE
150
+ - README.md
151
+ - lib/git-pivotal-tracker-integration/base.rb
152
+ - lib/git-pivotal-tracker-integration/finish.rb
153
+ - lib/git-pivotal-tracker-integration/pivotal_configuration.rb
154
+ - lib/git-pivotal-tracker-integration/start.rb
155
+ - lib/git-pivotal-tracker-integration/prepare-commit-msg.sh
156
+ - bin/git-finish
157
+ - bin/git-start
158
+ homepage: https://github.com/nebhale/git-pivotal-tracker-integration
159
+ licenses:
160
+ - Apache-2.0
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: 2.0.0
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.0.0
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Git commands for integration with Pivotal Tracker
182
+ test_files: []