Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit 6aaa7cc

Browse files
authored
Merge pull request #84 from jd/add-label
Allow to set labels to pull request when sent
2 parents b8867dd + dce81c5 commit 6aaa7cc

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

git_pull_request/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ def git_pull_request(target_remote=None, target_branch=None,
254254
fork=True,
255255
setup_only=False,
256256
branch_prefix=None,
257-
dry_run=False):
257+
dry_run=False,
258+
labels=None):
258259
branch = git_get_branch_name()
259260
if not branch:
260261
LOG.critical("Unable to find current branch")
@@ -326,7 +327,7 @@ def git_pull_request(target_remote=None, target_branch=None,
326327
retcode = fork_and_push_pull_request(
327328
g, hosttype, repo, rebase, target_remote, target_branch, branch,
328329
user, title, message, comment, force_editor, tag_previous_revision,
329-
fork, setup_only, branch_prefix, dry_run,
330+
fork, setup_only, branch_prefix, dry_run, labels,
330331
)
331332

332333
approve_login_password(host=hostname, user=user, password=password)
@@ -435,7 +436,8 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
435436
title, message, comment,
436437
force_editor, tag_previous_revision, fork,
437438
setup_only, branch_prefix,
438-
dry_run=False):
439+
dry_run=False,
440+
labels=None):
439441

440442
g_user = g.get_user()
441443

@@ -553,6 +555,10 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
553555
# that yet
554556
repo_to_fork.get_issue(pull.number).create_comment(comment)
555557
LOG.debug("Commented: \"%s\"", comment)
558+
559+
if labels:
560+
LOG.debug("Adding labels %s", labels)
561+
pull.add_to_labels(*labels)
556562
else:
557563
if dry_run:
558564
LOG.info("Pull-request would be created.")
@@ -588,6 +594,10 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
588594
else:
589595
LOG.info("Pull-request created: %s", pull.html_url)
590596

597+
if labels:
598+
LOG.debug("Adding labels %s", labels)
599+
pull.add_to_labels(*labels)
600+
591601
if tag_previous_revision:
592602
preserve_older_revision(branch, remote_to_push)
593603

@@ -643,6 +653,9 @@ def build_parser():
643653
help="Title of the pull request.")
644654
parser.add_argument("--message", "-m",
645655
help="Message of the pull request.")
656+
parser.add_argument("--label", "-l", action='append',
657+
help="The labels to add to the pull request. "
658+
"Can be used multiple times.")
646659
git_config_add_argument(parser,
647660
"--branch-prefix",
648661
help="Prefix remote branch")
@@ -723,6 +736,7 @@ def main():
723736
setup_only=args.setup_only,
724737
branch_prefix=args.branch_prefix,
725738
dry_run=args.dry_run,
739+
labels=args.label,
726740
)
727741
except Exception:
728742
LOG.error("Unable to send pull request", exc_info=True)

0 commit comments

Comments
 (0)