def push(project, local_ref, remote_branch, bypass_review=False, dry_run=False, reviewers=None, topic=None, draft=False): """ Push the changes for review. Unless review is False, in this case, simply update the remote gerrit branch :param reviewers: A list of reviewers to invite to review """ git = qisrc.git.Git(project.path) review_remote = project.review_remote args = list() if dry_run: args.append("--dry-run") args.append(review_remote.url) if bypass_review: args.append("%s:%s" % (local_ref, remote_branch)) else: ui.info("Pushing code to", review_remote.name, "for review.") if draft: remote_ref = "refs/drafts/%s" % remote_branch else: remote_ref = "refs/for/%s" % remote_branch if topic: remote_ref = "%s/%s" % (remote_ref, topic) args.append("%s:%s" % (local_ref, remote_ref)) if reviewers and not dry_run: # Get the SHA1s that will be pushed so that we can add reviewers remote = project.review_remote remote.parse_url() server = remote.server username = remote.username ssh_port = remote.port ui.info("Fetching", remote.name) git.fetch(remote.name, "--quiet") commits_pushed = git.get_log("%s/%s" % (remote.name, remote_branch), "HEAD") sha1s = [commit["sha1"] for commit in commits_pushed] ui.info("Publishing changes") git.push(*args) if reviewers and not dry_run: ui.info("Adding reviewers...", ("(" + ", ".join(reviewers) + ")")) try: set_reviewers(sha1s, reviewers, username, server, ssh_port) except qisys.command.CommandFailedException as e: ui.warning("Couldn't set reviewers") ui.warning(e) else: ui.info("Done!")
def test_changelog(cd_to_tmpdir): git = TestGit() git.initialize() message_1 = "mess1" git.commit_file("foo.txt", "foo\n", message=message_1) message_2 = "mess2" git.commit_file("foo.txt", "bar\n", message=message_2) commits = git.get_log("HEAD~2", "HEAD") assert len(commits) == 2 assert commits[0]["message"] == message_1 assert commits[1]["message"] == message_2
def push(project, branch, bypass_review=False, dry_run=False, reviewers=None, topic=None): """ Push the changes for review. Unless review is False, in this case, simply update the remote gerrit branch :param reviewers: A list of reviewers to invite to review """ git = qisrc.git.Git(project.path) review_remote = project.review_remote args = list() if dry_run: args.append("--dry-run") args.append(review_remote.url) if bypass_review: args.append("%s:%s" % (branch, branch)) else: ui.info("Pushing code to", review_remote.name, "for review.") remote_ref = "refs/for/%s" % branch if topic: remote_ref = "%s/%s" % (remote_ref, topic) args.append("%s:%s" % (branch, remote_ref)) if reviewers and not dry_run: # Get the SHA1s that will be pushed so that we can add reviewers remote = project.review_remote remote.parse_url() server = remote.server username = remote.username ssh_port = remote.port git.fetch(remote.name) commits_pushed = git.get_log("%s/%s" % (remote.name, branch), "HEAD") sha1s = [commit["sha1"] for commit in commits_pushed] git.push(*args) if reviewers and not dry_run: ui.info("Adding reviewers...") try: for sha1 in sha1s: set_reviewers(sha1, reviewers, username, server, ssh_port) except qisys.command.CommandFailedException as e: ui.warning("Couldn't set reviewers") ui.warning(e) else: ui.info("Done!")