16
16
{self} [--path=<path>] [-v...] <target> add <user>/<repo> [<name>] [--tracking=<branch>] [-a]
17
17
{self} [--path=<path>] [-v...] <target> request (list|ls)
18
18
{self} [--path=<path>] [-v...] <target> request fetch <request> [-f]
19
- {self} [--path=<path>] [-v...] <target> request create <title> [--message=<message>]
20
- {self} [--path=<path>] [-v...] <target> request create <local_branch> <title> [--message=<message>]
21
- {self} [--path=<path>] [-v...] <target> request create <remote_branch> <local_branch> <title> [--message=<message>]
19
+ {self} [--path=<path>] [-v...] <target> request create [--title= <title>] [--message=<message>]
20
+ {self} [--path=<path>] [-v...] <target> request create <local_branch> [--title= <title>] [--message=<message>]
21
+ {self} [--path=<path>] [-v...] <target> request create <remote_branch> <local_branch> [--title= <title>] [--message=<message>]
22
22
{self} [--path=<path>] [-v...] <target> request <user>/<repo> (list|ls)
23
23
{self} [--path=<path>] [-v...] <target> request <user>/<repo> fetch <request> [-f]
24
- {self} [--path=<path>] [-v...] <target> request <user>/<repo> create <title> [--branch=<remote>] [--message=<message>]
25
- {self} [--path=<path>] [-v...] <target> request <user>/<repo> create <local_branch> <title> [--branch=<remote>] [--message=<message>]
26
- {self} [--path=<path>] [-v...] <target> request <user>/<repo> create <remote_branch> <local_branch> <title> [--branch=<remote>] [--message=<message>]
24
+ {self} [--path=<path>] [-v...] <target> request <user>/<repo> create [--title= <title>] [--branch=<remote>] [--message=<message>]
25
+ {self} [--path=<path>] [-v...] <target> request <user>/<repo> create <local_branch> [--title= <title>] [--branch=<remote>] [--message=<message>]
26
+ {self} [--path=<path>] [-v...] <target> request <user>/<repo> create <remote_branch> <local_branch> [--title= <title>] [--branch=<remote>] [--message=<message>]
27
27
{self} [--path=<path>] [-v...] <target> (gist|snippet) (list|ls) [<gist>]
28
28
{self} [--path=<path>] [-v...] <target> (gist|snippet) clone <gist>
29
29
{self} [--path=<path>] [-v...] <target> (gist|snippet) fetch <gist> [<gist_file>]
89
89
--secret Do not publicize gist when pushing
90
90
91
91
Options for request:
92
- <title> Title to give to the request for merge
92
+ -t,--title= <title> Title to give to the request for merge
93
93
-m,--message=<message> Description for the request for merge
94
94
95
95
Configuration options:
140
140
from .kwargparse import KeywordArgumentParser , store_parameter , register_action
141
141
142
142
from git import Repo , Git
143
- from git .exc import InvalidGitRepositoryError , NoSuchPathError
143
+ from git .exc import InvalidGitRepositoryError , NoSuchPathError , BadName
144
144
145
145
import re
146
146
147
147
EXTRACT_URL_RE = re .compile ('[^:]*(://|@)[^/]*/' )
148
148
149
+ def loop_input (* args , method = input , ** kwarg ):
150
+ out = ''
151
+ while len (out ) == 0 :
152
+ out = method (* args , ** kwarg )
153
+ return out
154
+
149
155
def confirm (what , where ):
150
156
'''
151
157
Method to show a CLI based confirmation message, waiting for a yes/no answer.
@@ -154,7 +160,7 @@ def confirm(what, where):
154
160
ans = input ('Are you sure you want to delete the '
155
161
'{} {} from the service?\n [yN]> ' .format (what , where ))
156
162
if 'y' in ans :
157
- ans = input ('Are you really sure? there\' s no coming back!\n '
163
+ ans = loop_input ('Are you really sure? there\' s no coming back!\n '
158
164
'[type \' burn!\' to proceed]> ' )
159
165
if 'burn!' != ans :
160
166
return False
@@ -411,18 +417,64 @@ def do_request_list(self):
411
417
412
418
@register_action ('request' , 'create' )
413
419
def do_request_create (self ):
420
+ def request_edition (repository , from_branch ):
421
+ try :
422
+ commit = repository .commit (from_branch )
423
+ title , * body = commit .message .split ('\n ' )
424
+ except BadName :
425
+ log .error ('Couldn\' t find local source branch {}' .format (from_branch ))
426
+ return None
427
+ from tempfile import NamedTemporaryFile
428
+ from subprocess import call
429
+ with NamedTemporaryFile (
430
+ prefix = 'git-repo-issue-' ,
431
+ suffix = '.md' ,
432
+ mode = 'w+b' ) as request_file :
433
+ request_file .write ((
434
+ '# Request for Merge Title ##########################\n '
435
+ '{}\n '
436
+ '\n '
437
+ '# Request for Merge Body ###########################\n '
438
+ '{}\n '
439
+ '####################################################\n '
440
+ '## Filled with commit:\n '
441
+ '## {}\n '
442
+ '####################################################\n '
443
+ '## * All lines starting with # will be ignored.\n '
444
+ '## * First non-ignored line is the title of the request.\n '
445
+ ).format (title , '\n ' .join (body ), commit .name_rev ).encode ('utf-8' ))
446
+ request_file .flush ()
447
+ rv = call ("{} {}" .format (os .environ ['EDITOR' ], request_file .name ), shell = True )
448
+ if rv != 0 :
449
+ raise ArgumentError ("Aborting request, as editor exited abnormally." )
450
+ request_file .seek (0 )
451
+ request_message = map (lambda l : l .decode ('utf-8' ),
452
+ filter (lambda l : not l .strip ().startswith (b'#' ), request_file .readlines ()))
453
+ try :
454
+ title = next (request_message )
455
+ body = '' .join (request_message )
456
+ except Exception :
457
+ raise ResourceError ("Format of the request message cannot be parsed." )
458
+
459
+ return title , body
460
+
461
+
414
462
service = self .get_service (resolve_targets = ('upstream' , '{service}' , 'origin' ))
463
+
415
464
new_request = service .request_create (self .user_name ,
416
465
self .repo_name ,
417
466
self .local_branch ,
418
467
self .remote_branch ,
419
468
self .title ,
420
469
self .message ,
421
- self .repo_slug != None )
470
+ self .repo_slug != None ,
471
+ request_edition )
422
472
log .info ('Successfully created request of `{local}` onto `{}:{remote}`, with id `{ref}`!' .format (
423
473
'/' .join ([self .user_name , self .repo_name ]),
424
474
** new_request )
425
475
)
476
+ if 'url' in new_request :
477
+ log .info ('available at: {url}' .format (** new_request ))
426
478
return 0
427
479
428
480
@register_action ('request' , 'fetch' )
@@ -496,12 +548,6 @@ def do_gist_delete(self):
496
548
def do_config (self ):
497
549
from getpass import getpass
498
550
499
- def loop_input (* args , method = input , ** kwarg ):
500
- out = ''
501
- while len (out ) == 0 :
502
- out = method (* args , ** kwarg )
503
- return out
504
-
505
551
def setup_service (service ):
506
552
new_conf = dict (
507
553
fqdn = None ,
0 commit comments