def merge_pull_request(self, pull_request): if self.dry_run: _log.info('[dry_run] Would have attempted to merge PR') return _log.info('Attempting to merge...') # This is outside of the try block because if there's a problem communicating # with the GitHub API, we should hard fail. branch = self.wpt_github.get_pr_branch(pull_request.number) try: self.wpt_github.merge_pr(pull_request.number) # This is in the try block because if a PR can't be merged, we shouldn't # delete its branch. _log.info('Deleting remote branch %s...', branch) self.wpt_github.delete_remote_branch(branch) change_id = self.wpt_github.extract_metadata( 'Change-Id: ', pull_request.body) if change_id: cl = GerritCL(data={'change_id': change_id}, api=self.gerrit) pr_url = '{}pull/{}'.format(WPT_GH_URL, pull_request.number) cl.post_comment(( 'The WPT PR for this CL has been merged upstream! {pr_url}' ).format(pr_url=pr_url)) except MergeError: _log.warn('Could not merge PR.')
def test_fetch_current_revision_commit(self): host = MockHost() host.executive = mock_git_commands({ 'fetch': '', 'rev-parse': '4de71d0ce799af441c1f106c5432c7fa7256be45', 'footers': 'no-commit-position-yet' }, strict=True) data = { 'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb', 'subject': 'fake subject', '_number': 638250, 'current_revision': '1', 'revisions': {'1': { 'fetch': {'http': { 'url': 'https://chromium.googlesource.com/chromium/src', 'ref': 'refs/changes/50/638250/1' }} }}, 'owner': {'email': '*****@*****.**'}, } gerrit_cl = GerritCL(data, MockGerritAPI()) commit = gerrit_cl.fetch_current_revision_commit(host) self.assertEqual(commit.sha, '4de71d0ce799af441c1f106c5432c7fa7256be45') self.assertEqual(host.executive.calls, [ ['git', 'fetch', 'https://chromium.googlesource.com/chromium/src', 'refs/changes/50/638250/1'], ['git', 'rev-parse', 'FETCH_HEAD'], ['git', 'footers', '--position', '4de71d0ce799af441c1f106c5432c7fa7256be45'] ])
def test_empty_cl_is_not_exportable(self): data = { 'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb', 'subject': 'fake subject', '_number': 638250, 'owner': {'email': '*****@*****.**'}, } gerrit_cl = GerritCL(data, MockGerritAPI()) # It's important that this does not throw! self.assertFalse(gerrit_cl.is_exportable())
def test_url(self): data = { 'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb', '_number': 638250, } gerrit_cl = GerritCL(data, MockGerritAPI()) self.assertEqual(gerrit_cl.url, 'https://chromium-review.googlesource.com/638250')
def test_current_revision_description(self): data = { 'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb', 'subject': 'fake subject', '_number': 638250, 'current_revision': '1', 'revisions': { '1': {} }, 'owner': { 'email': '*****@*****.**' }, } gerrit_cl = GerritCL(data, MockGerritAPI()) self.assertEqual(gerrit_cl.current_revision_description, '') data['revisions']['1']['description'] = 'patchset 1' gerrit_cl = GerritCL(data, MockGerritAPI()) self.assertEqual(gerrit_cl.current_revision_description, 'patchset 1')
def test_wpt_cl_is_exportable(self): data = { 'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb', 'subject': 'fake subject', '_number': 638250, 'current_revision': '1', 'revisions': { '1': { 'commit_with_footers': 'fake subject', 'files': { RELATIVE_WEB_TESTS + 'external/wpt/foo/bar.html': '', } } }, 'owner': { 'email': '*****@*****.**' }, } gerrit_cl = GerritCL(data, MockGerritAPI()) self.assertTrue(gerrit_cl.is_exportable())
def test_no_wpt_cl_is_not_exportable(self): data = { 'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb', 'subject': 'fake subject', '_number': 638250, 'current_revision': '1', 'revisions': { '1': { 'commit_with_footers': 'fake subject', 'files': { 'third_party/WebKit/LayoutTests/foo/bar.html': '', } } }, 'owner': { 'email': '*****@*****.**' }, } gerrit_cl = GerritCL(data, MockGerritAPI()) self.assertFalse(gerrit_cl.is_exportable())