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

Add option to no-op if target branch is up-to-date. #83

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions git_pull_request/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def git_get_title_and_message(begin, end):
return (len(titles), title, message)


def git_pull_request(target_remote=None, target_branch=None,
def git_pull_request(*,
target_remote=None, target_branch=None,
title=None, message=None,
comment=None,
rebase=True,
Expand All @@ -254,7 +255,9 @@ def git_pull_request(target_remote=None, target_branch=None,
fork=True,
setup_only=False,
branch_prefix=None,
dry_run=False):
dry_run=False,
allow_noop=False
):
branch = git_get_branch_name()
if not branch:
LOG.critical("Unable to find current branch")
Expand Down Expand Up @@ -326,7 +329,7 @@ def git_pull_request(target_remote=None, target_branch=None,
retcode = fork_and_push_pull_request(
g, hosttype, repo, rebase, target_remote, target_branch, branch,
user, title, message, comment, force_editor, tag_previous_revision,
fork, setup_only, branch_prefix, dry_run,
fork, setup_only, branch_prefix, dry_run, allow_noop=allow_noop,
)

approve_login_password(host=hostname, user=user, password=password)
Expand Down Expand Up @@ -435,7 +438,7 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
title, message, comment,
force_editor, tag_previous_revision, fork,
setup_only, branch_prefix,
dry_run=False):
dry_run=False, *, allow_noop):

g_user = g.get_user()

Expand Down Expand Up @@ -582,10 +585,16 @@ def fork_and_push_pull_request(g, hosttype, repo_to_fork, rebase,
title=title,
body=message)
except github.GithubException as e:
LOG.critical(
_format_github_exception("create pull request", e)
)
return 50
if allow_noop and any((
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to fail with that. I'd just not add a new option for that.

error.get("message", "").startswith("No commits between")
for error in e.data.get("errors", [])
)):
LOG.info("Did not create pull-request, no new commits.")
else:
LOG.critical(
_format_github_exception("create pull request", e)
)
return 50
else:
LOG.info("Pull-request created: %s", pull.html_url)

Expand Down Expand Up @@ -693,6 +702,13 @@ def build_parser():
default=False,
help="Just setup the fork repo"
)
git_config_add_argument(
parser,
"--allow-noop",
action="store_true",
default=False,
help="If the target branch is up-to-date, do nothing."
)
return parser


Expand Down Expand Up @@ -724,6 +740,7 @@ def main():
setup_only=args.setup_only,
branch_prefix=args.branch_prefix,
dry_run=args.dry_run,
allow_noop=args.allow_noop,
)
except Exception:
LOG.error("Unable to send pull request", exc_info=True)
Expand Down
4 changes: 4 additions & 0 deletions git_pull_request/tests/test_gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ def test_get_remote_for_branch(self):
gpr._run_shell_command(["git", "config",
"git-pull-request.target-branch",
"awesome_branch"])
gpr._run_shell_command(["git", "config",
"git-pull-request.allow-noop",
"true"])
args = gpr.build_parser().parse_args([])
self.assertEqual(True, args.setup_only)
self.assertEqual("never", args.fork)
self.assertEqual("awesome_branch", args.target_branch)
self.assertEqual(True, args.allow_noop)