Skip to content

Commit

Permalink
It works
Browse files Browse the repository at this point in the history
  • Loading branch information
legoguy1000 committed Jan 12, 2025
1 parent d7ffc48 commit 3c4ac69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
1 change: 0 additions & 1 deletion vendor-update/pr-template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# SUMMARY
The following vendor dependencies have been updated.

| Vendor | Change |
Expand Down
34 changes: 27 additions & 7 deletions vendor-update/vendor-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,34 @@
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", None)
BASE_BRANCH = os.getenv("BASE_BRANCH", "main")
REPO_PATH = os.getenv("REPO_PATH", None)
PR_TITLE = []

if __name__ == "__main__":
auth = Auth.Token(GITHUB_TOKEN)
g = Github(auth=auth)
repo = Repo(Path.cwd())
try:
repo.delete_head(BRANCH_NAME)
repo.git.checkout(BRANCH_NAME)
current_branch = repo.active_branch
target_branch = repo.heads[BASE_BRANCH]
rebase_branch = repo.create_head("temp_rebase_branch", target_branch)
repo.head.reference = rebase_branch
repo.head.reset(index=True, working_tree=True)
try:
repo.git.rebase(current_branch)
except exc.GitCommandError as e:
# Handle rebase conflicts if any
print("Rebase conflicts occurred. Resolve them manually.")
print(e)
else:
# Delete the original branch
repo.delete_head(current_branch)
# Rename the rebased branch to the original branch name
rebase_branch.rename(current_branch)
# Update the remote branch (if needed)
# repo.remotes.origin.push(force=True)
except exc.GitCommandError:
pass
new_branch = repo.create_head(BRANCH_NAME)
new_branch.checkout(force=True)
repo.git.checkout('-b', BRANCH_NAME)

print("Checking for WPILIB Updates")
update_wpilib = False
Expand Down Expand Up @@ -57,6 +74,7 @@
"new_version": wpilib_latest_version,
}
)
PR_TITLE.append("WPILib")
else:
print("No new version of WPILIB.")
print("Checking for Vendor Dep Updates")
Expand Down Expand Up @@ -94,12 +112,13 @@
modified_deps = [x for x in untracked + diffs if x.startswith("vendordeps")]
if len(modified_deps) > 0:
repo.git.add("vendordeps/*")
PR_TITLE.append("Vendor Dependency")
else:
print("No vendor updates")
if len(modified_deps) == 0 and not update_wpilib:
sys.exit(0)

repo.index.commit("Updating Vendor Dependencies and WPILIB")
repo.index.commit(f"Updating {', '.join([x.get('name') for x in UPDATED_DEPS])}")
repo.git.push("--force", "--set-upstream", "origin", repo.head.ref)

gh_repo = g.get_repo(REPO_PATH)
Expand All @@ -108,8 +127,9 @@
)
with open(SCRIPT_PATH.joinpath("pr-template.j2")) as f:
body = Template(f.read()).render(deps=UPDATED_DEPS)
title = f"{" and ".join(PR_TITLE)} Updates"
if pulls.totalCount == 0:
gh_repo.create_pull(base=BASE_BRANCH, head=BRANCH_NAME, title="Vendor Dependency Updates", body=body, draft=True)
gh_repo.create_pull(base=BASE_BRANCH, head=BRANCH_NAME, title=title, body=body, draft=True)
elif pulls.totalCount == 1:
pull: PullRequest = pulls[0]
pull.edit(body=body)
pull.edit(body=body, title=title)

0 comments on commit 3c4ac69

Please sign in to comment.