Replace fixed-name branch rebase with stash merge
This commit is contained in:
parent
6be23859c3
commit
ef76e27efb
1 changed files with 20 additions and 9 deletions
|
@ -71,14 +71,22 @@ def set_git_remote_url(git, token, github_repository):
|
||||||
git.remote('set-url', 'origin', "https://x-access-token:%s@github.com/%s" % (token, github_repository))
|
git.remote('set-url', 'origin', "https://x-access-token:%s@github.com/%s" % (token, github_repository))
|
||||||
|
|
||||||
|
|
||||||
def push_changes(git, remote_exists, branch, commit_message):
|
def checkout_branch(git, remote_exists, branch):
|
||||||
git.add('-A')
|
|
||||||
git.commit(m=commit_message)
|
|
||||||
if remote_exists:
|
if remote_exists:
|
||||||
|
git.stash('--include-untracked')
|
||||||
git.checkout(branch)
|
git.checkout(branch)
|
||||||
git.rebase('-Xtheirs', '-')
|
try:
|
||||||
|
git.stash('pop')
|
||||||
|
except:
|
||||||
|
git.checkout('--theirs', '.')
|
||||||
|
git.reset()
|
||||||
else:
|
else:
|
||||||
git.checkout('HEAD', b=branch)
|
git.checkout('HEAD', b=branch)
|
||||||
|
|
||||||
|
|
||||||
|
def push_changes(git, branch, commit_message):
|
||||||
|
git.add('-A')
|
||||||
|
git.commit(m=commit_message)
|
||||||
return git.push('-f', '--set-upstream', 'origin', branch)
|
return git.push('-f', '--set-upstream', 'origin', branch)
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,16 +118,12 @@ def process_event(event_name, event_data, repo, branch, base, remote_exists):
|
||||||
pull_request_reviewers = os.environ.get('PULL_REQUEST_REVIEWERS')
|
pull_request_reviewers = os.environ.get('PULL_REQUEST_REVIEWERS')
|
||||||
pull_request_team_reviewers = os.environ.get('PULL_REQUEST_TEAM_REVIEWERS')
|
pull_request_team_reviewers = os.environ.get('PULL_REQUEST_TEAM_REVIEWERS')
|
||||||
|
|
||||||
# Get the HEAD committer's email and name
|
|
||||||
author_email, author_name = get_head_author(event_name, event_data)
|
|
||||||
# Set git configuration
|
|
||||||
set_git_config(repo.git, author_email, author_name)
|
|
||||||
# Update URL for the 'origin' remote
|
# Update URL for the 'origin' remote
|
||||||
set_git_remote_url(repo.git, github_token, github_repository)
|
set_git_remote_url(repo.git, github_token, github_repository)
|
||||||
|
|
||||||
# Push the local changes to the remote branch
|
# Push the local changes to the remote branch
|
||||||
print("Pushing changes.")
|
print("Pushing changes.")
|
||||||
push_result = push_changes(repo.git, remote_exists, branch, commit_message)
|
push_result = push_changes(repo.git, branch, commit_message)
|
||||||
print(push_result)
|
print(push_result)
|
||||||
|
|
||||||
# If the remote existed then a PR likely exists and we can finish here
|
# If the remote existed then a PR likely exists and we can finish here
|
||||||
|
@ -199,6 +203,13 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
|
||||||
print("Pull request branch '%s' already exists for this commit. Skipping." % branch)
|
print("Pull request branch '%s' already exists for this commit. Skipping." % branch)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
# Get the HEAD committer's email and name
|
||||||
|
author_email, author_name = get_head_author(event_name, event_data)
|
||||||
|
# Set git configuration
|
||||||
|
set_git_config(repo.git, author_email, author_name)
|
||||||
|
# Checkout branch
|
||||||
|
checkout_branch(repo.git, remote_exists, branch)
|
||||||
|
|
||||||
# Check if there are changes to pull request
|
# Check if there are changes to pull request
|
||||||
if repo.is_dirty() or len(repo.untracked_files) > 0:
|
if repo.is_dirty() or len(repo.untracked_files) > 0:
|
||||||
print("Repository has modified or untracked files.")
|
print("Repository has modified or untracked files.")
|
||||||
|
|
Loading…
Reference in a new issue