Skip to content

Update open stubsabot PRs #8813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022
Merged
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
8 changes: 4 additions & 4 deletions scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,27 +377,27 @@ async def create_or_update_pull_request(*, title: str, body: str, branch_name: s
response.raise_for_status()


def origin_branch_has_changes(branch: str) -> bool:
def has_non_stubsabot_commits(branch: str) -> bool:
assert not branch.startswith("origin/")
try:
# number of commits on origin/branch that are not on branch or are
# patch equivalent to a commit on branch
output = subprocess.check_output(
["git", "rev-list", "--right-only", "--cherry-pick", "--count", f"{branch}...origin/{branch}"],
["git", "log", "--right-only", "--pretty=%an", "--cherry-pick", f"{branch}...origin/{branch}"],
stderr=subprocess.DEVNULL,
)
return bool(set(output.splitlines()) - {b"stubsabot"})
except subprocess.CalledProcessError:
# origin/branch does not exist
return False
return int(output) > 0


class RemoteConflict(Exception):
pass


def somewhat_safe_force_push(branch: str) -> None:
if origin_branch_has_changes(branch):
if has_non_stubsabot_commits(branch):
raise RemoteConflict(f"origin/{branch} has changes not on {branch}!")
subprocess.check_call(["git", "push", "origin", branch, "--force"])

Expand Down