/** * Creates contribution review model. * * Returns model if successfully added. * * @param Project $project Project model to relate with model * @param BaseCommit $commit Contribution model to relate with model * @param ContributorInterface $contributor Contributor model * @param ContributorInterface $reviewer Reviewer model (null if set to default contributor reviewer) * * @return ContributionReview|null */ public function createContributionReview(Project $project, BaseCommit $commit, ContributorInterface $contributor, $reviewer = null) { $model = new ContributionReview(); $model->setAttributes(['commit_id' => $commit->getId(), 'project_id' => $project->id, 'date' => $commit->getDate()->format('Y-m-d H:i:s'), 'message' => $commit->message, 'contributor_name' => $commit->contributorName, 'contributor_email' => $commit->contributorEmail, 'repo_type' => $project->repo_type, 'contributor_id' => $contributor->getContributorId(), 'reviewer_id' => $reviewer instanceof ContributorInterface ? $reviewer->getContributorId() : $contributor->getDefaultViewerId()]); if ($model->save()) { return $model; } return null; }
/** * @inheritdoc */ public function init() { if (!$this->project instanceof Project) { throw new InvalidParamException('Project variable must be an instance of ' . Project::className()); } if (!$this->repository instanceof BaseRepository) { throw new InvalidParamException('Repository variable must be an instance of ' . BaseRepository::className()); } if (!$this->commit instanceof BaseCommit) { throw new InvalidParamException('Commit variable must be an instance of ' . BaseCommit::className()); } if (!$this->file instanceof File) { throw new InvalidParamException('File variable must be an instance of ' . File::className()); } $this->id = $this->commit->getId() . md5($this->file->getPathname()); }
/** * Prepare testing data and returns it * * @return array */ protected function prepareFixtures() { /* @var $contributor User */ $contributor = $this->getModule('Yii2')->grabFixture('users', 'activeUser1'); /* @var $reviewer User */ $reviewer = $this->getModule('Yii2')->grabFixture('users', 'activeUser2'); // authorized user model $authModel = new Auth(['identityClass' => User::className(), 'identity' => $reviewer]); /* @var $project Project */ $project = $this->getModule('Yii2')->grabFixture('projects', 'gitProject'); /* @var $history BaseCommit[] */ $history = $project->getRepositoryObject()->getHistory(1, 0); $this->assertNotEmpty($history); $commit = $history[0]; $this->assertInstanceOf(BaseCommit::className(), $commit); return [$contributor, $reviewer, $authModel, $project, $commit]; }
/** * Test get project contributions array from date * * @return BaseCommit First commit from generator */ public function testGetProjectContributions() { /* @var $project Project */ $project = $this->getModule('Yii2')->grabFixture('projects', 'gitProject'); $dateFrom = new DateTime(); $dateFrom->setDate(2016, 1, 1); $dateFrom->setTime(0, 0, 0); $this->assertNotEmpty($this->projectApi->getProjectContributions($project, $dateFrom)); $this->assertContainsOnly(BaseCommit::className(), $this->projectApi->getProjectContributions($project, $dateFrom)); // check if not less than date from $firstCommit = null; foreach ($this->projectApi->getProjectContributions($project, $dateFrom) as $commit) { $this->assertGreaterThan($dateFrom->getTimestamp(), $commit->getDate()->getTimestamp()); if (is_null($firstCommit)) { $firstCommit = $commit; } } return $firstCommit; }
/** * Prepare testing data and returns it * * @param string $fileStatus Status wich will be set for file * * @return array */ protected function prepareFixtures($fileStatus) { /* @var $project Project */ $project = $this->getModule('Yii2')->grabFixture('projects', 'gitProject'); /* @var $history BaseCommit[] */ $history = $project->getRepositoryObject()->getHistory(100, 0); $this->assertNotEmpty($history); // search commit and file $commit = null; $file = null; foreach ($history as $searchCommit) { $this->assertInstanceOf(BaseCommit::className(), $searchCommit); foreach ($searchCommit->getChangedFiles() as $searchFile) { $commit = $searchCommit; $file = new File($searchFile->getPath(), $project->getRepositoryObject(), $fileStatus); break; } } return [$project, $commit, $file]; }
/** * Push new commit to stack and check him level. * Used static var to check head levels commits. * * @staticvar array $headLevels * @param BaseCommit $commit */ public function pushCommit(BaseCommit $commit) { $this->commits[$commit->getId()] = $commit; $this->levels = max($commit->graphLevel, $this->levels); }