示例#1
0
 /**
  * 提交任务
  *
  * @param $projectId
  * @return string
  */
 public function actionSubmit($projectId = null)
 {
     $task = new Task();
     if ($projectId) {
         // svn下无trunk
         $nonTrunk = false;
         $conf = Project::find()->where(['id' => $projectId, 'status' => Project::STATUS_VALID])->one();
         $conf = Project::getConf($projectId);
         // 第一次可能会因为更新而耗时,但一般不会,第一次初始化会是在检测里
         if ($conf->repo_type == Project::REPO_SVN && !file_exists(Project::getDeployFromDir())) {
             $version = Repo::getRevision($conf);
             $version->updateRepo();
         }
         // 为了简化svn无trunk, branches时,不需要做查看分支,直接就是主干
         $svnTrunk = sprintf('%s/trunk', Project::getDeployFromDir());
         // svn下无trunk目录
         if (!file_exists($svnTrunk)) {
             $nonTrunk = true;
         }
     }
     if (\Yii::$app->request->getIsPost()) {
         if (!$conf) {
             throw new \Exception(yii::t('task', 'unknown project'));
         }
         $group = Group::find()->where(['user_id' => $this->uid, 'project_id' => $projectId])->count();
         if (!$group) {
             throw new \Exception(yii::t('task', 'you are not the member of project'));
         }
         if ($task->load(\Yii::$app->request->post())) {
             // 是否需要审核
             $status = $conf->audit == Project::AUDIT_YES ? Task::STATUS_SUBMIT : Task::STATUS_PASS;
             $task->user_id = $this->uid;
             $task->project_id = $projectId;
             $task->status = $status;
             if ($task->save()) {
                 return $this->redirect('/task/');
             }
         }
     }
     if ($projectId) {
         $tpl = $conf->repo_type == Project::REPO_GIT ? 'submit-git' : 'submit-svn';
         return $this->render($tpl, ['task' => $task, 'conf' => $conf, 'nonTrunk' => $nonTrunk]);
     }
     // 成员所属项目
     $projects = Project::find()->leftJoin(Group::tableName(), '`group`.project_id=project.id')->where(['project.status' => Project::STATUS_VALID, '`group`.user_id' => $this->uid])->asArray()->all();
     return $this->render('select-project', ['projects' => $projects]);
 }
示例#2
0
 /**
  * ansible copy
  *
  * @return bool
  * @throws \Exception
  */
 private function _ansibleCopy()
 {
     $revision = Repo::getRevision($this->conf);
     $files = $revision->getCommandFiles($this->task);
     // 更新到指定版本
     $sTime = Command::getMs();
     $ret = $this->walleFolder->copyFiles($this->task->link_id, $files);
     $duration = Command::getMs() - $sTime;
     Record::saveRecord($this->walleFolder, $this->task->id, Record::ACTION_SYNC, $duration);
     if (!$ret) {
         throw new \Exception(yii::t('walle', 'rsync error'));
     }
     return true;
 }
示例#3
0
 /**
  * 更新代码文件
  *
  * @return bool
  * @throws \Exception
  */
 private function _gitUpdate()
 {
     // 更新代码文件
     $revision = Repo::getRevision($this->conf);
     $sTime = Command::getMs();
     $ret = $revision->updateToVersion($this->task);
     // 更新到指定版本
     // 记录执行时间
     $duration = Command::getMs() - $sTime;
     Record::saveRecord($revision, $this->task->id, Record::ACTION_CLONE, $duration);
     if (!$ret) {
         throw new \Exception('更新代码文件出错');
     }
     return true;
 }
示例#4
0
 public function getFiles($commitId = '', $parentDir = '')
 {
     $filesOnChange = [];
     if ($lastTask = Task::find()->where(['project_id' => $this->id, 'file_transmission_mode' => 1])->orderBy('id DESC')->one()) {
         $lastDeployCommitId = $lastTask->commit_id;
         $filesOnChange = Repo::getRevision($this)->getVersionDiff($lastDeployCommitId, $commitId);
     }
     array_walk($filesOnChange, function (&$item) {
         $item['selected'] = true;
     });
     /*
     $files = (new Folder($this))->getFiles($parentDir); 
     array_walk($files, function (&$item) {
        $item['selected'] = false;
     });
     
     $files = array_merge($files, $filesOnChange);
     */
     $files = $filesOnChange;
     $rootPath = $this->getDeployFromDir();
     foreach ($files as &$item) {
         $item['type'] = is_file($item['file']) ? 'f' : 'd';
         $item['file'] = str_replace($rootPath . '/', '', $item['file']);
     }
     return array_values($files);
 }