async def wait_for_checkboxes(*, github_access_token, org, repo): """ Wait for checkboxes, polling every 60 seconds Args: github_access_token (str): The github access token org (str): The github organization (eg mitodl) repo (str): The github repository (eg micromasters) """ print("Waiting for checkboxes to be checked. Polling every 60 seconds...") error_count = 0 while True: try: unchecked_authors = get_unchecked_authors( github_access_token=github_access_token, org=org, repo=repo, ) if not unchecked_authors: break except Exception as exception: # pylint: disable=broad-except sys.stderr.write("Error: {}".format(exception)) error_count += 1 if error_count >= 5: raise await asyncio.sleep(60) print(".", end='') sys.stdout.flush() print("All checkboxes are now checked")
def test_get_unchecked_authors(): """ get_unchecked_authors should download the PR body, parse it, filter out checked authors and leave only unchecked ones """ org = 'org' repo = 'repo' access_token = 'all-access' with patch('lib.get_release_pr', autospec=True, return_value=ReleasePR( body=FAKE_RELEASE_PR_BODY, version='1.2.3', url='http://url' )) as get_release_pr_mock: unchecked = get_unchecked_authors( github_access_token=access_token, org=org, repo=repo, ) assert unchecked == {"Alice Pote"} get_release_pr_mock.assert_called_once_with( github_access_token=access_token, org=org, repo=repo, )
async def do_release(self, repo_info, version): """ Start a new release and wait for deployment Args: repo_info (RepoInfo): Information for a repo version (str): The version """ repo_url = repo_info.repo_url channel_id = repo_info.channel_id release(repo_url, version) await self.say( channel_id, "Behold, my new evil scheme - release {}! Now deploying to RC...". format(version)) await wait_for_deploy(repo_url, repo_info.rc_hash_url, "release-candidate") org, repo = get_org_and_repo(repo_url) unchecked_authors = get_unchecked_authors(org, repo, version) slack_usernames = self.translate_slack_usernames(unchecked_authors) await self.say( channel_id, "Release {version} was deployed! PR is up at <{pr_url}|Release {version}>." " These people have commits in this release: {authors}".format( version=version, authors=", ".join(slack_usernames), pr_url=get_release_pr(org, repo, version)['html_url'], ))
async def release_command(self, command_args): """ Start a new release and wait for deployment Args: command_args (CommandArgs): The arguments for this command """ repo_info = command_args.repo_info version = command_args.args[0] repo_url = repo_info.repo_url channel_id = repo_info.channel_id org, repo = get_org_and_repo(repo_url) pr = get_release_pr(self.github_access_token, org, repo) if pr: raise ReleaseException( "A release is already in progress: {}".format(pr.url)) release( github_access_token=self.github_access_token, repo_url=repo_url, new_version=version, ) await self.say( channel_id=channel_id, text= "Behold, my new evil scheme - release {version} for {project}! Now deploying to RC..." .format( version=version, project=repo_info.name, ), ) await wait_for_deploy( github_access_token=self.github_access_token, repo_url=repo_url, hash_url=repo_info.rc_hash_url, watch_branch="release-candidate", ) unchecked_authors = get_unchecked_authors(self.github_access_token, org, repo) slack_usernames = self.translate_slack_usernames(unchecked_authors) pr = get_release_pr(self.github_access_token, org, repo) await self.say( channel_id=channel_id, text= "Release {version} for {project} was deployed! PR is up at {pr_url}." " These people have commits in this release: {authors}".format( version=version, authors=", ".join(slack_usernames), pr_url=pr.url, project=repo_info.name, )) await self.wait_for_checkboxes(repo_info, command_args.manager) command_args.loop.create_task(self.delay_message(repo_info))
def test_get_unchecked_authors(): """ get_unchecked_authors should download the PR body, parse it, filter out checked authors and leave only unchecked ones """ org = 'org' repo = 'repo' version = 'version' with patch('lib.get_release_pr', autospec=True, return_value=RELEASE_PR) as get_release_pr_mock: unchecked = get_unchecked_authors(org, repo, version) assert unchecked == {"Alice Pote"} get_release_pr_mock.assert_called_once_with(org, repo, version)
async def _web_application_release(self, command_args): """Do a web application release""" repo_info = command_args.repo_info version = command_args.args[0] repo_url = repo_info.repo_url channel_id = repo_info.channel_id org, repo = get_org_and_repo(repo_url) release( github_access_token=self.github_access_token, repo_url=repo_url, new_version=version, ) await self.say( channel_id=channel_id, text="Behold, my new evil scheme - release {version} for {project}! Now deploying to RC...".format( version=version, project=repo_info.name, ), ) await wait_for_deploy( github_access_token=self.github_access_token, repo_url=repo_url, hash_url=repo_info.rc_hash_url, watch_branch="release-candidate", ) unchecked_authors = get_unchecked_authors( github_access_token=self.github_access_token, org=org, repo=repo, ) slack_usernames = self.translate_slack_usernames(unchecked_authors) pr = get_release_pr( github_access_token=self.github_access_token, org=org, repo=repo, ) await self.say( channel_id=channel_id, text="Release {version} for {project} was deployed! PR is up at {pr_url}." " These people have commits in this release: {authors}".format( version=version, authors=", ".join(slack_usernames), pr_url=pr.url, project=repo_info.name, ) ) await self.wait_for_checkboxes(repo_info, command_args.manager) command_args.loop.create_task(self.delay_message(repo_info))
async def message_if_unchecked(self, repo_info, version): """ Send a message next morning if any boxes are not yet checked off Args: repo_info (RepoInfo): Information for a repo version (str): The version of the release to check """ org, repo = get_org_and_repo(repo_info.repo_url) unchecked_authors = get_unchecked_authors(org, repo, version) if unchecked_authors: slack_usernames = self.translate_slack_usernames(unchecked_authors) await self.say( repo_info.channel_id, "What an unexpected surprise! " "The following authors have not yet checked off their boxes: {}" .format(", ".join(slack_usernames)))
async def message_if_unchecked(self, repo_info): """ Send a message next morning if any boxes are not yet checked off Args: repo_info (RepoInfo): Information for a repo """ org, repo = get_org_and_repo(repo_info.repo_url) unchecked_authors = get_unchecked_authors(self.github_access_token, org, repo) if unchecked_authors: slack_usernames = self.translate_slack_usernames(unchecked_authors) await self.say( channel_id=repo_info.channel_id, text="What an unexpected surprise! " "The following authors have not yet checked off their boxes for {project}: {names}" .format( names=", ".join(slack_usernames), project=repo_info.name, ))