Skip to content

Commit beedd31

Browse files
Merge branch 'main' into release-sorting
2 parents 2845a93 + 8a67191 commit beedd31

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

.github/update-release-branch.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# The branch being merged from.
99
# This is the one that contains day-to-day development work.
10-
MASTER_BRANCH = 'master'
10+
MAIN_BRANCH = 'main'
1111
# The branch being merged into.
1212
# This is the release branch that users reference.
1313
LATEST_RELEASE_BRANCH = 'v1'
@@ -28,7 +28,7 @@ def branch_exists_on_remote(branch_name):
2828
return run_git('ls-remote', '--heads', ORIGIN, branch_name).strip() != ''
2929

3030
# Opens a PR from the given branch to the release branch
31-
def open_pr(repo, all_commits, short_master_sha, branch_name):
31+
def open_pr(repo, all_commits, short_main_sha, branch_name):
3232
# Sort the commits into the pull requests that introduced them,
3333
# and any commits that don't have a pull request
3434
pull_requests = []
@@ -49,7 +49,7 @@ def open_pr(repo, all_commits, short_master_sha, branch_name):
4949
commits_without_pull_requests = sorted(commits_without_pull_requests, key=lambda c: c.commit.author.date)
5050

5151
# Start constructing the body text
52-
body = 'Merging ' + short_master_sha + ' into ' + LATEST_RELEASE_BRANCH
52+
body = 'Merging ' + short_main_sha + ' into ' + LATEST_RELEASE_BRANCH
5353

5454
conductor = get_conductor(repo, pull_requests, commits_without_pull_requests)
5555
body += '\n\nConductor for this PR is @' + conductor
@@ -71,7 +71,7 @@ def open_pr(repo, all_commits, short_master_sha, branch_name):
7171
body += ' - ' + get_truncated_commit_message(commit)
7272
body += ' (@' + commit.author.login + ')'
7373

74-
title = 'Merge ' + MASTER_BRANCH + ' into ' + LATEST_RELEASE_BRANCH
74+
title = 'Merge ' + MAIN_BRANCH + ' into ' + LATEST_RELEASE_BRANCH
7575

7676
# Create the pull request
7777
pr = repo.create_pull(title=title, body=body, head=branch_name, base=LATEST_RELEASE_BRANCH)
@@ -90,12 +90,12 @@ def get_conductor(repo, pull_requests, other_commits):
9090
# Otherwise take the author of the latest commit
9191
return other_commits[-1].author.login
9292

93-
# Gets a list of the SHAs of all commits that have happened on master
93+
# Gets a list of the SHAs of all commits that have happened on main
9494
# since the release branched off.
9595
# This will not include any commits that exist on the release branch
96-
# that aren't on master.
96+
# that aren't on main.
9797
def get_commit_difference(repo):
98-
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + LATEST_RELEASE_BRANCH + '...' + MASTER_BRANCH).strip().split('\n')
98+
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + LATEST_RELEASE_BRANCH + '...' + MAIN_BRANCH).strip().split('\n')
9999

100100
# Convert to full-fledged commit objects
101101
commits = [repo.get_commit(c) for c in commits]
@@ -115,7 +115,7 @@ def get_truncated_commit_message(commit):
115115
else:
116116
return message
117117

118-
# Converts a commit into the PR that introduced it to the master branch.
118+
# Converts a commit into the PR that introduced it to the main branch.
119119
# Returns the PR object, or None if no PR could be found.
120120
def get_pr_for_commit(repo, commit):
121121
prs = commit.get_pulls()
@@ -144,20 +144,20 @@ def main():
144144
repo = Github(github_token).get_repo(repository_nwo)
145145

146146
# Print what we intend to go
147-
print('Considering difference between ' + MASTER_BRANCH + ' and ' + LATEST_RELEASE_BRANCH)
148-
short_master_sha = run_git('rev-parse', '--short', MASTER_BRANCH).strip()
149-
print('Current head of ' + MASTER_BRANCH + ' is ' + short_master_sha)
147+
print('Considering difference between ' + MAIN_BRANCH + ' and ' + LATEST_RELEASE_BRANCH)
148+
short_main_sha = run_git('rev-parse', '--short', MAIN_BRANCH).strip()
149+
print('Current head of ' + MAIN_BRANCH + ' is ' + short_main_sha)
150150

151151
# See if there are any commits to merge in
152152
commits = get_commit_difference(repo)
153153
if len(commits) == 0:
154-
print('No commits to merge from ' + MASTER_BRANCH + ' to ' + LATEST_RELEASE_BRANCH)
154+
print('No commits to merge from ' + MAIN_BRANCH + ' to ' + LATEST_RELEASE_BRANCH)
155155
return
156156

157157
# The branch name is based off of the name of branch being merged into
158158
# and the SHA of the branch being merged from. Thus if the branch already
159159
# exists we can assume we don't need to recreate it.
160-
new_branch_name = 'update-' + LATEST_RELEASE_BRANCH + '-' + short_master_sha
160+
new_branch_name = 'update-' + LATEST_RELEASE_BRANCH + '-' + short_main_sha
161161
print('Branch name is ' + new_branch_name)
162162

163163
# Check if the branch already exists. If so we can abort as this script
@@ -168,11 +168,11 @@ def main():
168168

169169
# Create the new branch and push it to the remote
170170
print('Creating branch ' + new_branch_name)
171-
run_git('checkout', '-b', new_branch_name, MASTER_BRANCH)
171+
run_git('checkout', '-b', new_branch_name, MAIN_BRANCH)
172172
run_git('push', ORIGIN, new_branch_name)
173173

174174
# Open a PR to update the branch
175-
open_pr(repo, commits, short_master_sha, new_branch_name)
175+
open_pr(repo, commits, short_main_sha, new_branch_name)
176176

177177
if __name__ == '__main__':
178178
main()

0 commit comments

Comments
 (0)