Skip to content
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
49 changes: 34 additions & 15 deletions tools/deprecate_version/deprecate_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ def CreateIssues(access_token, runtime_and_pr):

Args:
access_token: GitHub access token (see comment at top of file).
runtime_and_pr: a list of runtime guards and the PRs they were added.
runtime_and_pr: a list of runtime guards and the PRs and commits they were added.
"""
repo = github.Github(access_token).get_repo('envoyproxy/envoy')
git = github.Github(access_token)
repo = git.get_repo('envoyproxy/envoy')

# Find GitHub label objects for LABELS.
labels = []
Expand All @@ -70,47 +71,63 @@ def CreateIssues(access_token, runtime_and_pr):
raise DeprecateVersionError('Unknown labels (expected %s, got %s)' % (LABELS, labels))

issues = []
for runtime_guard, pr in runtime_and_pr:
for runtime_guard, pr, commit in runtime_and_pr:
# Who is the author?
pr_info = repo.get_pull(pr)
if pr:
# Extract PR title, number, and author.
pr_info = repo.get_pull(pr)
change_title = pr_info.title
number = ('#%d') % pr
login = pr_info.user.login
else:
# Extract commit message, sha, and author.
# Only keep commit message title (remove description), and truncate to 50 characters.
change_title = commit.message.split('\n')[0][:50]
number = ('commit %s') % commit.hexsha
email = commit.author.email
# Use the commit author's email to search through users for their login.
search_user = git.search_users(email.split('@')[0] + " in:email")
login = search_user[0].login if search_user else None

title = '%s deprecation' % (runtime_guard)
body = ('#%d (%s) introduced a runtime guarded feature. This issue '
'tracks source code cleanup.') % (pr, pr_info.title)
body = ('%s (%s) introduced a runtime guarded feature. This issue '
'tracks source code cleanup.') % (number, change_title)

print(title)
print(body)
print(' >> Assigning to %s' % pr_info.user.login)
print(' >> Assigning to %s' % (login or email))

# TODO(htuch): Figure out how to do this without legacy and faster.
exists = repo.legacy_search_issues('open', '"%s"' % title) or repo.legacy_search_issues(
'closed', '"%s"' % title)
if exists:
print(' >> Issue already exists, not posting!')
else:
issues.append((title, body, pr_info.user))
issues.append((title, body, login))

if not issues:
print('No features to deprecate in this release')
return

if GetConfirmation():
print('Creating issues...')
for title, body, user in issues:
for title, body, login in issues:
try:
repo.create_issue(title, body=body, assignees=[user.login], labels=labels)
repo.create_issue(title, body=body, assignees=[login], labels=labels)
except github.GithubException as e:
try:
body += '\ncc @' + user.login
if login:
body += '\ncc @' + login
repo.create_issue(title, body=body, labels=labels)
print(('unable to assign issue %s to %s. Add them to the Envoy proxy org'
'and assign it their way.') % (title, user.login))
'and assign it their way.') % (title, login))
except github.GithubException as e:
print('GithubException while creating issue.')
raise


def GetRuntimeAndPr():
"""Returns a list of tuples of [runtime features to deprecate, PR the feature was added]
"""Returns a list of tuples of [runtime features to deprecate, PR, commit the feature was added]
"""
repo = Repo(os.getcwd())

Expand Down Expand Up @@ -140,14 +157,16 @@ def GetRuntimeAndPr():
if runtime_guard == 'envoy.reloadable_features.test_feature_true':
found_test_feature_true = True
continue
pr = (int(re.search('\(#(\d+)\)', commit.message).group(1)))
pr_num = re.search('\(#(\d+)\)', commit.message)
# Some commits may not come from a PR (if they are part of a security point release).
pr = (int(pr_num.group(1))) if pr_num else None
pr_date = date.fromtimestamp(commit.committed_date)
removable = (pr_date < removal_date)
# Add the runtime guard and PR to the list to file issues about.
print('Flag ' + runtime_guard + ' added at ' + str(pr_date) + ' ' +
(removable and 'and is safe to remove' or 'is not ready to remove'))
if removable:
features_to_flip.append((runtime_guard, pr))
features_to_flip.append((runtime_guard, pr, commit))
print('Failed to find test_feature_false. Script needs fixing')
sys.exit(1)

Expand Down