forked from joyjit/git-jira-hook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
executable file
·297 lines (211 loc) · 9.87 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
=======================================================================
Copyright 2009 Broadcom Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
========================================================================
git-jira-hook README
********************
Author: Joyjit Nath
*******************
Table of Contents
=================
1. Introduction
2. System Requirements
3. Installation
4. Using git-jira-hook
5. Known limitations
6. Frequently Asked Questions (FAQ)
7. Credits
1. Introduction
===============
1.1 Get git and Jira to work in Harmony
---------------------------------------
If you are using git [1] for source control and Jira [2] for bug
tracking, then the git-jira-hook script might be useful to you.
Once you have the script setup in your environment, every time you
make a git commit, a comment is automatically posted to an open
issue in Jira.
This script will also "enforce" that for every git commit, you have at
least one Jira issue that you are referencing.
This way you have a paper trail of the history behind each and every
git commit.
This is particularly useful for corporate git repositories.
1.2 Example use
---------------
In order to specify which issue (or issues) you want the commit message
to get tracked to in Jira, you place magic text markers such as:
"refs #NNN" or "fixes #NNN"
anywhere in your commit message, where "NNN" is the name of an open
Jira issue.
For example, say you have typed in the following commit message in
your git repository.
Hey look! This is my very first git-commit
Using the new and fresh git-jira-hook
refs #SW-189, refs #HW-278 fixes #FW-702
The following things will happen:
In your Jira bug database, for projects named "TST", "HW" and "FW"
in Jira, for issue numbers "SW-189", "HW-278", and "FW-702", the
following comments will be added:
commit 424daa955f5c8a17aab9d524071f65f1999769a9
Author: Joyjit Nath <[email protected]>
Date: Tue Aug 25 15:12:39 2009 -0700
Hey look! This is my very first git-commit
Using the new and fresh git-jira-hook
refs #SW-189, refs #HW-278 fixes #FW-702
In addition,
* the issue "FW=702" will be marked as resolved. (NOTE:
this "resolved" part does not work yet. See "Known
Limitations" section.)
1.3 Wait! there's more
-----------------------
If your git repository is exposed using gitweb [3], an hyperlink
linking to the exact commit will also be embedded in the Jira issue
comment that was added. This enables anyone to examine your git
commit simply by clicking on the hyperlink.
2. System Requirements
======================
- Python 2.x and python modules: SOAPpy, ConfigParser.
I have tested with Python 2.5.2.
- A Jira installation with Remote APIs enabled.
- git version 1.6.x.y (I have tested with 1.6.0.4).
- Linux or some other similar Unix flavor (I have tested with
CentOS 5.x).
- OPTIONAL, but Highly recommended: gitweb [4] which has been
setup with "upstream" git repositories.
3. Installation
===============
Here is a typical example of how this hook may be used.
In a corporate setting where git is used, there is typically an
"upstream" or "public" repository. And then developers have their
"private" repositories. For their day-to-day work, the developers
use their private repositories. Periodically, they (either
directly, or via gatekeepers) push changes from their private
repository to the "upstream" one. Also, the "upstream" repository
is typically a bare repository, and no actual commits are done
here.
In the private repository, the hook should be installed, but only
*partically*. Every time a commit is made, the hook only checks to
make sure that the commit text conforms to correct formatting (i.e.
the magic references to Jira issues are present). No Jira issues
are updated.
The hook is completely installed in the "upstream" repository.
Whenever a commit is made in the upstream repository or a "git push"
is done to it, the installed hook will kick in and validate the
commit message, followed by update of the Jira issue.
3.1 Installtion for "private" repository
----------------------------------------
(i) Copy this script to <your-git-repo-GIT-dir>/hooks/commit-msg
and mark it executable
Example:
cp git-jira-hook joyjit-project/.git/hooks/commit-msg
chmod +x joyjit-project/.git/hooks/commit-msg
(iii) Set the following git config value
Example:
cd joyjit-repo
git config jira.url "http://jira.mycompany.com"
(iv) [Optional] If you wish jira integration to be triggered only
on certain branches, add a comma-separated list of
branch names to git config "git-jira-hook.branches"
For example:
cd joyjit-repo
git config git-jira-hook.branches "jira1,jira2"
This will cause the integration to be triggered only on
git branches jira1 and jira2. For instance, if you make a commit
to branch "master", the hook will simply stay disabled.
By default, if you do not set this config, all branches are
checked.
See the "Frequently Asked Questions" section to figure out what
values to use for your "jira.url".
3.2 Installation for "upstream" repository
------------------------------------------
(i) Copy this script to
<upstream-repo-GIT-dir>/hooks/{commit-msg|post-commit|update|post-receive}
and mark it executable
Example:
cp git-jira-hook upstream-project.git/hooks/commit-msg
cp git-jira-hook upstream-project.git/hooks/post-commit
cp git-jira-hook upstream-project.git/hooks/update
cp git-jira-hook upstream-project.git/hooks/post-receive
chmod +x upstream-project.git/hooks/commit-msg
chmod +x upstream-project.git/hooks/post-commit
chmod +x upstream-project.git/hooks/update
chmod +x upstream-project.git/hooks/post-receive
(iii) Set the following git config values (Note: gitweb.url config is
recommended, but Optional): "jira.url" "gitweb.url"
Example:
cd upstream.git
git config jira.url "http://jira.mycompany.com"
git config gitweb.url "http://git.mycompany.com/gitweb.cgi/p=upstream-project.git;a=commit;h="
(iv) [Optional] If you wish jira integration to be triggered only
on certain branches, add a comma-separated list of
branch names to git config "git-jira-hook.branches"
For example:
cd joyjit-repo
git config git-jira-hook.branches "jira1,jira2"
This will cause the integration to be triggered only on
git branches jira1 and jira2. For instance, if you make a commit
to branch "master", the hook will simply stay disabled.
By default, if you do not set this config, all branches are
checked.
See the "Frequently Asked Questions" section to figure out what values
to use for your "jira.url" and "gitweb.url"
4. Using git-jira-hook
======================
When you are read to make a git commit, make sure that you have an
appropriate open jira issue. There can be more than one open issues.
Lets say this commit deals with Jira issues FOO-23 and BAR-42 and
also marks FOO-56 as resolved.
Anywhere in your commit message, you must put the following strings
(without the quotes):
"refs #FOO-23"
"refs #BAR-42"
"fixes #FOO-56"
And then you do a "git commit" the normal way. At this time, assuming
the "private" repository, the commit message will be checked for
references to Jira issues and the commit will succeed only if these
issues exist.
And then, at a later time, when you do "git push" to push your changes
upstream, the final validation and Jira issue update will be done.
NOTE: The "fixes" feature does not work yet :<
5. Known Limitations
====================
I am working to fix all of these issues:
* The "fixes" text does not yet mark the Jira issue as resolved.
* The error messages are a bit confusing (cluttered with too much detail).
DISCLAIMER: This is my very first attempt at writing python code, so it is not
very well written.
6. Frequently asked Questions
=============================
Q 6.1 What value should I use for "jira.url" git config?
A. It depends on your Jira server setup. When you log-in to the Jira
server using a browser, the URL to the login page typically looks like:
http://jira.mycompany.com/secure/Dashboard.jspa
In which case, your "jira.url" should be "http://jira.mycompany.com"
Q 6.2 What value should I use for "gitweb.url" git config?
A. Assuming you have gitweb enabled for your repository, this is the URL which you
use to access gitweb.
for instance, in order to view commit "424daa955f5c8a17aab9d524071f65f1999769a9"
in gitweb, if you use:
http://git.mycompany.com/gitweb.cgi?p=joyjit-repo/.git;a=commit;h=424daa955f5c8a17aab9d524071f65f1999769a9
Then the "gitweb.url" to use is:
"http://git.mycompany.com/gitweb.cgi?p=joyjit-repo/.git;a=commit;h="
7. Credits
==========
This script was inspired by the following:
http://github.com/dreiss/git-jira-attacher/tree/master
http://confluence.atlassian.com/display/JIRAEXT/Jira+CLI
8. References
=============
[1] Git, an source configuratiin management ("SCM") tool
http://git-scm.com/
[2] Jira, a bug tracking system
http://www.atlassian.com/software/jira
[3] Gitweb, a web based browser for git
http://git.or.cz/gitwiki/Gitweb