def test_get_pr_info_by_number(self): """ Get all available information about PR by PR number """ pr_fixture = get_raw_fixture('github/api_pr.json') responses.add( responses.GET, 'https://api.github.com/repos/edx/edx-platform/pulls/8474', body=pr_fixture, content_type='application/json; charset=utf8', status=200 ) pr_info = github.get_pr_info_by_number('edx/edx-platform', 8474) expected_pr_info = json.loads(pr_fixture) self.assertEqual(pr_info, expected_pr_info)
def test_get_pr_info_by_number(self): """ Get all available information about PR by PR number """ pr_fixture = get_raw_fixture('github/api_pr.json') responses.add( responses.GET, 'https://api.github.com/repos/edx/edx-platform/pulls/8474', body=pr_fixture, content_type='application/json; charset=utf8', status=200) pr_info = github.get_pr_info_by_number('edx/edx-platform', 8474) expected_pr_info = json.loads(pr_fixture) self.assertEqual(pr_info, expected_pr_info)
def shut_down_obsolete_pr_sandboxes(): """ Shut down instances whose PRs got merged (more than) one week ago. """ for instance in OpenEdXInstance.objects.filter(watchedpullrequest__isnull=False): pr = github.get_pr_info_by_number( instance.watchedpullrequest.target_fork_name, instance.watchedpullrequest.github_pr_number ) if pr['state'] == 'closed': closed_at = github.parse_date(pr['closed_at']) now = datetime.now() if sufficient_time_passed(closed_at, now, 7): instance.shut_down()
def shut_down_obsolete_pr_sandboxes(): """ Shut down instances whose PRs got merged (more than) one week ago. """ for instance in OpenEdXInstance.objects.filter(watchedpullrequest__isnull=False): pr = github.get_pr_info_by_number( instance.watchedpullrequest.target_fork_name, instance.watchedpullrequest.github_pr_number ) if pr['state'] == 'closed' and not instance.ref.is_archived: closed_at = github.parse_date(pr['closed_at']) now = datetime.now() if sufficient_time_passed(closed_at, now, 7): instance.logger.info("Shutting down obsolete sandbox instance") instance.archive()