def coub_wbnb_changes_and_commits_on_working_base(): # Set the working base to a branch that is not the pull request base repo.git.checkout(NOT_BASE_BRANCH) # Create commits on the working base create_commits() # Create tracked and untracked file changes tracked_content, untracked_content = create_changes() result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, BASE, BRANCH) assert result["action"] == "created" assert get_tracked_content() == tracked_content assert get_untracked_content() == untracked_content # Push pull request branch to remote repo.git.push("--force", REPO_URL, f"HEAD:refs/heads/{BRANCH}") repo.remotes.origin.fetch() after_test(delete_remote=False) before_test() # Set the working base to a branch that is not the pull request base repo.git.checkout(NOT_BASE_BRANCH) # Create commits on the working base create_commits() # Create tracked and untracked file changes tracked_content, untracked_content = create_changes() result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, BASE, BRANCH) assert result["action"] == "updated" assert result["diff"] assert get_tracked_content() == tracked_content assert get_untracked_content() == untracked_content
def coub_wbnb_changes_no_diff(): # Save the default branch tracked content default_tracked_content = get_tracked_content() # Set the working base to a branch that is not the pull request base repo.git.checkout(NOT_BASE_BRANCH) # Create tracked and untracked file changes tracked_content, untracked_content = create_changes() result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, BASE, BRANCH) assert result["action"] == "created" assert get_tracked_content() == tracked_content assert get_untracked_content() == untracked_content # Push pull request branch to remote repo.git.push("--force", REPO_URL, f"HEAD:refs/heads/{BRANCH}") repo.remotes.origin.fetch() after_test(delete_remote=False) before_test() # Set the working base to a branch that is not the pull request base repo.git.checkout(NOT_BASE_BRANCH) # Running with no update effectively reverts the branch back to match the base result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, BASE, BRANCH) assert result["action"] == "updated" assert result["diff"] == False assert get_tracked_content() == default_tracked_content
def coub_commits_on_base_no_diff(): # Create tracked and untracked file changes tracked_content, untracked_content = create_changes() result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, None, BRANCH) assert result["action"] == "created" assert get_tracked_content() == tracked_content assert get_untracked_content() == untracked_content # Push pull request branch to remote repo.git.push("--force", REPO_URL, f"HEAD:refs/heads/{BRANCH}") repo.remotes.origin.fetch() after_test(delete_remote=False) before_test() # Create commits on the base tracked_content, untracked_content = create_commits() repo.git.push("--force", REPO_URL, f"HEAD:refs/heads/{DEFAULT_BRANCH}") repo.remotes.origin.fetch() # Create the same tracked and untracked file changes that were made to the base create_changes(tracked_content, untracked_content) result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, None, BRANCH) assert result["action"] == "updated" assert result["diff"] == False assert get_tracked_content() == tracked_content assert get_untracked_content() == untracked_content
def coub_untracked_changes(): # Create an untracked file change untracked_content = create_untracked_change() result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, None, BRANCH) assert result["action"] == "created" assert get_untracked_content() == untracked_content # Push pull request branch to remote repo.git.push("--force", REPO_URL, f"HEAD:refs/heads/{BRANCH}") repo.remotes.origin.fetch() after_test(delete_remote=False) before_test() # Create an untracked file change untracked_content = create_untracked_change() result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, None, BRANCH) assert result["action"] == "updated" assert result["diff"] assert get_untracked_content() == untracked_content
# Output head branch print(f"Pull request branch to create or update set to '{branch}'") # Set the committer and author try: set_committer_author(repo, committer, author) except ValueError as e: print(f"::error::{e} " + "Unable to continue. Exiting.") sys.exit(1) # Set the repository URL repo_url = f"https://*****:*****@github.com/{github_repository}" # Create or update the pull request branch result = coub.create_or_update_branch(repo, repo_url, commit_message, base, branch) if result["action"] in ["created", "updated"]: # The branch was created or updated print(f"Pushing pull request branch to 'origin/{branch}'") repo.git.push("--force", repo_url, f"HEAD:refs/heads/{branch}") # Set the base. It would have been 'None' if not specified as an input base = result["base"] # If there is no longer a diff with the base delete the branch and exit if not result["diff"]: print(f"Branch '{branch}' no longer differs from base branch '{base}'") print(f"Closing pull request and deleting branch '{branch}'") repo.git.push("--delete", "--force", repo_url, f"refs/heads/{branch}") sys.exit()
def coub_wbnb_no_changes_on_create(): # Set the working base to a branch that is not the pull request base repo.git.checkout(NOT_BASE_BRANCH) result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, BASE, BRANCH) assert result["action"] == "none"
def coub_no_changes_on_create(): result = coub.create_or_update_branch(repo, REPO_URL, COMMIT_MESSAGE, None, BRANCH) assert result["action"] == "none"