-
Notifications
You must be signed in to change notification settings - Fork 9
/
wi.py
executable file
·78 lines (59 loc) · 1.93 KB
/
wi.py
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
#!/usr/bin/env python3
from core import *
noteNamespace = 'tf.wi'
class wi(Command):
"""Associate a commit with a TFS workitem."""
def argParserCtorArgs(self):
args = Command.argParserCtorArgs(self)
args['epilog'] = """
Examples:
Associate workitems 123 and 456 with a HEAD commit:
$ git tf wi 123
$ git tf wi 456
Show associated workitems:
$ git tf wi
123,456
Remove workitem 123 association:
$ git tf wi -d 123
Remove all workitem associations:
$ git tf wi -d
"""
return args
def _initArgParser(self, parser):
parser.addVerbose()
parser.add_argument('-c', '--commit', default='HEAD',
help='commit to associate with. Defaults to HEAD.')
parser.add_argument('-d', '--delete', action='store_true',
help='Remove work item association.')
parser.add_argument('workitem', type=int, nargs='?',
help='Workitem ID')
def _run(self):
args = self.args
def notes(noteArgs, **kwargs):
gitArgs = 'notes --ref=%s %s %s' % (noteNamespace, noteArgs, args.commit)
return git(gitArgs, **kwargs)
def add(note):
notes('add -fm "%s"' % note)
note = notes('show', errorValue='')
if args.delete:
if not note:
return
workitem = args.workitem
if workitem:
items = note.split(',')
try:
items.remove(str(workitem))
except ValueError:
fail('Workitem %s is not associated with %s' % (workitem, args.commit))
if items:
add(','.join(items))
return
notes('remove')
elif args.workitem:
if note:
note += ','
add(note + str(args.workitem))
elif note:
print(note)
if __name__ == '__main__':
wi().run()