| |
@@ -0,0 +1,68 @@
|
| |
+ import getpass
|
| |
+ import sys
|
| |
+
|
| |
+ import click
|
| |
+
|
| |
+ from pag.app import app
|
| |
+ from pag.utils import (
|
| |
+ configured,
|
| |
+ assert_local_repo,
|
| |
+ in_git_repo,
|
| |
+ get_default_upstream_branch,
|
| |
+ get_current_local_branch,
|
| |
+ run,
|
| |
+ )
|
| |
+ from pag.client import client
|
| |
+
|
| |
+ HEADER = "Pull request title goes here."
|
| |
+ MARKER = "# All lines below this marker are ignored."
|
| |
+
|
| |
+
|
| |
+ @app.command('pull-request')
|
| |
+ @assert_local_repo
|
| |
+ @click.option('-b', '--base')
|
| |
+ @click.option('-h', '--head')
|
| |
+ @configured
|
| |
+ def pullrequest(conf, base, head):
|
| |
+
|
| |
+ name = in_git_repo()
|
| |
+
|
| |
+ if base is None:
|
| |
+ try:
|
| |
+ base = get_default_upstream_branch(name)
|
| |
+ except Exception:
|
| |
+ click.echo("Failed to find default upstream branch for %r" % name)
|
| |
+ click.echo("Please specify a base branch explicitly.")
|
| |
+ sys.exit(1)
|
| |
+
|
| |
+ if head is None:
|
| |
+ head = get_current_local_branch()
|
| |
+
|
| |
+ cmd = ['git', 'log', '{base}..{head}'.format(base=base, head=head)]
|
| |
+ _, log = run(cmd, echo=False)
|
| |
+
|
| |
+ def modify(line):
|
| |
+ if not line:
|
| |
+ return line
|
| |
+ if line[0].isspace():
|
| |
+ return line.strip()
|
| |
+ return '# ' + line
|
| |
+
|
| |
+ log = '\n'.join([modify(line) for line in log.split('\n')])
|
| |
+ edited = click.edit(
|
| |
+ "\n\n".join([HEADER, MARKER, log]),
|
| |
+ env=dict(VIMINIT='set filetype="gitcommit"'),
|
| |
+ )
|
| |
+ title, comment = edited.split('\n', 1)
|
| |
+ if not title:
|
| |
+ click.echo("Aborting due to empty pull request message.")
|
| |
+ sys.exit(1)
|
| |
+ comment = comment.split(MARKER)[0]
|
| |
+ comment = comment.strip()
|
| |
+
|
| |
+ username = conf['username']
|
| |
+ if not client.is_logged_in:
|
| |
+ password = getpass.getpass("FAS password for %r" % username)
|
| |
+ client.login(username=username, password=password)
|
| |
+ url = client.submit_pull_request(name, base, head, title, comment)
|
| |
+ click.echo(url)
|
| |
the
name.split
like this may actually break with one feature of pagure under review: pseudo-namespace where we allow up to 1 '/' in project names.But that's eventually something for later when it'll be in used.