def get_rietveld_diff(rietveld_url, cc, git_checkout_path): # pragma: no cover """Reads the diff for a specified commit Args: commit_hash(str): a git hash cc: a cursor for the Cloud SQL connection git_checkout_path(str): path to a local git checkout Return: diff(list): the lines in the rietveld diff """ canonical_url = crp.to_canonical_review_url(rietveld_url) json_data = crp.extract_code_review_json_data( canonical_url, cc, git_checkout_path) for message in json_data['messages']: if ('committed' in message['text'].lower() and (json_data['closed'] or message['issue_was_closed'])): if 'patchset' in message: patchset = message['patchset'] elif message['text'] and 'patchset' in message['text']: for word in message['text'].split(): if word.startswith('(id:'): patchset = word[4:].strip(')') else: # no commited patchset id found so diff comparison cannot happen return [] url_components = re.split('(https?:\/\/)([\da-z\.-]+)', canonical_url) diff_url = '%s%s/download/issue%s_%s.diff' % (url_components[1], url_components[2], url_components[3][1:], patchset) h = httplib2.Http(".cache") _, content = h.request(diff_url, "GET") lines = content.splitlines() return lines return []
def test_extract_code_review_json_data(self, mock_g, mock_r): cc = None checkout = None code_review_parse.extract_code_review_json_data(self.r_lgtm_no_tbr, cc, checkout) mock_r.assert_called_with(self.r_lgtm_no_tbr) code_review_parse.extract_code_review_json_data(self.g_not_lgtm, cc, checkout) mock_g.assert_called_with(self.g_not_lgtm, cc, checkout) code_review_parse.extract_code_review_json_data('invalid url', cc, checkout)
def test_extract_code_review_json_data(self, mock_g, mock_r): cc = None checkout = None code_review_parse.extract_code_review_json_data( self.r_lgtm_no_tbr, cc, checkout) mock_r.assert_called_with(self.r_lgtm_no_tbr) code_review_parse.extract_code_review_json_data( self.g_not_lgtm, cc, checkout) mock_g.assert_called_with(self.g_not_lgtm, cc, checkout) code_review_parse.extract_code_review_json_data( 'invalid url', cc, checkout)