/* @var $repository BaseRepository */ /* @var $commit BaseCommit */ /* @var $reviewModel ContributionReview */ /* @var $contributorApi ContributorApi */ $contributorApi = Yii::$app->contributors; echo ProjectPanel::widget(['project' => $project]); ?> <h4><?php echo Html::encode($commit->message); ?> </h4> <div class="js-commit-panel"> <?php echo CommitPanel::widget(['reviewModel' => $reviewModel, 'authUser' => Yii::$app->user, 'contributor' => $reviewModel ? $reviewModel->contributor : $contributorApi->getContributor($project->repo_type, $commit->contributorName, $commit->contributorEmail), 'project' => $project, 'commit' => $commit, 'reviewButtonClass' => 'js-review-button']); ?> </div> <h5><?php echo Yii::t('project', 'Changed files'); ?> :</h5> <?php foreach ($commit->getChangedFiles() as $item) { print RevisionFile::widget(['repository' => $repository, 'project' => $project, 'commit' => $commit, 'file' => $item]); } // JavaScript page options $jsOptions = ['fileDetailsUrl' => Url::to(['file-view', 'id' => $project->getPrimaryKey(), 'commitId' => $commit->getId()]), 'fileContentSelector' => '.js-revision-file-content', 'fileLinkSelector' => '.js-revision-file', 'fileLinkActiveClass' => 'active', 'commitPanelSelector' => '.js-commit-panel', 'reviewButtonSelector' => '.js-review-button']; CommitSummaryAsset::register($this, $jsOptions);
/** * Test panel with finished review model * * @depends testWithReview */ public function testWithFinishedReview() { list($contributor, $reviewer, $authModel, $project, $commit) = $this->prepareFixtures(); $reviewModel = $this->projectModule->createContributionReview($project, $commit, $contributor, $reviewer); $this->assertInstanceOf(ContributionReview::className(), $reviewModel); $this->assertTrue($reviewModel->finishReview()); /* @var $contributor User */ /* @var $reviewer User */ /* @var $authModel Auth */ /* @var $project Project */ /* @var $commit BaseCommit */ $result = CommitPanel::widget(['project' => $project, 'commit' => $commit, 'contributor' => $contributor, 'authUser' => $authModel, 'reviewModel' => $reviewModel]); // contains review model but not contains finish review button $this->assertContains($reviewer->name, $result); $this->assertNotContains('did not complete a review', $result); $expectedString = '/projects/' . $project->id . '/' . $commit->getId() . '/finish-review'; $this->assertNotContains($expectedString, $result); $this->assertNotContains('Finish review', $result); // not contains to be a reviewer button $this->assertNotContains('(has no review)', $result); // has to be review button $expectedString = '/projects/' . $project->id . '/' . $commit->getId() . '/create-self-review'; $this->assertNotContains($expectedString, $result); $this->assertNotContains('To be a reviewer', $result); // contains finish review date $expectedString = 'at ' . $reviewModel->getReviewedDateTime()->format("d\\'M y H:i:s"); $this->assertContains($expectedString, $result); }
/** * To be reviewer * * @param integer $projectId Project identifier * @param string $commitId Commit identifier * * @return array */ public function actionCreateSelfReview($projectId, $commitId) { Yii::$app->response->format = Response::FORMAT_JSON; $project = $this->findProject($projectId); $commit = $this->findCommit($project, $commitId); $result = ['success' => false, 'html' => '', 'message' => '']; // find existent review model $model = ContributionReview::find()->andWhere(['project_id' => $project->id, 'commit_id' => $commit->getId()])->one(); if ($model && $model->reviewer_id == Yii::$app->user->getId()) { // user try to create existent model // it's not an error $result['success'] = true; } elseif ($model && is_null($model->reviewer_id)) { // model exists, but reviewer is not set $model->reviewer_id = Yii::$app->user->getId(); if ($model->save()) { $result['success'] = true; } } elseif ($model) { // other reviewer already installed $result['success'] = false; $result['message'] = Yii::t('project', 'Reviewer is already installed to this contribution'); } else { // model is not exists // create it $contributor = $this->contributorApi->getContributor($project->repo_type, $commit->contributorName, $commit->contributorEmail); $reviewer = $this->contributorApi->getContributorById(Yii::$app->user->getId()); $model = $this->projectApi->createContributionReview($project, $commit, $contributor, $reviewer); if (!$model instanceof ContributionReview) { $result['success'] = false; $result['message'] = Yii::t('project', 'An error occurred during the creation of the review'); } else { $result['success'] = true; } } if ($result['success'] && $model) { $result['html'] = CommitPanel::widget(['reviewModel' => $model, 'authUser' => Yii::$app->user, 'contributor' => $model->contributor, 'project' => $project, 'commit' => $commit, 'reviewButtonClass' => 'js-review-button']); } return $result; }