Esempio n. 1
0
 public function testMarkMerged()
 {
     $stubApi = $this->getStubApiForDefaultRemoteData();
     $stubApi->expects($this->exactly(2))->method('gsql')->will($this->returnCallback(function ($gsql, array $params) {
         $apiResult = new ApiResult(array('rowCount' => 1), array());
         if (strstr($gsql, 'UPDATE changes')) {
             $this->assertCount(2, $params, 'UPDATE params');
             $this->assertEquals(2, $params[0], 'patch set count');
             $this->assertEquals($this->fakeChangeId, $params[1], 'change id');
             return $apiResult;
         } else {
             if (strstr($gsql, 'INSERT INTO')) {
                 $this->assertCount(4, $params, 'INSERT params');
                 $this->assertEquals($this->fakeMergedHash, $params[0]);
                 $this->assertEquals(9, $params[1]);
                 $this->assertEquals($this->changeNum, $params[2]);
                 $this->assertEquals(2, $params[3]);
                 return $apiResult;
             }
         }
         $this->fail('Unexpected GSQL sent to Api::gsql()  - ' . $gsql);
     }));
     $this->registerDiesel('\\Bart\\Gerrit\\Api', $stubApi);
     $change = new Change($this->fakeChangeId);
     $change->markMerged($this->fakeMergedHash);
 }
Esempio n. 2
0
 /**
  * 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);
     }
 }