Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 0 additions & 44 deletions hack/backfill.py

This file was deleted.

49 changes: 27 additions & 22 deletions hack/stabilization-changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,28 +315,27 @@ def notify(message, webhook=None):


def promote(version, channel_name, channel_path, subject, body, github_repo, github_token, upstream_remote, upstream_branch):
if not github_token:
raise ValueError('cannot promote without a configured GitHub token')

process = subprocess.run(['git', 'remote', 'get-url', '--push', upstream_remote], check=True, capture_output=True, text=True)
upstream_uri = urllib.parse.urlsplit(process.stdout.strip())
if upstream_uri.scheme != 'https':
raise ValueError('pushing by token requires HTTPS for security, so cannot use {} scheme {}'.format(upstream_remote, upstream_uri.scheme))
_, have_user_info, host_info = upstream_uri.netloc.rpartition('@')
if have_user_info:
raise ValueError('remote {} configured with user info is not supported, because we expect to authenticate with the configured GitHub token'.format(upstream_remote))
upstream_uri_with_token = urllib.parse.urlunsplit(upstream_uri._replace(netloc='{}@{}'.format(github_token, host_info)))

subprocess.run(['git', 'fetch', upstream_remote], check=True)
branch = 'promote-{}-to-{}'.format(version, channel_name)
try:
subprocess.run(['git', 'show', branch], check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as error:
if 'unknown revision or path not in the working tree' not in error.stderr:
raise
else:
raise ValueError('branch {} already exists; possibly waiting for an open pull request to merge'.format(branch))
subprocess.run(['git', 'checkout', '-b', branch, '{}/{}'.format(upstream_remote, upstream_branch)], check=True)
if github_token:
process = subprocess.run(['git', 'remote', 'get-url', '--push', upstream_remote], check=True, capture_output=True, text=True)
upstream_uri = urllib.parse.urlsplit(process.stdout.strip())
if upstream_uri.scheme != 'https':
raise ValueError('pushing by token requires HTTPS for security, so cannot use {} scheme {}'.format(upstream_remote, upstream_uri.scheme))
_, have_user_info, host_info = upstream_uri.netloc.rpartition('@')
if have_user_info:
raise ValueError('remote {} configured with user info is not supported, because we expect to authenticate with the configured GitHub token'.format(upstream_remote))
upstream_uri_with_token = urllib.parse.urlunsplit(upstream_uri._replace(netloc='{}@{}'.format(github_token, host_info)))

subprocess.run(['git', 'fetch', upstream_remote], check=True)
branch = 'promote-{}-to-{}'.format(version, channel_name)
try:
subprocess.run(['git', 'show', branch], check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as error:
if 'unknown revision or path not in the working tree' not in error.stderr:
raise
else:
raise ValueError('branch {} already exists; possibly waiting for an open pull request to merge'.format(branch))
subprocess.run(['git', 'checkout', '-b', branch, '{}/{}'.format(upstream_remote, upstream_branch)], check=True)

with open(channel_path) as f:
try:
data = yaml.load(f, Loader=yaml.SafeLoader)
Expand All @@ -350,6 +349,12 @@ def promote(version, channel_name, channel_path, subject, body, github_repo, git
with open(channel_path, 'w') as f:
yaml.safe_dump(data, f, default_flow_style=False)
message = '{}\n\n{}\n'.format(subject, textwrap.fill(body, width=76))

if not github_token:
pull = github.PullRequest
pull.html_url = 'data://no-token-so-no-pull'
return pull

subprocess.run(['git', 'commit', '--file', '-', channel_path], check=True, encoding='utf-8', input=message)
subprocess.run(['git', 'push', '-u', upstream_uri_with_token, branch], check=True)

Expand Down