/
git-yui
executable file
·943 lines (795 loc) · 30.4 KB
/
git-yui
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
#!/usr/bin/env python
import os, sys, string, shutil, urllib2, urllib, pprint, simplejson, datetime
from cStringIO import StringIO
from subprocess import call, PIPE, Popen
##Setup pp for debugging
pp = pprint.PrettyPrinter(indent=4)
##The supported projects, if not in this list, this script doesn't work
supported_projects = [
'yui2',
'yui3',
'yui3-gallery',
'yuidoc',
'builder'
]
##The supported build projects
supported_builds = [
'yui2',
'yui3',
'yui3-gallery'
]
##Globals
server_name = 'http://yuilibrary.com'
args = []
count = 0
username = None
origin = None
git_config = {}
action = None
git_dir = None
build_dir = None
member_list = None
##Process the Arguments
for arg in sys.argv:
if count > 0:
if not action:
action = arg
args.append(arg)
count = count + 1
##Format bold text
def bold(str):
return "\033[1m%s\033[0m" % str
##Format red text (for errors)
def red(str):
return "\033[31m%s\033[0m" % str
##Print and format an error, then exit the script
def print_error(str):
print bold(red(str))
sys.exit(1)
##Fetch the git config and place it in the git_config global
def fetchGitConfig():
raw_config = os.popen('git config --list').read().split("\n")
for i in raw_config:
line = i.split('=')
if line[0]:
git_config[line[0]] = line[1]
if 'yui.apiserver' in git_config:
globals()['server_name'] = git_config['yui.apiserver']
##Fetch the list of users that forked this project
def fetchMembersList():
if globals()['member_list']:
return
url = "http://github.com/yui/%s/network/members.json" % origin
data = simplejson.load(urllib.urlopen(url))
out = [];
for i in data['users']:
out.append(i['owner']['login'])
globals()['member_list'] = out
##Parse the project out of the git config
def fetchProject():
if 'remote.origin.url' in git_config:
org_remote = git_config['remote.origin.url'].replace('git@github.com:', '')
remote = org_remote.replace('git://github.com/', '')
remote = remote.replace('http://github.com:', '')
remote = remote.replace('.git', '')
remote = remote.split('/')
if len(remote) < 2:
print_error('Remote not found: %s' % org_remote)
if remote[1] not in supported_projects:
print_error('(%s) is not in supported projects list: %s' % (remote[1], ",".join(supported_projects)))
if 'github.user' in git_config:
globals()['username'] = git_config['github.user']
if git_config['user.email']:
globals()['useremail'] = git_config['user.email']
return remote[1]
else:
print_error('No remote origin found, are we in a git repo?')
##Fetch the upstream code and drop it in to a branch
def fetchUpstream(master, user=None):
if not user:
user = 'yui'
print "%s %s/%s" % (bold("Syncing with the upstream master:"), user, master)
f_name = '%s_%s' % (user, master)
remote_name = 'remote.%s.url' % f_name
if not remote_name in git_config:
call(['git', 'remote', 'add', f_name, 'git://github.com/%s/%s.git' % (user, master)])
use_branch = True
if 'yui.usebranch' in git_config:
if git_config['yui.usebranch'] == 'false':
use_branch = False
if use_branch:
retcode = call(['git', 'checkout', '-b', f_name], stderr=error_file)
if retcode == 128:
retcode = call(['git', 'checkout', f_name])
else:
retcode = call(['git', 'checkout', 'master'])
if retcode == 0:
retcode = call(['git', 'fetch', 'origin', '-v'])
if retcode == 0:
retcode = call(['git', 'fetch', f_name, '-v'])
if retcode == 0:
retcode = call(['git', 'merge', '%s/master' % f_name])
else:
call(['git', 'checkout', 'master'])
call(['git', 'branch', '-d', f_name])
print_error('Bad username given, branch %s deleted' % f_name)
##Merge the upstream back into master
def mergeUpstream(master, user):
if not user:
user = 'yui'
print "%s %s/%s" % (bold("Merging into master:"), user, master)
f_name = '%s_%s' % (user, master)
retcode = call(['git', 'checkout', 'master'])
if retcode == 0:
retcode = call(['git', 'merge', f_name])
##Check if the builder project is above the git root
def checkBuilder():
build_dir = os.path.abspath(os.path.join(git_dir, '../builder'))
if not os.path.exists(build_dir):
print_error('Builder module was not found. Please install it: http://github.com/yui/builder')
globals()['build_dir'] = build_dir
##Check if the yuidoc project is above the git root
def checkYUIDoc():
yuidoc_dir = os.path.abspath(os.path.join(git_dir, '../yuidoc'))
if not os.path.exists(yuidoc_dir):
print_error('YUIDoc module was not found. Please install it: http://github.com/yui/yuidoc')
globals()['doc_dir'] = os.path.abspath(os.path.join(yuidoc_dir, 'bin'))
##Check if ant is installed
def checkAnt():
try:
call(['ant', '-version'], stdout=PIPE)
except OSError:
print_error('Ant was not found, please install it: http://ant.apache.org/')
return True
##Check if java is installed
def checkJava():
try:
call(['java', '-version'], stdout=PIPE, stderr=PIPE)
except OSError:
print_error('Java was not found, please install it')
return True
##Find the root of this project, the one with the .git as a direct child.
def findGitRoot():
if globals()["git_dir"]:
return globals()["git_dir"]
args = ['git', 'rev-parse', '--git-dir']
output = Popen(args, stdout=PIPE).communicate()[0]
tmp_git_dir = os.path.abspath(output.strip())
globals()["git_dir"] = os.path.abspath(os.path.join(tmp_git_dir, '../'))
error_file_path = os.path.abspath(os.path.join(tmp_git_dir, 'yuilog'))
if os.path.exists(error_file_path):
os.rename(
os.path.abspath(error_file_path),
os.path.abspath(os.path.join(tmp_git_dir, 'yuilog.last'))
)
globals()["error_file_path_last"] = os.path.abspath(os.path.join(tmp_git_dir, 'yuilog.last'))
globals()["error_file_path"] = error_file_path
globals()["error_file"] = open(error_file_path, 'w+')
##Build this item from source
def buildFromSource(item):
src_path = os.path.abspath(os.path.join(git_dir, 'src/%s' % item))
if not os.path.exists(src_path):
print_error("Source Directory Not Found: \n%s" % src_path)
os.chdir(src_path)
print bold("Building source in: %s." % red(item))
#TODO - Once Matt fixes his build environment, this can be removed..
if os.path.isfile(os.path.join('', 'build.sh')):
print bold(red('Control skipped (%s): found a build.sh file' % item))
else:
if os.path.isfile(os.path.join('', 'build.xml')):
call(['ant', '-q', 'all'], stderr=error_file, stdout=error_file)
print bold("Source for %s has been built." % item)
else:
print bold(red("No build.xml file found.."))
##Get all the source directories, so we can build them
def getSrcDirs():
src_path = os.path.abspath(os.path.join(git_dir, 'src/'))
os.chdir(src_path)
subdirs = []
for i in os.listdir(src_path):
# Checking for directories that start with a '.'
# Windows doesn't hide these directories by default
if not i.startswith('.'):
# Checking for known bad directory: CVS
if i != 'CVS':
fullname = os.path.join(src_path, i)
if os.path.isdir(fullname):
subdirs.append(i)
return subdirs
##Build all from source
def buildAllFromSource():
print bold("Building all from source..")
subdirs = getSrcDirs()
for i in subdirs:
buildFromSource(i)
##Handle the build arg
def buildControl(item):
checkAnt()
checkBuilder()
if item == 'all':
buildAllFromSource()
else:
buildFromSource(item)
##Generate the docs for a groups of modules
def genDocs(items):
prepDocParse()
paths = []
for i in items:
src_path = os.path.abspath(os.path.join(git_dir, 'src/%s/js' % i))
if os.path.exists(src_path):
paths.append(src_path)
print bold('Generating docs...')
ver = origin.replace('yui', '')
args = [os.path.join(doc_dir, 'yuidoc.py')]
args2 = ['-p', os.path.join(doc_base_path, 'parser'),
'-o', os.path.join(doc_base_path, 'html'),
'-t', os.path.abspath(os.path.join(doc_dir, '../', 'template')),
'-v', '1.0.0',
'-Y', ver]
##Put all the pieces together
for i in paths:
args.append(i)
for i in args2:
args.append(i)
retcode = call(args, stderr=error_file, stdout=error_file)
if retcode > 0:
print_error('Docs failed to parse. Call "git yui log" to see the error')
print bold('Docs generated')
##Generate all the docs
def genAllDocs():
print bold('Generating all docs')
subdirs = getSrcDirs()
genDocs(subdirs)
##Prep for doc parsing, setting up directories
def prepDocParse():
src_path = os.path.abspath(os.path.join(git_dir, '../yui-docs'))
if not os.path.exists(src_path):
globals()['doc_base_path'] = src_path
os.mkdir(os.path.abspath(src_path))
os.mkdir(os.path.abspath(os.path.join(src_path, 'html')))
os.mkdir(os.path.abspath(os.path.join(src_path, 'parser')))
else:
print_error('Docs directory exists. Please run: git yui doc clean')
##Remove the current docs directory
def clearDocs():
src_path = os.path.abspath(os.path.join(git_dir, '../yui-docs'))
if os.path.exists(src_path):
shutil.rmtree(src_path, ignore_errors=True)
print bold("Old docs directory removed.")
else:
print bold("No directory to clean")
##Handle the docs argument
def buildDocs(item):
checkYUIDoc()
if item[0] == 'all':
genAllDocs()
elif item[0] == 'clean':
clearDocs()
else:
genDocs(item)
##Handle the log argument
def showLog():
f = open(error_file_path_last)
print f.read()
##handle the lint argument
def lintFiles(items):
for i in items:
lintFile(i)
##Run JSLint on a file
def lintFile(file):
if not os.path.exists(file):
print_error('File not found')
if not file.endswith('.js'):
print_error('File is not a JavaScript file.')
checkJava()
checkBuilder()
c_build = os.path.abspath(os.path.join(build_dir, 'componentbuild', 'lib'))
jar_path = os.path.abspath(os.path.join(c_build, 'rhino', 'js.jar'))
console_path = os.path.abspath(os.path.join(c_build, 'jslint', 'jslint-console.js'))
full_path = os.path.abspath(os.path.join(c_build, 'jslint', 'fulljslint.js'))
args = ['java', '-jar', jar_path, console_path, full_path, file]
call(args)
##Show the list of forks for this project
def showNetwork():
fetchMembersList()
list = member_list
list.sort()
##This need to move to an API call on yuilibrary.com
url = "%s/gallery/api/forks" % (server_name)
data = simplejson.load(urllib.urlopen(url))
contribs = data['results']
contribs.sort()
print bold("List of forks for: %s" % origin)
print "Known contributors are bolded and marked with an *"
print bold('yui*')
for i in contribs:
if i in list:
print bold("%s*" % i)
for i in list:
if not i in contribs and i != 'yui':
print i
##Show your last (n) commits and their SHA1's
def showCommits(num, user):
if not user:
user = username
print bold('Showing last %s commits for %s' % (num, user))
args = [
'git',
'--no-pager',
'log',
'--author=%s' % user,
'--no-merges',
'--pretty=oneline',
'-n%s' % num
]
call(args)
def getUserGalleryModules():
try:
username = git_config['yui.user']
token = git_config['yui.token']
except KeyError:
print_error("No YUI username or token in your git config.\nhttp:://wiki.github.com/davglass/yui-git-yui-api-token")
url = "%s/gallery/api/user/%s" % ( server_name, username )
req = urllib2.Request(url)
data = simplejson.load(urllib2.urlopen(req))
items = []
for module in data["modules"]:
items.append("gallery-" + module["module"])
return items
def showGalleryPending(id):
print bold('Gallery Pending Items')
try:
username = git_config['yui.user']
ghusername = git_config['github.user']
token = git_config['yui.token']
except KeyError:
print_error("No YUI username or GitHub token in your git config.\nhttp://wiki.github.com/davglass/yui-git/yui-api-token")
url = "%s/gallery/api/pullpending" % server_name
out = {}
out['nocache'] = 'nocache'
out['username'] = username
out['token'] = token
data = urllib.urlencode(out)
req = urllib2.Request(url, data)
data = simplejson.load(urllib2.urlopen(req))
if data['count'] > 0:
if id:
for i in data['results']:
if i['pullid'] == id:
print bold('[%s] %s' % (i['pullid'], i['title']))
gh = i['userinfo']['github']
print '--------------------------------------------------------------------------'
remote_name = 'remote.%s.url' % gh
if not remote_name in git_config:
#call(['git', 'remote', 'add', gh, 'git://github.com/%s/%s.git' % (gh, master)])
print "git remote add %s git://github.com/%s/yui3-gallery.git" % (gh, gh)
branch = "pending-%s" % i['sha1'][0:9]
#print "git checkout -b %s" % branch
call(['git', 'checkout', '-b', branch])
#print "git pull %s %s:%s" % (gh, i['branch'], branch)
call(['git', 'pull', gh, '%s:%s' % (i['branch'], branch)])
#print "git reset %s --hard" % i['sha1'][0:9]
call(['git', 'reset', '--hard', i['sha1'][0:9]])
print "Pull Complete:"
print "Lint all: git yui lint build/%s/*.js src/%s/js/*" % (i['module'], i['module'])
print "Reset back to master: git reset --hard master"
print '--------------------------------------------------------------------------'
else:
for i in data['results']:
print bold('[%s] %s' % (i['pullid'], i['title']))
print 'command: %s' % (bold('git yui pending %s' % i['pullid']))
print '--------------------------------------------------------------------------'
print i['summary']
print '--------------------------------------------------------------------------'
else:
print_error('No pending requests found')
##Issue a Pull Request to yui on GitHub
def pullRequest(commitid):
print "%s %s" % (bold('Sending YUI a Pull Request for: '), commitid[0:8])
try:
username = git_config['yui.user']
ghusername = git_config['github.user']
token = git_config['yui.token']
except KeyError:
print_error("No YUI username or GitHub token in your git config.\nhttp://wiki.github.com/davglass/yui-git/yui-api-token")
if len(commitid) < 40:
print_error("You must give a full sha1")
out = {}
out['nocache'] = 'nocache'
out['username'] = username
out['token'] = token
out['component'] = 'None'
out['commit'] = commitid
args = [
'git',
'--no-pager',
'log',
commitid,
'--no-merges',
'--pretty=format:%s',
'-n1'
]
out['subject'] = Popen(args, stdout=PIPE).communicate()[0]
#Auto-Detect
out['branch'] = 'master'
print bold('Please add a (one line) comment to this request:')
comment = sys.stdin.readline().strip()
if not comment:
print bold(red('You must add a comment to the request.'))
comment = sys.stdin.readline().strip()
if not comment:
print_error('No comment given, Pull Request failed.')
out['message'] = comment
out['url'] = 'http://github.com/%s/%s/commit/%s' % (ghusername, origin, commitid)
print bold('Are you sure you wish to make a Pull Request for %s/%s? [Y/n]' % (origin, commitid[0:8]))
go = sys.stdin.readline().strip().lower()
if go[0:1] == 'y':
print bold('Sending Pull Request to YUILibrary.com')
url = "%s/projects/%s/api/v1/pullrequest" % (server_name, origin)
data = urllib.urlencode(out)
req = urllib2.Request(url, data)
data = simplejson.load(urllib2.urlopen(req))
if 'id' in data:
url = '%s/projects/%s/ticket/%s' % (server_name, origin, data['id'])
copy(url)
print bold('Pull Request Submitted:')
print url
if 'error' in data:
print_error(data['error'])
else:
print_error('Pull Request cancelled')
##Get ticket data
def getTicket(id):
if not 'yui.user' in git_config:
print_error('No yui user setting in your git config')
if not 'yui.token' in git_config:
print_error('No yui token found in your git config')
uname = git_config['yui.user']
token = git_config['yui.token']
url = "%s/projects/%s/api/v1/ticket?username=%s&token=%s&id=%s" % (server_name, origin, uname, token, id)
data = simplejson.load(urllib.urlopen(url))
return data
def formatDate(stamp):
return datetime.datetime.fromtimestamp(int(stamp))
##Show a ticket
def ticketShow(id):
data = getTicket(id)
if 'error' in data:
print_error(data['error'])
ticket = data['data']
#pp.pprint(ticket)
sep = '----------------------------------------------------------------------------'
print bold("Ticket #%s: %s" % (ticket['id'], ticket['summary']))
print "(%s %s)" % (ticket['status'], ticket['type'])
print ""
print "%s created on: %s" % (ticket['reporter'], formatDate(ticket['time']))
print "Last modified on: %s" % (formatDate(ticket['changetime']))
print "Owner: %s" % ticket['owner']
print ""
print sep
print "Description:"
print ticket['description']
print sep
print ""
print "|%s" % sep
print "| This bug currently has the following settings:"
print "| Component: %s" % ticket['component']
print "| Severity: %s" % ticket['severity']
print "| Priority: %s" % ticket['priority']
print "| Ticket Type: %s" % ticket['type']
rel = ticket['milestone']
if rel == '':
rel = '--'
print "| Target Release: %s" % rel
print "| Ticket URL: %s" % ticket['url']
print "|%s" % sep
print ""
comment = False
for i in ticket['history']:
if i['comment']:
comment = i
if comment:
print ""
print "Last Comment by %s on %s" % (comment['author'], formatDate(comment['stamp']))
print sep
print ""
print comment['comment']
print ""
print ""
##Comment on a Bug Ticket
def ticketComment(id, sha1=None):
print "%s %s" % (bold("Adding a comment to:"), id)
data = getTicket(id)
comment = None
if 'error' in data:
print_error(data['error'])
if sha1:
args = [
'git',
'--no-pager',
'log',
sha1,
'--no-merges',
'--pretty=format:%s',
'-n1'
]
comment = Popen(args, stdout=PIPE).communicate()[0]
if comment == "":
print_error('Failed to find a log message for %s' % sha1)
if not comment:
print bold('Add your comment below:')
print "Control + d to end your comment"
comment = sys.stdin.readlines()
uname = git_config['yui.user']
token = git_config['yui.token']
comment = "".join(comment)
out = {}
out['id'] = id
out['username'] = uname
out['token'] = token
out['action'] = 'comment'
out['comment'] = comment
#pp.pprint(out)
url = "%s/projects/%s/api/v1/ticket" % (server_name, origin)
data = urllib.urlencode(out)
req = urllib2.Request(url, data)
response = simplejson.load(urllib2.urlopen(req))
if 'error' in response:
print_error(data['error'])
else:
print bold('Comment added to ticket')
print response['data']['url']
copy(response['data']['url'])
##Copies content to the OS clipboard
def copy(content):
system = sys.platform
if system == 'darwin':
p = Popen(['pbcopy'], stdin=PIPE)
p.stdin.write(content)
p.stdin.close()
retcode = p.wait()
elif system == 'linux':
p = Popen(['xclip'], stdin=PIPE)
p.stdin.write(content)
p.stdin.close()
retcode = p.wait()
##Creates the directory structure for a new module
def createComponent(name):
checkBuilder()
origin = globals()['origin']
if origin == 'yui3-gallery':
if name[0:8] != 'gallery-':
name = "gallery-%s" % name
src_path = os.path.abspath(os.path.join(git_dir, 'src', name))
b_path = os.path.abspath(os.path.join(git_dir, 'build', name))
if os.path.exists(src_path):
print_error("Path exists, can not create:\n%s" % src_path)
print bold('Creating new module: %s' % name)
#Sand box
if origin == 'yui3-gallery':
sbox_path = os.path.abspath(os.path.join(git_dir, 'sandbox', username, name))
sbox_readme = os.path.abspath(os.path.join(git_dir, 'sandbox', username, name, 'README'))
else:
sbox_readme = os.path.abspath(os.path.join(git_dir, 'sandbox', name, 'README'))
sbox_path = os.path.abspath(os.path.join(git_dir, 'sandbox', name))
#js dir
js_path = os.path.abspath(os.path.join(src_path, 'js'))
#Tests dir
test_path = os.path.abspath(os.path.join(src_path, 'tests'))
#READMEs
src_readme = os.path.abspath(os.path.join(src_path, 'README'))
if origin == 'yui3-gallery':
origin = 'yui3'
#Copy the builder files
build_prop = os.path.abspath(os.path.join(build_dir, 'componentbuild', 'templates', origin, 'build.properties'))
build_prop_final = os.path.abspath(os.path.join(src_path, 'build.properties'))
build_xml = os.path.abspath(os.path.join(build_dir, 'componentbuild', 'templates', origin, 'build.xml'))
build_xml_final = os.path.abspath(os.path.join(src_path, 'build.xml'))
#Do all the work
os.mkdir(b_path)
os.mkdir(src_path)
os.mkdir(js_path)
os.mkdir(test_path)
os.makedirs(sbox_path)
open(src_readme, 'w').close()
open(sbox_readme, 'w').close()
shutil.copyfile(build_prop, build_prop_final)
shutil.copyfile(build_xml, build_xml_final)
print bold('Module directories created and temp files copied')
def showMyTickets():
if not 'yui.user' in git_config:
print_error('No yui user setting in your git config')
if not 'yui.token' in git_config:
print_error('No yui token found in your git config')
url = "%s/projects/%s/api/v1/report?reportid=5&username=%s&token=%s" % (server_name, origin, git_config['yui.user'], git_config['yui.token'])
data = simplejson.load(urllib.urlopen(url))
#pp.pprint(data)
for i in data['results']:
print bold("%s: [%s] %s" % (i['id'], i['status'], i['summary']))
def formatHelp(action, string):
if help_limit:
if action.startswith(help_limit):
print " %s:\n %s" % (bold(action), string)
print ""
else:
print " %s:\n %s" % (bold(action), string)
print ""
def guessComp():
test_path = os.path.abspath(os.path.join('./')).replace(git_dir, '').replace('/sandbox/', '').replace('/src/', '').replace('/build/', '')
test_path = test_path.split(os.sep)
return test_path[0]
def showHelp(item=None):
label = "[action]"
globals()['help_limit'] = False
if item:
label = "%s" % item
globals()['help_limit'] = item
print "usage: git yui %s" % (label)
formatHelp("up", "Pull the latest changes from yui HEAD into a branch called yui_[project]")
formatHelp("up [github username] [?]", "Pull the latest changes from [username] HEAD into a branch called [username]_[project]")
formatHelp("merge", "Merge the yui_[project] branch back into the master branch")
formatHelp("merge [github username] [?]", "Merge the [username]_[project] branch back into the master branch")
formatHelp("sync [github username] [?]", "Runs git yui up, then git yui merge")
formatHelp("build [control]", "Run the ant processes needed to build the control%s" % bold(red('*')))
formatHelp("build all", "Run the build on all dir's in src%s" % bold(red('*')))
formatHelp("docs [control1] [control2]", "Build the API docs for the specified modules%s" % bold(red('*')))
formatHelp("docs all", "Build the API docs for all modules%s" % bold(red('*')))
if origin == "yui3-gallery":
formatHelp("docs my", "Build the API docs for gallery modules owned by you%s" % bold(red('*')))
formatHelp("lint [path-to-file] [path-to-file] [path-to-file]", "Run JSLint on the supplied files%s" % bold(red('*')))
formatHelp("network|users|forks", "Show the list of forks for this project")
formatHelp("commits [nn] [email-address]", "Shows the last [nn] commits by user. default: 5 and you")
formatHelp("pullreq|pullrequest [SHA1]", "Submit a Pull Request to YUI for the provided SHA1")
formatHelp("create [module]", "Creates the directory structure for a new module")
formatHelp("comment [ticket id]", "Allows you to comment on a yuilibrary.com ticket for this YUI Project")
formatHelp("comment [ticket id] [sha1]", "Add the comment from the supplied sha1 to the provided yuilibrary.com ticket")
formatHelp("ticket [ticket id]", "Shows you a summary of this yuilibrary.com ticket")
formatHelp("my", "Shows you a list of your open tickets")
formatHelp("log", "Show the error (stderr) output of the last command")
print "%s denotes a dependency" % bold(red('*'))
########ACTION CODE STARTS HERE
fetchGitConfig()
findGitRoot()
origin = fetchProject()
##Process the arguments.. Maybe a better way?
##I don't want to use OptionParser, don't want to require the use of - arguments
if action == 'up':
user = None
if count > 2:
fetchMembersList()
user = args[1]
if user == '?':
print bold('Available forks of this project:')
print ", ".join(member_list)
sys.exit(0)
if not user in member_list:
print_error('User (%s) not in network' % user)
fetchUpstream(origin, user)
elif action == 'merge':
use_branch = True
if 'yui.usebranch' in git_config:
if git_config['yui.usebranch'] == 'false':
use_branch = False
if not use_branch:
print_error('usebranch is false in config, this will do nothing.')
user = None
if count > 2:
fetchMembersList()
user = args[1]
if user == '?':
print bold('Available forks of this project:')
print ", ".join(member_list)
sys.exit(0)
if not user in member_list:
print_error('User (%s) not in network' % user)
mergeUpstream(origin, user)
elif action == 'sync':
user = None
if count > 2:
fetchMembersList()
user = args[1]
if user == '?':
print bold('Available forks of this project:')
print ", ".join(member_list)
sys.exit(0)
if not user in member_list:
print_error('User (%s) not in network' % user)
fetchUpstream(origin, user)
mergeUpstream(origin, user)
elif action == 'build':
#if origin != 'yui2' and origin != 'yui3':
if not origin in supported_builds:
print_error('Not supported on this project')
comp = False
if count > 2:
comp = args[1]
if not comp:
#Try to find the component that we are in and auto build it.
comp = guessComp()
if comp:
buildControl(comp)
else:
print_error('You must provide a component name')
elif action == 'docs' or action == 'doc':
#if origin != 'yui2' and origin != 'yui3':
if not origin in supported_builds:
print_error('Not supported on this project')
if origin == 'yui3-gallery' and args[1] == 'mine':
items = getUserGalleryModules()
buildDocs(items)
elif count > 2:
items = []
for k,v in enumerate(args):
if k > 0:
items.append(v)
buildDocs(items)
else:
print_error('You must provide at least one component name')
elif action == 'log':
showLog()
elif action == 'my':
if origin == 'yui3-gallery':
print_error('Ticket list not supported for this project.')
showMyTickets()
elif action == 'ticket':
if origin == 'yui3-gallery':
print_error('Ticket list not supported for this project.')
if count > 2:
ticketShow(args[1])
else:
print bold(red('You need to provide a ticket id.'))
elif action == 'comment':
if origin == 'yui3-gallery':
print_error('Ticket list not supported for this project.')
if count > 3:
ticketComment(args[1], args[2])
elif count > 2:
ticketComment(args[1])
else:
print bold(red('You need to provide a ticket id.'))
elif action == 'create':
if not origin in supported_builds:
print_error('Not supported on this project')
if count > 2:
createComponent(args[1])
else:
print_error('You must provide a component name')
elif action == 'network' or action == 'users' or action == 'forks':
showNetwork()
elif action == 'commits':
num = 5
user = username
if count > 2:
num = args[1]
if count > 3:
user = args[2]
showCommits(num, user)
elif action == 'pullreq' or action == 'pullrequest':
if count > 2:
pullRequest(args[1])
else:
print bold(red('You need to supply a commit id.'))
showCommits(5, username)
elif action == 'pending':
if origin == 'yui3-gallery':
id = 0
if count > 2:
id = args[1]
showGalleryPending(id)
else:
print_error('Not in the gallery project')
elif action == 'lint' or action == 'jslint':
if count > 2:
items = []
for k,v in enumerate(args):
if k > 0:
items.append(v)
lintFiles(items)
else:
print_error('No file given')
else:
##Print Help
if count > 2:
showHelp(args[1])
else:
showHelp()