def testGetNumbering(self, mock_request): params = { 'number': '498032', 'numbering_identifier': 'refs/heads/master', 'numbering_type': 'COMMIT_POSITION', 'project': 'chromium', 'repo': 'chromium/src' } return_value = { 'git_sha': '4c9925b198332f5fbb82b3edb672ed55071f87dd', 'repo': 'chromium/src', 'numbering_type': 'COMMIT_POSITION', 'number': '498032', 'project': 'chromium', 'numbering_identifier': 'refs/heads/master', 'redirect_url': 'https://chromium.googlesource.com/chromium/src/+/foo', 'kind': 'crrev#numberingItem', 'etag': '"z28iYHtWcY14RRFEUgin0OFGLHY/au8p5YtferYwojQRpsPavK6G5-A"' } mock_request.return_value = json.dumps(return_value) self.assertEqual(crrev_service.GetNumbering(**params), return_value) mock_request.assert_called_once_with( 'https://cr-rev.appspot.com/_ah/api/crrev/v1/get_numbering', 'GET', project='chromium', repo='chromium/src', number='498032', numbering_type='COMMIT_POSITION', numbering_identifier='refs/heads/master')
def _GetCommitInfoForAlert(alert): repository_url = None repositories = namespaced_stored_object.Get('repositories') test_path = utils.TestPath(alert.test) if test_path.startswith('ChromiumPerf'): repository_url = repositories['chromium']['repository_url'] elif test_path.startswith('ClankInternal'): repository_url = repositories['clank']['repository_url'] if not repository_url: # Can't get committer info from this repository. return None rev = str(auto_bisect.GetRevisionForBisect(alert.end_revision, alert.test)) # TODO(sullivan, dtu): merge this with similar pinoint code. if (re.match(r'^[0-9]{5,7}$', rev) and repository_url == repositories['chromium']['repository_url']): # This is a commit position, need the git hash. result = crrev_service.GetNumbering( number=rev, numbering_identifier='refs/heads/master', numbering_type='COMMIT_POSITION', project='chromium', repo='chromium/src') rev = result['git_sha'] if not re.match(r'[a-fA-F0-9]{40}$', rev): # This still isn't a git hash; can't assign bug. return None return gitiles_service.CommitInfo(repository_url, rev)
def _AssignBugToCLAuthor(bug_id, alert, service): """Assigns the bug to the author of the given revision.""" repository_url = None repositories = namespaced_stored_object.Get('repositories') test_path = utils.TestPath(alert.test) if test_path.startswith('ChromiumPerf'): repository_url = repositories['chromium']['repository_url'] elif test_path.startswith('ClankInternal'): repository_url = repositories['clank']['repository_url'] if not repository_url: # Can't get committer info from this repository. return rev = str(auto_bisect.GetRevisionForBisect(alert.end_revision, alert.test)) # TODO(sullivan, dtu): merge this with similar pinoint code. if (re.match(r'^[0-9]{5,7}$', rev) and repository_url == repositories['chromium']['repository_url']): # This is a commit position, need the git hash. result = crrev_service.GetNumbering( number=rev, numbering_identifier='refs/heads/master', numbering_type='COMMIT_POSITION', project='chromium', repo='chromium/src') rev = result['git_sha'] if not re.match(r'[a-fA-F0-9]{40}$', rev): # This still isn't a git hash; can't assign bug. return commit_info = gitiles_service.CommitInfo(repository_url, rev) author = commit_info['author']['email'] message = commit_info['message'] sheriff = utils.GetSheriffForAutorollCommit(author, message) if sheriff: service.AddBugComment( bug_id, ('Assigning to sheriff %s because this autoroll is ' 'the only CL in range:\n%s') % (sheriff, message), status='Assigned', owner=sheriff) else: service.AddBugComment( bug_id, 'Assigning to %s because this is the only CL in range:\n%s' % (author, message), status='Assigned', owner=author)
def ResolveToGitHash(commit_position): # TODO: This function assumes Chromium. try: int(commit_position) result = crrev_service.GetNumbering( number=commit_position, numbering_identifier='refs/heads/master', numbering_type='COMMIT_POSITION', project='chromium', repo='chromium/src') if 'error' in result: raise InvalidParamsError( 'Error retrieving commit info: %s' % result['error'].get('message')) return result['git_sha'] except ValueError: pass # It was probably a git hash, so just return as is return commit_position
def ResolveToGitHash(commit_position, suite): try: int(commit_position) if suite in _SUITE_CRREV_CONFIGS: project, repo = _SUITE_CRREV_CONFIGS[suite] else: project, repo = 'chromium', 'chromium/src' result = crrev_service.GetNumbering( number=commit_position, numbering_identifier='refs/heads/master', numbering_type='COMMIT_POSITION', project=project, repo=repo) if 'error' in result: raise InvalidParamsError('Error retrieving commit info: %s' % result['error'].get('message')) return result['git_sha'] except ValueError: pass # It was probably a git hash, so just return as is return commit_position