From ceb1fd45fba7e9966b8b343cea27b4540e7d6bd7 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 23 Nov 2016 10:40:15 +0800 Subject: [PATCH] * add api for integrate svn/git. --- module/git/control.php | 52 ++++++++++++++++++++++++++++++++++++++++++ module/git/model.php | 19 +++++++++++++++ module/svn/control.php | 12 ++++++++++ module/svn/model.php | 19 +++++++++++++++ 4 files changed, 102 insertions(+) diff --git a/module/git/control.php b/module/git/control.php index cdffbfc01d..44ea33760b 100644 --- a/module/git/control.php +++ b/module/git/control.php @@ -107,4 +107,56 @@ class git extends control exit; } } + + /** + * Ajax save log. + * + * @access public + * @return void + */ + public function ajaxSaveLog() + { + $repoUrl = trim($this->post->repoUrl); + $repoRoot = str_replace('\\', '/', trim($this->post->repoRoot)); + $message = trim($this->post->message); + $revision = trim($this->post->revision); + $files = $this->post->files; + + /* Ignore git. */ + if(strpos($repoUrl, '://') === false) die(); + + $parsedFiles = array(); + foreach($files as $file) + { + $file = trim($file); + if(empty($file)) continue; + $path = str_replace($repoRoot, '', $file); + $parsedFiles[''][] = $path; + } + + $objects = $this->git->parseComment($message); + if($objects) + { + $log = new stdclass(); + $log->author = $this->app->user->account; + $log->date = helper::now(); + $log->msg = $message; + $log->revision = $revision; + $log->files = $parsedFiles; + $this->git->saveAction2PMS($objects, $log, $repoUrl); + } + die(); + } + + /** + * Ajax get repos. + * + * @access public + * @return void + */ + public function ajaxGetRepos() + { + $repos = $this->git->getRepos(); + die(json_encode($repos)); + } } diff --git a/module/git/model.php b/module/git/model.php index 8ace7470df..2c414193ab 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -187,6 +187,25 @@ class gitModel extends model return true; } + /** + * Get repos. + * + * @access public + * @return array + */ + public function getRepos() + { + $repos = array(); + if(!$this->config->git->repos) return $repos; + + foreach($this->config->git->repos as $repo) + { + if(empty($repo['path'])) continue; + $repos[] = $repo['path']; + } + return $repos; + } + /** * Set repo. * diff --git a/module/svn/control.php b/module/svn/control.php index 364af0c1b4..a48918b238 100644 --- a/module/svn/control.php +++ b/module/svn/control.php @@ -135,4 +135,16 @@ class svn extends control } die(); } + + /** + * Ajax get repos. + * + * @access public + * @return void + */ + public function ajaxGetRepos() + { + $repos = $this->svn->getRepos(); + die(json_encode($repos)); + } } diff --git a/module/svn/model.php b/module/svn/model.php index e7aa3250d6..72f4509ca5 100644 --- a/module/svn/model.php +++ b/module/svn/model.php @@ -186,6 +186,25 @@ class svnModel extends model return true; } + /** + * Get repos. + * + * @access public + * @return array + */ + public function getRepos() + { + $repos = array(); + if(!$this->config->svn->repos) return $repos; + + foreach($this->config->svn->repos as $repo) + { + if(empty($repo['path'])) continue; + $repos[] = $repo['path']; + } + return $repos; + } + /** * Set repo. *