def test_get_username_list_from_team_404(self): """ Get list of open PR for non-existent team """ responses.add( responses.GET, 'https://api.github.com/orgs/open-craft/teams', body=get_raw_fixture('github/api_teams.json'), content_type='application/json; charset=utf8', status=200) with self.assertRaises(KeyError, msg='non-existent'): github.get_username_list_from_team('open-craft', team_name='non-existent')
def test_get_username_list_from_team_404(self): """ Get list of open PR for non-existent team """ responses.add(responses.GET, 'https://api.github.com/orgs/open-craft/teams', body=get_raw_fixture('github/api_teams.json'), content_type='application/json; charset=utf8', status=200) with self.assertRaises(KeyError, msg='non-existent'): github.get_username_list_from_team('open-craft', team_name='non-existent')
def test_get_username_list_from_team_404(self): """ Get list of open PR for non-existent team """ responses.add( responses.GET, "https://api.github.com/orgs/open-craft/teams", body=get_raw_fixture("github/api_teams.json"), content_type="application/json; charset=utf8", status=200, ) with self.assertRaises(KeyError, msg="non-existent"): github.get_username_list_from_team("open-craft", team_name="non-existent")
def watch_pr(): """ Automatically create/update sandboxes for PRs opened by members of the watched organization on the watched repository """ team_username_list = get_username_list_from_team(settings.WATCH_ORGANIZATION) for username in team_username_list: for pr in get_pr_list_from_username(username, settings.WATCH_FORK): pr_sub_domain = 'pr{number}.sandbox'.format(number=pr.number) instance, created = OpenEdXInstance.objects.get_or_create( sub_domain=pr_sub_domain, fork_name=pr.fork_name, branch_name=pr.branch_name, ) truncated_title = truncatewords(pr.title, 4) instance.name = 'PR#{pr.number}: {truncated_title} ({pr.username}) - {i.reference_name}'\ .format(pr=pr, i=instance, truncated_title=truncated_title) instance.github_pr_number = pr.number instance.ansible_extra_settings = pr.extra_settings instance.save() if created: logger.info('New PR found, creating sandbox: %s', pr) provision_instance(instance.pk)
def github_admin_username_list(self): """ Returns the github usernames of this instance admins Admins are the members of the default team of the `github_admin_organization_name` org """ if self.github_admin_organization_name: return get_username_list_from_team(self.github_admin_organization_name) else: return []
def watch_pr(): """ Automatically create/update sandboxes for PRs opened by members of the watched organization on the watched repository """ team_username_list = get_username_list_from_team(settings.WATCH_ORGANIZATION) for username in team_username_list: for pr in get_pr_list_from_username(username, settings.WATCH_FORK): sub_domain = 'pr{number}.sandbox'.format(number=pr.number) instance, created = SingleVMOpenEdXInstance.objects.update_or_create_from_pr(pr, sub_domain) if created: logger.info('New PR found, creating sandbox: %s', pr) provision_instance(instance.pk)
def watch_pr(): """ Automatically create/update sandboxes for PRs opened by members of the watched organization on the watched repository """ team_username_list = get_username_list_from_team( settings.WATCH_ORGANIZATION) for username in team_username_list: for pr in get_pr_list_from_username(username, settings.WATCH_FORK): sub_domain = 'pr{number}.sandbox'.format(number=pr.number) instance, created = OpenEdXInstance.objects.update_or_create_from_pr( pr, sub_domain) if created: logger.info('New PR found, creating sandbox: %s', pr) provision_instance(instance.pk)
def test_get_username_list_from_team(self): """ Get list of members in a team """ responses.add( responses.GET, 'https://api.github.com/orgs/open-craft/teams', body=get_raw_fixture('github/api_teams.json'), content_type='application/json; charset=utf8', status=200) responses.add( responses.GET, 'https://api.github.com/teams/799617/members', body=get_raw_fixture('github/api_members.json'), content_type='application/json; charset=utf8', status=200) self.assertEqual( github.get_username_list_from_team('open-craft'), ['antoviaque', 'bradenmacdonald', 'e-kolpakov', 'itsjeyd', 'Kelketek', 'mtyaka', 'smarnach'] )
def test_get_username_list_from_team(self): """ Get list of members in a team """ responses.add(responses.GET, 'https://api.github.com/orgs/open-craft/teams', body=get_raw_fixture('github/api_teams.json'), content_type='application/json; charset=utf8', status=200) responses.add(responses.GET, 'https://api.github.com/teams/799617/members', body=get_raw_fixture('github/api_members.json'), content_type='application/json; charset=utf8', status=200) self.assertEqual(github.get_username_list_from_team('open-craft'), [ 'antoviaque', 'bradenmacdonald', 'e-kolpakov', 'itsjeyd', 'Kelketek', 'mtyaka', 'smarnach' ])
def test_get_username_list_from_team(self): """ Get list of members in a team """ responses.add( responses.GET, "https://api.github.com/orgs/open-craft/teams", body=get_raw_fixture("github/api_teams.json"), content_type="application/json; charset=utf8", status=200, ) responses.add( responses.GET, "https://api.github.com/teams/799617/members", body=get_raw_fixture("github/api_members.json"), content_type="application/json; charset=utf8", status=200, ) self.assertEqual( github.get_username_list_from_team("open-craft"), ["antoviaque", "bradenmacdonald", "e-kolpakov", "itsjeyd", "Kelketek", "mtyaka", "smarnach"], )