public function testCommenting() { $stubApi = $this->getStubApiForDefaultRemoteData(); $stubApi->expects($this->exactly(1))->method('review')->with($this->changeNum . ',1', null, 'See ya later')->will($this->returnValue(new ApiResult(array('rowCount' => 1), array()))); $this->registerDiesel('\\Bart\\Gerrit\\Api', $stubApi); $change = new Change($this->fakeChangeId); $change->comment('See ya later'); }
/** * Run the hook * @param Commit $commit Commit with Gerrit Change-Id * @throws GitHookException if requirement fails */ public function run(Commit $commit) { try { $changeId = $commit->gerritChangeId(); } catch (GitException $e) { $this->logger->warn("{$e->getMessage()}. Skipping commit."); throw new GitHookException("Couldn't get Change-Id for {$commit}", $e->getCode(), $e); } $change = new Change($changeId); try { if (!$change->exists()) { // This is not a warning, because some repositories do not require code review $this->logger->info('Skipping change b/c it does not exist in Gerrit'); return; } $change->abandon("Abandoning from git hook for commit {$commit}."); } catch (GerritException $e) { $this->logger->error("Problem abandoning Gerrit review {$changeId}", $e); throw new GitHookException("Problem abandoning Gerrit review {$changeId}", $e->getCode(), $e); } }
/** * Run the hook * @param Commit $commit Commit with Gerrit Change-Id * @throws GitHookException if requirement fails */ public function run(Commit $commit) { try { $changeId = $commit->gerritChangeId(); } catch (GitException $e) { $this->logger->warn("{$e->getMessage()}. Skipping commit."); throw new GitHookException("Couldn't get Change-Id for {$commit}", $e->getCode(), $e); } $change = new Change($changeId); try { if (!$change->exists()) { // This is not a warning, because some repositories do not require code review $this->logger->debug('Skipping change b/c it does not exist in Gerrit'); return; } $change->markMerged($commit->revision()); $change->comment("Git hook marking {$changeId} as merged by {$commit}"); } catch (GerritException $e) { $this->logger->error("Failed to mark Gerrit reivew {$changeId} as merged", $e); throw new GitHookException("Failed to mark Gerrit reivew {$changeId} as merged", $e->getCode(), $e); } }