/** * Test get contributor by id */ public function testGetContributorById() { /* @var $user1 User */ $user1 = $this->getModule('Yii2')->grabFixture('users', 'activeUser1'); $contributor = $this->contributorApi->getContributorById($user1->id); $this->assertInstanceOf(ContributorInterface::class, $contributor); $this->assertEquals($contributor->getContributorId(), $user1->id); }
/** * 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; }