From 23de383c838f6d0f3c98304435bda43c7820749b Mon Sep 17 00:00:00 2001
From: liyuchun <563917701@qq.com>
Date: Mon, 11 Jul 2022 08:57:24 +0000
Subject: [PATCH 01/85] * Finish task #60452.
---
lib/scm/gitea.class.php | 837 +++++++++++++++++++++++++++++++
module/gitea/model.php | 36 ++
module/repo/config.php | 2 +
module/repo/control.php | 96 +++-
module/repo/js/create.js | 41 +-
module/repo/js/edit.js | 46 +-
module/repo/lang/de.php | 4 +
module/repo/lang/en.php | 4 +
module/repo/lang/fr.php | 4 +
module/repo/lang/vi.php | 9 +
module/repo/lang/zh-cn.php | 4 +
module/repo/lang/zh-tw.php | 4 +
module/repo/model.php | 88 ++--
module/repo/view/create.html.php | 20 +-
module/repo/view/edit.html.php | 20 +-
15 files changed, 1117 insertions(+), 98 deletions(-)
create mode 100644 lib/scm/gitea.class.php
diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php
new file mode 100644
index 0000000000..c0f5150779
--- /dev/null
+++ b/lib/scm/gitea.class.php
@@ -0,0 +1,837 @@
+client = $client;
+ $this->root = rtrim($root, '/') . '/';
+ $this->token = $password;
+ $this->branch = isset($_COOKIE['repoBranch']) ? $_COOKIE['repoBranch'] : 'HEAD';
+ }
+
+ /**
+ * List files.
+ *
+ * @param string $path
+ * @param string $revision
+ * @access public
+ * @return array
+ */
+ public function ls($path, $revision = 'HEAD')
+ {
+ if(!scm::checkRevision($revision)) return array();
+ $api = "tree";
+
+ $param = new stdclass();
+ $param->path = ltrim($path, '/');
+ $param->ref = $revision;
+ $param->recursive = 0;
+ if(!empty($this->branch)) $param->ref = $this->branch;
+
+ $list = $this->fetch($api, $param, true);
+ if(empty($list)) return array();
+
+ $infos = array();
+ foreach($list as $file)
+ {
+ if(!isset($file->type)) continue;
+
+ $info = new stdClass();
+ $info->name = $file->name;
+ $info->kind = $file->type == 'blob' ? 'file' : 'dir';
+
+ if($file->type == 'blob')
+ {
+ $file = $this->files($file->path, $this->branch);
+
+ $info->revision = zget($file, 'revision', '');
+ $info->comment = zget($file, 'comment', '');
+ $info->account = zget($file, 'committer', '');
+ $info->date = zget($file, 'date', '');
+ $info->size = zget($file, 'size', '');
+ }
+ else
+ {
+ $commits = $this->getCommitsByPath($file->path, '', '', 1);
+ if(empty($commits)) continue;
+ $commit = $commits[0];
+
+ $info->revision = $commit->id;
+ $info->comment = $commit->message;
+ $info->account = $commit->committer_name;
+ $info->date = date('Y-m-d H:i:s', strtotime($commit->committed_date));
+ $info->size = 0;
+ }
+
+ $infos[] = $info;
+ unset($info);
+ }
+
+ /* Sort by kind */
+ foreach($infos as $key => $info) $kinds[$key] = $info->kind;
+ if($infos) array_multisort($kinds, SORT_ASC, $infos);
+ return $infos;
+ }
+
+ /**
+ * Get files info.
+ *
+ * The API path requested is: "GET /projects/:id/repository/files/:file_path".
+ * Known issue of GitLab API: if a '%' in 'file_path', GitLab API will show a error 'file_path should be a valid file path'.
+ *
+ * @param string $path
+ * @param string $ref
+ * @access public
+ * @return object
+ * @doc https://docs.gitlab.com/ee/api/repository_files.html
+ */
+ public function files($path, $ref = 'master')
+ {
+ $path = urlencode($path);
+ $api = "files/$path";
+ $param = new stdclass();
+ $param->ref = $ref;
+ $file = $this->fetch($api, $param);
+ if(!isset($file->file_name)) return false;
+
+ $commits = $this->getCommitsByPath($path, '', '', 1);
+ $file->revision = $file->commit_id;
+ $file->size = $this->formatBytes($file->size);
+
+ if(!empty($commits))
+ {
+ $commit = $commits[0];
+ $file->revision = $commit->id;
+ $file->committer = $commit->committer_name;
+ $file->comment = $commit->message;
+ $file->date = date('Y-m-d H:i:s', strtotime($commit->committed_date));
+ }
+
+ return $file;
+ }
+
+ /**
+ * Get tags
+ *
+ * @param string $path
+ * @param string $revision
+ * @access public
+ * @return array
+ */
+ public function tags($path, $revision = 'HEAD')
+ {
+ $api = "tags";
+ $tags = array();
+
+ $params = array();
+ $params['per_page'] = '100';
+ $params['order_by'] = 'updated';
+ $params['sort'] = 'asc';
+ for($page = 1; true; $page ++)
+ {
+ $params['page'] = $page;
+ $list = $this->fetch($api, $params);
+ if(empty($list)) break;
+
+ foreach($list as $tag) $tags[] = $tag->name;
+ if(count($list) < $params['per_page']) break;
+ }
+
+ return $tags;
+ }
+
+ /**
+ * Get branches.
+ *
+ * @access public
+ * @return array
+ */
+ public function branch()
+ {
+ /* Max size of per_page in gitlab API is 100. */
+ $params = array();
+ $params['per_page'] = '100';
+
+ $branches = array();
+ $default = array();
+ for($page = 1; true; $page ++)
+ {
+ $params['page'] = $page;
+ $branchList = $this->fetch("branches", $params);
+ if(empty($branchList)) break;
+
+ foreach($branchList as $branch)
+ {
+ if(!isset($branch->name)) continue;
+ if($branch->default)
+ {
+ $default[$branch->name] = $branch->name;
+ }
+ else
+ {
+ $branches[$branch->name] = $branch->name;
+ }
+ }
+
+ /* Last page. */
+ if(count($branchList) < $params['per_page']) break;
+ }
+
+ if(empty($branches) and empty($default)) $branches['master'] = 'master';
+ asort($branches);
+
+ $branches = $default + $branches;
+ return $branches;
+ }
+
+ /**
+ * Get last log.
+ *
+ * @param string $path
+ * @param int $count
+ * @access public
+ * @return array
+ */
+ public function getLastLog($path, $count = 10)
+ {
+ return $this->log($path);
+ }
+
+ /**
+ * Get logs.
+ *
+ * @param string $path
+ * @param string $fromRevision
+ * @param string $toRevision
+ * @param int $count
+ * @access public
+ * @return array
+ */
+ public function log($path, $fromRevision = 0, $toRevision = 'HEAD', $count = 0)
+ {
+ if(!scm::checkRevision($fromRevision)) return array();
+ if(!scm::checkRevision($toRevision)) return array();
+
+ $path = ltrim($path, DIRECTORY_SEPARATOR);
+ $count = $count == 0 ? '' : "-n $count";
+
+ $list = $this->getCommitsByPath($path, $fromRevision, $toRevision);
+ foreach($list as $commit)
+ {
+ if(isset($commit->id)) $commit->diffs = $this->getFilesByCommit($commit->id);
+ }
+
+ return $this->parseLog($list);
+ }
+
+ /**
+ * Blame file
+ *
+ * @param string $path
+ * @param string $revision
+ * @access public
+ * @return array
+ */
+ public function blame($path, $revision)
+ {
+ if(!scm::checkRevision($revision)) return array();
+
+ $path = ltrim($path, DIRECTORY_SEPARATOR);
+ $path = urlencode($path);
+ $api = "files/$path/blame";
+ $param = new stdclass;
+ $param->ref = ($revision and $revision != 'HEAD') ? $revision : $this->branch;
+ $results = $this->fetch($api, $param);
+
+ $blames = array();
+ $revLine = 0;
+ $revision = '';
+
+ $lineNumber = 1;
+ foreach($results as $blame)
+ {
+ $line = array();
+ $line['revision'] = $blame->commit->id;
+ $line['committer'] = $blame->commit->committer_name;
+ $line['time'] = $blame->commit->committer_name;
+ $line['line'] = $lineNumber;
+ $line['lines'] = count($blame->lines);
+ $line['content'] = array_shift($blame->lines);
+
+ $blames[$lineNumber] = $line;
+
+ $lineNumber ++;
+
+ foreach($blame->lines as $line)
+ {
+ $blames[$lineNumber] = array('line' => $lineNumber, 'content' => $line);
+ $lineNumber ++;
+ }
+ }
+
+ return $blames;
+ }
+
+ /**
+ * Diff file.
+ *
+ * @param string $path
+ * @param string $fromRevision
+ * @param string $toRevision
+ * @param string $fromProject
+ * @param string $extra
+ * @access public
+ * @return array
+ */
+ public function diff($path, $fromRevision, $toRevision, $fromProject = '', $extra = '')
+ {
+ if(!scm::checkRevision($fromRevision) and $extra != 'isBranchOrTag') return array();
+ if(!scm::checkRevision($toRevision) and $extra != 'isBranchOrTag') return array();
+
+ $api = "compare";
+ $params = array('from' => $fromRevision, 'to' => $toRevision);
+ if($fromProject) $params['from_project_id'] = $fromProject;
+
+ if($toRevision == 'HEAD' and $this->branch) $params['to'] = $this->branch;
+ $results = $this->fetch($api, $params);
+ if(!isset($results->diffs)) return array();
+
+ foreach($results->diffs as $key => $diff)
+ {
+ if($path != '' and strpos($diff->new_path, $path) === false) unset($results->diffs[$key]);
+ }
+ $diffs = $results->diffs;
+ $lines = array();
+ foreach($diffs as $diff)
+ {
+ $lines[] = sprintf("diff --git a/%s b/%s", $diff->old_path, $diff->new_path);
+ $lines[] = sprintf("index %s ... %s %s ", $fromRevision, $toRevision, $diff->b_mode);
+ $lines[] = sprintf("--a/%s", $diff->old_path);
+ $lines[] = sprintf("--b/%s", $diff->new_path);
+ $diffLines = explode("\n", $diff->diff);
+ foreach($diffLines as $diffLine) $lines[] = $diffLine;
+ }
+ return $lines;
+ }
+
+ /**
+ * Cat file.
+ *
+ * @param string $entry
+ * @param string $revision
+ * @access public
+ * @return string
+ */
+ public function cat($entry, $revision = 'HEAD')
+ {
+ if(!scm::checkRevision($revision)) return false;
+ if($revision == 'HEAD' and $this->branch) $revision = $this->branch;
+ $file = $this->files($entry, $revision);
+ return base64_decode($file->content);
+ }
+
+ /**
+ * Get info.
+ *
+ * @param string $entry
+ * @param string $revision
+ * @access public
+ * @return object
+ */
+ public function info($entry, $revision = 'HEAD')
+ {
+ if(!scm::checkRevision($revision)) return false;
+
+ $info = new stdclass();
+ $info->kind = 'dir';
+ $info->path = $entry;
+ $info->revision = $revision;
+ $info->root = '';
+ if($revision == 'HEAD' and $this->branch) $info->revision = $this->branch;
+
+ if($entry)
+ {
+ $parent = dirname($entry);
+ if($parent == '.') $parent = '/';
+ if($parent == '') $parent = '/';
+ $list = $this->tree($parent, 0);
+ $file = new stdclass();
+
+ foreach($list as $node) if($node->path == $entry) $file = $node;
+
+ $commits = $this->getCommitsByPath($entry);
+
+ if(!empty($commits)) $file->revision = zget($commits[0], 'id', '');
+ $info->kind = (isset($file->type) and $file->type == 'tree') ? 'dir' : 'file';
+ }
+
+ return $info;
+ }
+
+ /**
+ * Exec git cmd.
+ *
+ * @param string $cmd
+ * @access public
+ * @todo Exec commands by gitlab api.
+ * @return array
+ */
+ public function exec($cmd)
+ {
+ return execCmd(escapeCmd("$this->client $cmd"), 'array');
+ }
+
+ /**
+ * Parse diff.
+ *
+ * @param array $lines
+ * @access public
+ * @return array
+ */
+ public function parseDiff($lines)
+ {
+ if(empty($lines)) return array();
+ $diffs = array();
+ $num = count($lines);
+ $endLine = end($lines);
+ if(strpos($endLine, '\ No newline at end of file') === 0) $num -= 1;
+
+ $newFile = false;
+ $allFiles = array();
+ for($i = 0; $i < $num; $i ++)
+ {
+ $diffFile = new stdclass();
+ if(strpos($lines[$i], "diff --git ") === 0)
+ {
+ $fileInfo = explode(' ',$lines[$i]);
+ $fileName = substr($fileInfo[2], strpos($fileInfo[2], '/') + 1);
+
+ /* Prevent duplicate display of files. */
+ if(in_array($fileName, $allFiles)) continue;
+ $allFiles[] = $fileName;
+
+ $diffFile->fileName = $fileName;
+ for($i++; $i < $num; $i ++)
+ {
+ $diff = new stdclass();
+ /* Fix bug #1757. */
+ if($lines[$i] == '+++ /dev/null') $newFile = true;
+ if(strpos($lines[$i], '+++', 0) !== false) continue;
+ if(strpos($lines[$i], '---', 0) !== false) continue;
+ if(strpos($lines[$i], '======', 0) !== false) continue;
+ if(preg_match('/^@@ -(\\d+)(,(\\d+))?\\s+\\+(\\d+)(,(\\d+))?\\s+@@/A', $lines[$i]))
+ {
+ $startLines = trim(str_replace(array('@', '+', '-'), '', $lines[$i]));
+ list($oldStartLine, $newStartLine) = explode(' ', $startLines);
+ list($diff->oldStartLine) = explode(',', $oldStartLine);
+ list($diff->newStartLine) = explode(',', $newStartLine);
+ $oldCurrentLine = $diff->oldStartLine;
+ $newCurrentLine = $diff->newStartLine;
+ if($newFile)
+ {
+ $oldCurrentLine = $diff->newStartLine;
+ $newCurrentLine = $diff->oldStartLine;
+ }
+ $newLines = array();
+ for($i++; $i < $num; $i ++)
+ {
+ if(preg_match('/^@@ -(\\d+)(,(\\d+))?\\s+\\+(\\d+)(,(\\d+))?\\s+@@/A', $lines[$i]))
+ {
+ $i --;
+ break;
+ }
+ if(strpos($lines[$i], "diff --git ") === 0) break;
+
+ $line = $lines[$i];
+ if(strpos($line, '\ No newline at end of file') === 0)continue;
+ $sign = empty($line) ? '' : $line[0];
+ if($sign == '-' and $newFile) $sign = '+';
+ $type = $sign != '-' ? $sign == '+' ? 'new' : 'all' : 'old';
+ if($sign == '-' || $sign == '+')
+ {
+ $line = substr_replace($line, ' ', 1, 0);
+ if($newFile) $line = preg_replace('/^\-/', '+', $line);
+ }
+
+ $newLine = new stdclass();
+ $newLine->type = $type;
+ $newLine->oldlc = $type != 'new' ? $oldCurrentLine : '';
+ $newLine->newlc = $type != 'old' ? $newCurrentLine : '';
+ $newLine->line = htmlSpecialString($line);
+
+ if($type != 'new') $oldCurrentLine++;
+ if($type != 'old') $newCurrentLine++;
+
+ $newLines[] = $newLine;
+ }
+
+ $diff->lines = $newLines;
+ $diffFile->contents[] = $diff;
+ }
+
+ if(isset($lines[$i]) and strpos($lines[$i], "diff --git ") === 0)
+ {
+ $i --;
+ $newFile = false;
+ break;
+ }
+ }
+ $diffs[] = $diffFile;
+ }
+ }
+ return $diffs;
+ }
+
+ /**
+ * Get commit count.
+ *
+ * @param int $commits
+ * @param string $lastVersion
+ * @access public
+ * @return int
+ */
+ public function getCommitCount($commits = 0, $lastVersion = '')
+ {
+ if(!scm::checkRevision($lastVersion)) return false;
+
+ chdir($this->root);
+ $revision = $this->branch ? $this->branch : 'HEAD';
+ return execCmd(escapeCmd("$this->client rev-list --count $revision -- ./"), 'string');
+ }
+
+ /**
+ * Get first revision.
+ *
+ * @access public
+ * @return string
+ */
+ public function getFirstRevision()
+ {
+ chdir($this->root);
+ $list = execCmd(escapeCmd("$this->client rev-list --reverse HEAD -- ./"), 'array');
+ return $list[0];
+ }
+
+ /**
+ * Get latest revision
+ *
+ * @access public
+ * @return string
+ */
+ public function getLatestRevision()
+ {
+ chdir($this->root);
+ $revision = $this->branch ? $this->branch : 'HEAD';
+ $list = execCmd(escapeCmd("$this->client rev-list -1 $revision -- ./"), 'array');
+ return $list[0];
+ }
+
+ /**
+ * Get commits.
+ *
+ * @param string $version
+ * @param int $count
+ * @param string $branch
+ * @access public
+ * @return array
+ */
+ public function getCommits($version = '', $count = 0, $branch = '')
+ {
+ if(!scm::checkRevision($version)) return array();
+ $api = "commits";
+ $commits = array();
+ $files = array();
+
+ if(empty($count)) $count = 10;
+
+ if(!empty($version) and $count == 1)
+ {
+ $api .= '/' . $version;
+ $commit = $this->fetch($api);
+ if(isset($commit->id))
+ {
+ $log = new stdclass;
+ $log->committer = $commit->committer_name;
+ $log->revision = $commit->id;
+ $log->comment = $commit->message;
+ $log->time = date('Y-m-d H:i:s', strtotime($commit->created_at));
+
+ $commits[$commit->id] = $log;
+ $files[$commit->id] = $this->getFilesByCommit($log->revision);
+
+ return array('commits' => $commits, 'files' => $files);
+ }
+ }
+
+ $params = array();
+ $params['ref_name'] = $branch;
+ $params['per_page'] = $count;
+ $params['all'] = 0;
+
+ if($version and $version != 'HEAD')
+ {
+ /* Get since param. */
+ if(substr($version, 0, 5) == 'since')
+ {
+ $since = true;
+ $version = substr($version, 5);
+ }
+
+ $committedDate = $this->getCommittedDate($version);
+ if(!$committedDate) return array('commits' => array(), 'files' => array());
+
+ if(!empty($since))
+ {
+ $params['since'] = $committedDate;
+ }
+ else
+ {
+ $params['until'] = $committedDate;
+ }
+ }
+
+ $list = $this->fetch($api, $params);
+
+ foreach($list as $commit)
+ {
+ if(!is_object($commit)) continue;
+
+ $log = new stdclass;
+ $log->committer = $commit->committer_name;
+ $log->revision = $commit->id;
+ $log->comment = $commit->message;
+ $log->time = date('Y-m-d H:i:s', strtotime($commit->created_at));
+
+ $commits[$commit->id] = $log;
+ $files[$commit->id] = $this->getFilesByCommit($log->revision);
+ }
+
+ return array('commits' => $commits, 'files' => $files);
+ }
+
+ /**
+ * getCommit
+ *
+ * @param int $sha
+ * @access public
+ * @return void
+ */
+ public function getCommittedDate($sha)
+ {
+ if(!scm::checkRevision($sha)) return null;
+ if(!$sha or $sha == 'HEAD') return date('c');
+
+ global $dao;
+ $time = $dao->select('time')->from(TABLE_REPOHISTORY)->where('revision')->eq($sha)->fetch('time');
+ if($time) return date('c', strtotime($time));
+
+ $result = $this->fetch("commits/$sha");
+ return (isset($result->committed_date)) ? $result->committed_date : false;
+ }
+
+ /**
+ * Get commits by path.
+ *
+ * @param string $path
+ * @param string $fromRevision
+ * @param string $toRevision
+ * @param int $perPage
+ * @access public
+ * @return array
+ */
+ public function getCommitsByPath($path, $fromRevision = '', $toRevision = '', $perPage = 0)
+ {
+ $path = ltrim($path, DIRECTORY_SEPARATOR);
+ $api = "commits";
+
+ $param = new stdclass();
+ $param->path = urldecode($path);
+ $param->ref_name = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch;
+
+ $fromDate = $this->getCommittedDate($fromRevision);
+ $toDate = $this->getCommittedDate($toRevision);
+
+ $since = '';
+ $until = '';
+ if($fromRevision and $toRevision)
+ {
+ $since = min($fromDate, $toDate);
+ $until = max($fromDate, $toDate);
+ }
+ elseif($fromRevision)
+ {
+ $since = $fromDate;
+ }
+ if($since) $param->since = $since;
+ if($until) $param->until = $until;
+
+ if($perPage) $param->per_page = $perPage;
+
+ return $this->fetch($api, $param);
+ }
+
+ /**
+ * Get files by commit.
+ *
+ * @param string $commit
+ * @access public
+ * @return void
+ */
+ public function getFilesByCommit($revision)
+ {
+ if(!scm::checkRevision($revision)) return array();
+ $api = "commits/{$revision}/diff";
+ $params = new stdclass;
+ $params->page = 1;
+ $params->per_page = 100;
+
+ $allResults = array();
+ while(true)
+ {
+ $results = $this->fetch($api, $params);
+ $params->page ++;
+ if(!is_array($results)) $results = array();
+ $allResults = $allResults + $results;
+ if(count($results) < 100) break;
+ }
+
+ $files = array();
+ foreach($allResults as $row)
+ {
+ $file = new stdclass();
+ $file->revision = $revision;
+ $file->path = '/' . $row->new_path;
+ $file->type = 'file';
+
+ $file->action = 'M';
+ if($row->new_file) $file->action = 'A';
+ if($row->renamed_file) $file->action = 'R';
+ if($row->deleted_file) $file->action = 'D';
+ $files[] = $file;
+ }
+
+ return $files;
+ }
+
+ /**
+ * Repository/tree api.
+ *
+ * @param string $path
+ * @param bool $recursive
+ * @access public
+ * @return mixed
+ */
+ public function tree($path, $recursive = 1)
+ {
+ $api = "tree";
+
+ $params = array();
+ $params['path'] = ltrim($path, '/');
+ $params['ref'] = $this->branch;
+ $params['recursive'] = (int) $recursive;
+ return $this->fetch($api, $params);
+ }
+
+ /**
+ * Fetch data from gitlab api.
+ *
+ * @param string $api
+ * @access public
+ * @return mixed
+ */
+ public function fetch($api, $params = array(), $needToLoop = false)
+ {
+ $params = (array) $params;
+ $params['private_token'] = $this->token;
+ $params['per_page'] = isset($params['per_page']) ? $params['per_page'] : 100;
+
+ $api = ltrim($api, '/');
+ $api = $this->root . $api . '?' . http_build_query($params);
+ if($needToLoop)
+ {
+ $allResults = array();
+ for($page = 1; true; $page++)
+ {
+ $results = json_decode(commonModel::http($api . "&page={$page}"));
+ if(!is_array($results)) break;
+ if(!empty($results)) $allResults = array_merge($allResults, $results);
+ if(count($results) < 100) break;
+ }
+
+ return $allResults;
+ }
+ else
+ {
+ $response = commonModel::http($api);
+ if(!empty(commonModel::$requestErrors))
+ {
+ commonModel::$requestErrors = array();
+ return array();
+ }
+
+ return json_decode($response);
+ }
+ }
+
+ /**
+ * Format bytes shown.
+ *
+ * @param int $size
+ * @static
+ * @access public
+ * @return string
+ */
+ public static function formatBytes($size)
+ {
+ if($size < 1024) return $size . 'Bytes';
+ if(round($size / (1024 * 1024), 2) > 1) return round($size / (1024 * 1024), 2) . 'G';
+ if(round($size / 1024, 2) > 1) return round($size / 1024, 2) . 'M';
+ return round($size, 2) . 'KB';
+ }
+
+ /**
+ * Parse log.
+ *
+ * @param array $logs
+ * @access public
+ * @return array
+ */
+ public function parseLog($logs)
+ {
+ $parsedLogs = array();
+ $i = 0;
+ foreach($logs as $commit)
+ {
+ if(!isset($commit->id)) continue;
+ $parsedLog = new stdclass();
+ $parsedLog->revision = $commit->id;
+ $parsedLog->committer = $commit->committer_name;
+ $parsedLog->time = date('Y-m-d H:i:s', strtotime($commit->committed_date));
+ $parsedLog->comment = $commit->message;
+ $parsedLog->change = array();
+ foreach($commit->diffs as $diff)
+ {
+ $parsedLog->change[$diff->path] = array();
+ $parsedLog->change[$diff->path]['action'] = $diff->action;
+ $parsedLog->change[$diff->path]['kind'] = $diff->type;
+ }
+ $parsedLogs[] = $parsedLog;
+ }
+
+ return $parsedLogs;
+ }
+}
diff --git a/module/gitea/model.php b/module/gitea/model.php
index 2f72de8403..f1fabf2ffe 100644
--- a/module/gitea/model.php
+++ b/module/gitea/model.php
@@ -224,4 +224,40 @@ class giteaModel extends model
->andWhere('account')->eq($account)
->fetchPairs('providerID');
}
+
+ /**
+ * Get project by api.
+ *
+ * @param int $giteaID
+ * @param int $projectID
+ * @access public
+ * @return void
+ */
+ public function apiGetSingleProject($giteaID, $projectID)
+ {
+ $apiRoot = $this->getApiRoot($giteaID);
+ if(!$apiRoot) return array();
+
+ $url = sprintf($apiRoot, "/repos/$projectID");
+ return json_decode(commonModel::http($url));
+ }
+
+ /**
+ * Get projects by api.
+ *
+ * @param int $giteaID
+ * @param bool $sudo
+ * @access public
+ * @return array
+ */
+ public function apiGetProjects($giteaID, $sudo = 'true')
+ {
+ $apiRoot = $this->getApiRoot($giteaID, $sudo);
+ if(!$apiRoot) return array();
+
+ $url = sprintf($apiRoot, "/repos/search");
+ $results = json_decode(commonModel::http($url));
+
+ return $results->data;
+ }
}
diff --git a/module/repo/config.php b/module/repo/config.php
index 3c258706c1..af7bfa2cd0 100644
--- a/module/repo/config.php
+++ b/module/repo/config.php
@@ -49,6 +49,8 @@ $config->repo->gitlab = new stdclass;
$config->repo->gitlab->perPage = 300;
$config->repo->gitlab->apiPath = "%s/api/v4/projects/%s/repository/";
+$config->repo->gitServiceList = array('gitlab', 'gitea');
+
$config->repo->rules['module']['task'] = 'Task';
$config->repo->rules['module']['bug'] = 'Bug';
$config->repo->rules['module']['story'] = 'Story';
diff --git a/module/repo/control.php b/module/repo/control.php
index ac03e050e7..b1bcb3be74 100644
--- a/module/repo/control.php
+++ b/module/repo/control.php
@@ -142,14 +142,14 @@ class repo extends control
$products = $this->loadModel('product')->getProductPairsByProject($objectID);
$productID = count($products) > 0 ? key($products) : '';
- $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create;
- $this->view->position[] = $this->lang->repo->create;
- $this->view->groups = $this->loadModel('group')->getPairs();
- $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
- $this->view->products = $products;
- $this->view->productID = $productID;
- $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs();
- $this->view->objectID = $objectID;
+ $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create;
+ $this->view->position[] = $this->lang->repo->create;
+ $this->view->groups = $this->loadModel('group')->getPairs();
+ $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
+ $this->view->products = $products;
+ $this->view->productID = $productID;
+ $this->view->serviceHosts = $this->loadModel('gitlab')->getPairs();
+ $this->view->objectID = $objectID;
$this->display();
}
@@ -182,25 +182,29 @@ class repo extends control
$this->app->loadLang('action');
- if(strtolower($repo->SCM) == 'gitlab')
+ $scm = strtolower($repo->SCM);
+ if(in_array($scm, $this->config->repo->gitServiceList))
{
- $gitlabID = isset($repo->gitlab) ? $repo->gitlab : 0;
- $projects = $this->loadModel('gitlab')->apiGetProjects($gitlabID);
- $options = array();
- foreach($projects as $project) $options[$project->id] = $project->name_with_namespace;
+ $serviceID = isset($repo->gitService) ? $repo->gitService : 0;
+ $projects = $this->loadModel($scm)->apiGetProjects($serviceID);
+ $options = array();
+ foreach($projects as $project)
+ {
+ if($scm == 'gitlab') $options[$project->id] = $project->name_with_namespace;
+ if($scm == 'gitea') $options[$project->full_name] = $project->full_name;
+ }
$this->view->projects = $options;
}
- $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->edit;
- $repo->repoType = $repo->id . '-' . $repo->SCM;
- $this->view->repo = $repo;
- $this->view->repoID = $repoID;
- $this->view->objectID = $objectID;
- $this->view->groups = $this->loadModel('group')->getPairs();
- $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
- $this->view->products = $objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs();
- $this->view->gitlabHosts = array('' => '') + $this->loadModel('gitlab')->getPairs();
+ $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->edit;
+ $this->view->repo = $repo;
+ $this->view->repoID = $repoID;
+ $this->view->objectID = $objectID;
+ $this->view->groups = $this->loadModel('group')->getPairs();
+ $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
+ $this->view->products = $objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs();
+ $this->view->serviceHosts = array('' => '') + $this->loadModel('pipeline')->getPairs($repo->SCM);
$this->view->position[] = html::a(inlink('maintain'), $this->lang->repo->common);
$this->view->position[] = $this->lang->repo->edit;
@@ -1165,6 +1169,54 @@ class repo extends control
$this->display();
}
+ /**
+ * Ajax get hosts.
+ *
+ * @param int $scm
+ * @access public
+ * @return void
+ */
+ public function ajaxGetHosts($scm)
+ {
+ $scm = strtolower($scm);
+ $hosts = $this->loadModel($scm)->getPairs();
+ return print(html::select('pipelineHost', $hosts, '', "class='form-control chosen'"));
+ }
+
+ /**
+ * Ajax get projects by server.
+ *
+ * @param int $serverID
+ * @access public
+ * @return void
+ */
+ public function ajaxGetProjects($serverID)
+ {
+ $server = $this->loadModel('pipeline')->getByID($serverID);
+ $getProjectFunc = 'ajaxGet' . $server->type . 'Projects';
+
+ $this->$getProjectFunc($serverID);
+ }
+
+ /**
+ * Ajax get gitea projects.
+ *
+ * @param string $gitlabID
+ * @param string $projectIdList
+ * @access public
+ * @return void
+ */
+ public function ajaxGetGiteaProjects($giteaID)
+ {
+ $projects = $this->loadModel('gitea')->apiGetProjects($giteaID);
+ if(!$projects) $this->send(array('message' => array()));
+
+ $options = "";
+ foreach($projects as $project) $options .= "";
+
+ return print($options);
+ }
+
/**
* Ajax get gitlab projects.
*
diff --git a/module/repo/js/create.js b/module/repo/js/create.js
index a5ad8b9a92..d6db74f6e3 100644
--- a/module/repo/js/create.js
+++ b/module/repo/js/create.js
@@ -23,28 +23,35 @@ $(function()
}
});
- $('#gitlabHost').change(function()
+ $('#serviceHost').change(function()
{
- host = $('#gitlabHost').val();
- url = createLink('repo', 'ajaxGetGitlabProjects', "host=" + host);
+ var host = $('#serviceHost').val();
+ var url = createLink('repo', 'ajaxGetProjects', "host=" + host);
if(host == '') return false;
$.get(url, function(response)
{
- $('#gitlabProject').html('').append(response);
- $('#gitlabProject').chosen().trigger("chosen:updated");;
+ $('#serviceProject').html('').append(response);
+ $('#serviceProject').chosen().trigger("chosen:updated");;
});
});
- $('#gitlabProject').change(function()
+ $('#serviceProject').change(function()
{
$option = $(this).find('option:selected');
$('#name').val($option.data('name'));
});
- $('#gitlabHost').change();
+ $('#serviceHost').change();
});
+/**
+ * Changed SCM.
+ *
+ * @param string $scm
+ * @access public
+ * @return void
+ */
function scmChanged(scm)
{
if(scm == 'Git')
@@ -62,6 +69,22 @@ function scmChanged(scm)
$('.tips-svn').removeClass('hidden');
}
- $('tr.gitlab').toggle(scm == 'Gitlab');
- $('tr.hide-gitlab').toggle(scm != 'Gitlab');
+ if(scm == 'Git' || scm == 'Subversion')
+ {
+ $('tr.service').toggle(false);
+ $('tr.hide-service').toggle(true);
+ }
+ else
+ {
+ $('tr.service').toggle(true);
+ $('tr.hide-service').toggle(false);
+
+ var url = createLink('repo', 'ajaxGetHosts', "scm=" + scm);
+ $.get(url, function(response)
+ {
+ $('#serviceHost').html(response);
+ $('#serviceHost').chosen().trigger("chosen:updated");;
+ $('#serviceHost').change();
+ });
+ }
}
diff --git a/module/repo/js/edit.js b/module/repo/js/edit.js
index 60505a9229..229f4907ab 100644
--- a/module/repo/js/edit.js
+++ b/module/repo/js/edit.js
@@ -1,26 +1,26 @@
$(function()
{
- scmChanged(scm);
+ scmChanged(scm, true);
$('#submit').mousedown(function()
{
$form = $(this).closest('form');
$form.css('min-height', $form.height());
})
- $('#gitlabHost').change(function()
+ $('#serviceHost').change(function()
{
- host = $('#gitlabHost').val();
+ host = $('#serviceHost').val();
if(host == '') return false;
- url = createLink('repo', 'ajaxGetGitlabProjects', "host=" + host);
+ url = createLink('repo', 'ajaxGetProjects', "host=" + host);
$.get(url, function(response)
{
- $('#gitlabProject').html('').append(response);
- $('#gitlabProject').chosen().trigger("chosen:updated");;
+ $('#serviceProject').html('').append(response);
+ $('#serviceProject').chosen().trigger("chosen:updated");;
});
});
- $('#gitlabProject').change(function()
+ $('#serviceProject').change(function()
{
$option = $(this).find('option:selected');
if(!$option.data('name')) return false;
@@ -29,7 +29,14 @@ $(function()
});
});
-function scmChanged(scm)
+/**
+ * Changed SCM.
+ *
+ * @param string $scm
+ * @access public
+ * @return void
+ */
+function scmChanged(scm, isFirstRequest = false)
{
if(scm == 'Git')
{
@@ -46,6 +53,25 @@ function scmChanged(scm)
$('.tips-svn').removeClass('hidden');
}
- $('tr.gitlab').toggle(scm == 'Gitlab');
- $('tr.hide-gitlab').toggle(scm != 'Gitlab');
+ if(scm == 'Git' || scm == 'Subversion')
+ {
+ $('tr.service').toggle(false);
+ $('tr.hide-service').toggle(true);
+ }
+ else
+ {
+ $('tr.service').toggle(true);
+ $('tr.hide-service').toggle(false);
+
+ if(!isFirstRequest)
+ {
+ var url = createLink('repo', 'ajaxGetHosts', "scm=" + scm);
+ $.get(url, function(response)
+ {
+ $('#serviceHost').html(response);
+ $('#serviceHost').chosen().trigger("chosen:updated");;
+ $('#serviceHost').change();
+ });
+ }
+ }
}
diff --git a/module/repo/lang/de.php b/module/repo/lang/de.php
index e17e9084cc..cffe5ebcfd 100644
--- a/module/repo/lang/de.php
+++ b/module/repo/lang/de.php
@@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8';
$lang->repo->encodingList['gbk'] = 'GBK';
$lang->repo->scmList['Gitlab'] = 'GitLab';
+$lang->repo->scmList['Gitea'] = 'Gitea';
$lang->repo->scmList['Git'] = 'Git';
$lang->repo->scmList['Subversion'] = 'SVN';
@@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Host';
$lang->repo->gitlabToken = 'GitLab Token';
$lang->repo->gitlabProject = 'Project';
+$lang->repo->serviceHost = 'Host';
+$lang->repo->serviceProject = 'Project';
+
$lang->repo->placeholder = new stdclass;
$lang->repo->placeholder->gitlabHost = 'Input url of gitlab';
diff --git a/module/repo/lang/en.php b/module/repo/lang/en.php
index 62ab96d159..725f3d2263 100644
--- a/module/repo/lang/en.php
+++ b/module/repo/lang/en.php
@@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8';
$lang->repo->encodingList['gbk'] = 'GBK';
$lang->repo->scmList['Gitlab'] = 'GitLab';
+$lang->repo->scmList['Gitea'] = 'Gitea';
$lang->repo->scmList['Git'] = 'Git';
$lang->repo->scmList['Subversion'] = 'SVN';
@@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Host';
$lang->repo->gitlabToken = 'GitLab Token';
$lang->repo->gitlabProject = 'Project';
+$lang->repo->serviceHost = 'Host';
+$lang->repo->serviceProject = 'Project';
+
$lang->repo->placeholder = new stdclass;
$lang->repo->placeholder->gitlabHost = 'Input url of gitlab';
diff --git a/module/repo/lang/fr.php b/module/repo/lang/fr.php
index 160d388e3f..22661b03db 100644
--- a/module/repo/lang/fr.php
+++ b/module/repo/lang/fr.php
@@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8';
$lang->repo->encodingList['gbk'] = 'GBK';
$lang->repo->scmList['Gitlab'] = 'GitLab';
+$lang->repo->scmList['Gitea'] = 'Gitea';
$lang->repo->scmList['Git'] = 'Git';
$lang->repo->scmList['Subversion'] = 'Subversion';
@@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Host';
$lang->repo->gitlabToken = 'GitLab Token';
$lang->repo->gitlabProject = 'Project';
+$lang->repo->serviceHost = 'Host';
+$lang->repo->serviceProject = 'Project';
+
$lang->repo->placeholder = new stdclass;
$lang->repo->placeholder->gitlabHost = 'Input url of gitlab';
diff --git a/module/repo/lang/vi.php b/module/repo/lang/vi.php
index 01a694336e..e84f6866e6 100644
--- a/module/repo/lang/vi.php
+++ b/module/repo/lang/vi.php
@@ -137,9 +137,18 @@ $lang->repo->logStyles['D'] = 'Xóa';
$lang->repo->encodingList['utf_8'] = 'UTF-8';
$lang->repo->encodingList['gbk'] = 'GBK';
+$lang->repo->scmList['Gitlab'] = 'GitLab';
+$lang->repo->scmList['Gitea'] = 'Gitea';
$lang->repo->scmList['Git'] = 'Git';
$lang->repo->scmList['Subversion'] = 'SVN';
+$lang->repo->gitlabHost = 'GitLab Host';
+$lang->repo->gitlabToken = 'GitLab Token';
+$lang->repo->gitlabProject = 'Project';
+
+$lang->repo->serviceHost = 'Host';
+$lang->repo->serviceProject = 'Project';
+
$lang->repo->notice = new stdclass();
$lang->repo->notice->syncing = 'Đang đồng bộ. Vui lòng đợi ...';
$lang->repo->notice->syncComplete = 'Synchronized. Now redirecting ...';
diff --git a/module/repo/lang/zh-cn.php b/module/repo/lang/zh-cn.php
index 964d445042..d9c12cd196 100644
--- a/module/repo/lang/zh-cn.php
+++ b/module/repo/lang/zh-cn.php
@@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8';
$lang->repo->encodingList['gbk'] = 'GBK';
$lang->repo->scmList['Gitlab'] = 'GitLab';
+$lang->repo->scmList['Gitea'] = 'Gitea';
$lang->repo->scmList['Git'] = '本地 Git';
$lang->repo->scmList['Subversion'] = 'Subversion';
@@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Server';
$lang->repo->gitlabToken = 'GitLab Token';
$lang->repo->gitlabProject = 'GitLab 项目';
+$lang->repo->serviceHost = '服务器';
+$lang->repo->serviceProject = '仓库';
+
$lang->repo->placeholder = new stdclass;
$lang->repo->placeholder->gitlabHost = '请填写GitLab访问地址';
diff --git a/module/repo/lang/zh-tw.php b/module/repo/lang/zh-tw.php
index 839ae5e4b0..9811b114f1 100644
--- a/module/repo/lang/zh-tw.php
+++ b/module/repo/lang/zh-tw.php
@@ -135,6 +135,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8';
$lang->repo->encodingList['gbk'] = 'GBK';
$lang->repo->scmList['Gitlab'] = 'GitLab';
+$lang->repo->scmList['Gitea'] = 'Gitea';
$lang->repo->scmList['Git'] = '本地 Git';
$lang->repo->scmList['Subversion'] = 'Subversion';
@@ -142,6 +143,9 @@ $lang->repo->gitlabHost = 'GitLab Server';
$lang->repo->gitlabToken = 'GitLab Token';
$lang->repo->gitlabProject = 'GitLab 項目';
+$lang->repo->serviceHost = '服务器';
+$lang->repo->serviceProject = '仓库';
+
$lang->repo->placeholder = new stdclass;
$lang->repo->placeholder->gitlabHost = '請填寫GitLab訪問地址';
diff --git a/module/repo/model.php b/module/repo/model.php
index d417ca9f3a..bdc537385e 100644
--- a/module/repo/model.php
+++ b/module/repo/model.php
@@ -137,7 +137,7 @@ class repoModel extends model
}
}
- if($repo->SCM == 'Gitlab') $repo = $this->processGitlab($repo);
+ if(in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) $repo = $this->processGitService($repo);
}
return $repos;
@@ -164,7 +164,7 @@ class repoModel extends model
if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password);
$repo->acl = json_decode($repo->acl);
if($type == 'haspriv' and !$this->checkPriv($repo)) unset($repos[$i]);
- if(strtolower($repo->SCM) == 'gitlab') $repo = $this->processGitlab($repo);
+ if(in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) $repo = $this->processGitService($repo);
}
return $repos;
@@ -181,19 +181,20 @@ class repoModel extends model
if(!$this->checkClient()) return false;
if(!$this->checkConnection()) return false;
- if($this->post->SCM == 'Gitlab')
+ $isPipelineServer = in_array(strtolower($this->post->SCM), $this->config->repo->gitServiceList) ? true : false;
+ if($isPipelineServer)
{
- if($this->post->gitlabHost == '') dao::$errors['gitlabHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabHost);
- if($this->post->gitlabProject == '') dao::$errors['gitlabProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabProject);
+ if($this->post->serviceHost == '') dao::$errors['serviceHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceHost);
+ if($this->post->serviceProject == '') dao::$errors['serviceProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceProject);
if(dao::isError()) return false;
}
$data = fixer::input('post')
- ->setIf($this->post->SCM == 'Gitlab', 'password', $this->post->gitlabToken)
- ->setIf($this->post->SCM == 'Gitlab', 'path', $this->post->gitlabProject)
- ->setIf($this->post->SCM == 'Gitlab', 'client', $this->post->gitlabHost)
- ->setIf($this->post->SCM == 'Gitlab', 'extra', $this->post->gitlabProject)
- ->setIf($this->post->SCM == 'Gitlab', 'prefix', '')
+ ->setIf($isPipelineServer, 'password', $this->post->serviceToken)
+ ->setIf($isPipelineServer, 'path', $this->post->serviceProject)
+ ->setIf($isPipelineServer, 'client', $this->post->serviceHost)
+ ->setIf($isPipelineServer, 'extra', $this->post->serviceProject)
+ ->setIf($isPipelineServer, 'prefix', '')
->setIf($this->post->SCM == 'Git', 'account', '')
->setIf($this->post->SCM == 'Git', 'password', '')
->skipSpecial('path,client,account,password')
@@ -208,7 +209,7 @@ class repoModel extends model
->andWhere('client')->eq($data->client)
->andWhere('path')->eq($data->path)
->fetch();
- if(!empty($repo)) dao::$errors['gitlabProject'] = sprintf($this->lang->error->unique, $this->lang->repo->gitlabProject, $repo->id);
+ if(!empty($repo)) dao::$errors['serviceProject'] = sprintf($this->lang->error->unique, $this->lang->repo->serviceProject, $repo->id);
if(dao::isError()) return false;
}
@@ -225,9 +226,9 @@ class repoModel extends model
}
if($data->encrypt == 'base64') $data->password = base64_encode($data->password);
- $this->dao->insert(TABLE_REPO)->data($data, $skip = 'gitlabHost,gitlabToken,gitlabProject')
+ $this->dao->insert(TABLE_REPO)->data($data, $skip = 'serviceHost,serviceToken,serviceProject')
->batchCheck($this->config->repo->create->requiredFields, 'notempty')
- ->checkIF($data->SCM == 'Gitlab', 'gitlabProject', 'notempty')
+ ->checkIF($isPipelineServer, 'serviceProject', 'notempty')
->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty')
->checkIF($data->SCM == 'Git', 'path', 'unique', "`SCM` = 'Git'")
->checkIF($data->SCM == 'Subversion', 'path', 'unique', "`SCM` = 'Subversion'")
@@ -261,17 +262,18 @@ class repoModel extends model
{
$repo = $this->getRepoByID($id);
- if($this->post->SCM == 'Gitlab')
+ $isPipelineServer = in_array(strtolower($this->post->SCM), $this->config->repo->gitServiceList) ? true : false;
+ if($isPipelineServer)
{
- if($this->post->gitlabHost == '') dao::$errors['gitlabHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabHost);
- if($this->post->gitlabProject == '') dao::$errors['gitlabProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabProject);
+ if($this->post->serviceHost == '') dao::$errors['serviceHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceHost);
+ if($this->post->serviceProject == '') dao::$errors['serviceProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceProject);
}
$data = fixer::input('post')
- ->setIf($this->post->SCM == 'Gitlab', 'password', $this->post->gitlabToken)
- ->setIf($this->post->SCM == 'Gitlab', 'path', $this->post->gitlabProject)
- ->setIf($this->post->SCM == 'Gitlab', 'client', $this->post->gitlabHost)
- ->setIf($this->post->SCM == 'Gitlab', 'extra', $this->post->gitlabProject)
+ ->setIf($isPipelineServer, 'password', $this->post->serviceToken)
+ ->setIf($isPipelineServer, 'path', $this->post->serviceProject)
+ ->setIf($isPipelineServer, 'client', $this->post->serviceHost)
+ ->setIf($isPipelineServer, 'extra', $this->post->serviceProject)
->setDefault('prefix', $repo->prefix)
->setIf($this->post->SCM == 'Gitlab', 'prefix', '')
->setDefault('client', 'svn')
@@ -306,7 +308,7 @@ class repoModel extends model
->andWhere('path')->eq($data->path)
->andWhere('id')->ne($id)
->fetch();
- if(!empty($repo)) dao::$errors['gitlabProject'] = sprintf($this->lang->error->unique, $this->lang->repo->gitlabProject, $repo->id);
+ if(!empty($repo)) dao::$errors['serviceProject'] = sprintf($this->lang->error->unique, $this->lang->repo->serviceProject, $repo->id);
if(dao::isError()) return false;
}
@@ -314,7 +316,7 @@ class repoModel extends model
if(!$this->checkConnection()) return false;
if($data->encrypt == 'base64') $data->password = base64_encode($data->password);
- $this->dao->update(TABLE_REPO)->data($data, $skip = 'gitlabHost,gitlabToken,gitlabProject')
+ $this->dao->update(TABLE_REPO)->data($data, $skip = 'serviceHost,serviceToken,serviceProject')
->batchCheck($this->config->repo->edit->requiredFields, 'notempty')
->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty')
->checkIF($data->SCM == 'Gitlab', 'extra', 'notempty')
@@ -415,10 +417,8 @@ class repoModel extends model
{
$repoPairs = $this->getRepoPairs($type, $projectID);
- $repos = array();
- $repos['Gitlab'] = array();
- $repos['SVN'] = array();
- $repos['Git'] = array();
+ $repos = array();
+ foreach($this->lang->repo->scmList as $scmType => $scm) $repos[$scmType] = array();
foreach($repoPairs as $id => $repo)
{
@@ -427,6 +427,11 @@ class repoModel extends model
$repo = str_replace('[gitlab]', '', $repo);
$repos['Gitlab'][$id] = $repo;
}
+ if(strpos($repo, '[gitea]') !== false)
+ {
+ $repo = str_replace('[gitea]', '', $repo);
+ $repos['Gitea'][$id] = $repo;
+ }
if(strpos($repo, '[svn]') !== false)
{
$repo = str_replace('[svn]', '', $repo);
@@ -454,7 +459,7 @@ class repoModel extends model
if(!$repo) return false;
if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password);
- if(strtolower($repo->SCM) == 'gitlab') $repo = $this->processGitlab($repo);
+ if(in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) $repo = $this->processGitService($repo);
$repo->acl = json_decode($repo->acl);
return $repo;
}
@@ -1273,7 +1278,7 @@ class repoModel extends model
*/
public function checkClient()
{
- if($this->post->SCM == 'Gitlab') return true;
+ if(in_array(strtolower($this->post->SCM), $this->config->repo->gitServiceList)) return true;
if(!$this->config->features->checkClient) return true;
if(!$this->post->client)
@@ -2015,21 +2020,21 @@ class repoModel extends model
}
/**
- * Process gitlab repo.
+ * Process git service repo.
*
* @param object $repo
* @access public
* @return object
*/
- public function processGitlab($repo)
+ public function processGitService($repo)
{
- $gitlab = $this->loadModel('gitlab')->getByID($repo->client); // The $repo->client is gitlabID.
+ $service = $this->loadModel('pipeline')->getByID($repo->client);
- $repo->gitlab = $gitlab ? $gitlab->id : 0;
- $repo->project = $gitlab ? $repo->path : ''; // The projectID in gitlab.
- $repo->path = $gitlab ? sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $repo->path) : '';
- $repo->client = $gitlab ? $gitlab->url : '';
- $repo->password = $gitlab ? $gitlab->token : '';
+ $repo->gitService = $service ? $service->id : 0;
+ $repo->project = $service ? $repo->path : ''; // The projectID in gitlab.
+ $repo->path = $service ? sprintf($this->config->repo->gitlab->apiPath, $service->url, $repo->path) : '';
+ $repo->client = $service ? $service->url : '';
+ $repo->password = $service ? $service->token : '';
return $repo;
}
@@ -2150,13 +2155,22 @@ class repoModel extends model
}
elseif($repo->SCM == 'Gitlab')
{
- $project = $this->loadModel('gitlab')->apiGetSingleProject($repo->gitlab, $repo->project);
+ $project = $this->loadModel('gitlab')->apiGetSingleProject($repo->gitService, $repo->project);
if(isset($project->id))
{
$url->http = $project->http_url_to_repo;
$url->ssh = $project->ssh_url_to_repo;
}
}
+ elseif($repo->SCM == 'Gitea')
+ {
+ $project = $this->loadModel('gitea')->apiGetSingleProject($repo->gitService, $repo->project);
+ if(isset($project->id))
+ {
+ $url->http = $project->clone_url;
+ $url->ssh = $project->ssh_url;
+ }
+ }
else
{
$this->scm = $this->app->loadClass('scm');
diff --git a/module/repo/view/create.html.php b/module/repo/view/create.html.php
index 0c7b890b18..ea5aa9a668 100644
--- a/module/repo/view/create.html.php
+++ b/module/repo/view/create.html.php
@@ -32,20 +32,20 @@
| repo->password;?> |
From 625631c62594e060a464dc24e362d22fa8371b7c Mon Sep 17 00:00:00 2001
From: liyuchun <563917701@qq.com>
Date: Mon, 11 Jul 2022 08:59:50 +0000
Subject: [PATCH 02/85] * Adjust scm.
---
lib/scm/gitea.class.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php
index c0f5150779..41b8285932 100644
--- a/lib/scm/gitea.class.php
+++ b/lib/scm/gitea.class.php
@@ -8,9 +8,9 @@ class gitea
* Construct
*
* @param string $client gitea api url.
- * @param string $root id of gitlab project.
+ * @param string $root id of gitea project.
* @param string $username null
- * @param string $password token of gitlab api.
+ * @param string $password token of gitea api.
* @param string $encoding
* @access public
* @return void
@@ -97,7 +97,7 @@ class gitea
* @param string $ref
* @access public
* @return object
- * @doc https://docs.gitlab.com/ee/api/repository_files.html
+ * @doc https://docs.gitea.com/ee/api/repository_files.html
*/
public function files($path, $ref = 'master')
{
@@ -162,7 +162,7 @@ class gitea
*/
public function branch()
{
- /* Max size of per_page in gitlab API is 100. */
+ /* Max size of per_page in gitea API is 100. */
$params = array();
$params['per_page'] = '100';
@@ -387,7 +387,7 @@ class gitea
*
* @param string $cmd
* @access public
- * @todo Exec commands by gitlab api.
+ * @todo Exec commands by gitea api.
* @return array
*/
public function exec($cmd)
@@ -747,7 +747,7 @@ class gitea
}
/**
- * Fetch data from gitlab api.
+ * Fetch data from gitea api.
*
* @param string $api
* @access public
From e5ffd04c34b14409199c6c720dff569d462f9548 Mon Sep 17 00:00:00 2001
From: caoyanyi
Date: Tue, 12 Jul 2022 09:45:31 +0800
Subject: [PATCH 03/85] * Finish task #60565,60566.
---
module/gitlab/control.php | 461 ++++---------------
module/gitlab/js/managebranchpriv.js | 72 +++
module/gitlab/js/managetagpriv.js | 72 +++
module/gitlab/lang/de.php | 9 +-
module/gitlab/lang/en.php | 9 +-
module/gitlab/lang/fr.php | 9 +-
module/gitlab/lang/vi.php | 9 +-
module/gitlab/lang/zh-cn.php | 9 +-
module/gitlab/model.php | 156 +++----
module/gitlab/view/browsebranchpriv.html.php | 81 ----
module/gitlab/view/browseproject.html.php | 4 +-
module/gitlab/view/browsetagpriv.html.php | 82 ----
module/gitlab/view/createbranchpriv.html.php | 47 --
module/gitlab/view/createtagpriv.html.php | 43 --
module/gitlab/view/edittagpriv.html.php | 44 --
module/gitlab/view/managebranchpriv.html.php | 82 ++++
module/gitlab/view/managetagpriv.html.php | 76 +++
module/group/lang/resource.php | 18 +-
18 files changed, 485 insertions(+), 798 deletions(-)
create mode 100644 module/gitlab/js/managebranchpriv.js
create mode 100644 module/gitlab/js/managetagpriv.js
delete mode 100644 module/gitlab/view/browsebranchpriv.html.php
delete mode 100644 module/gitlab/view/browsetagpriv.html.php
delete mode 100644 module/gitlab/view/createbranchpriv.html.php
delete mode 100644 module/gitlab/view/createtagpriv.html.php
delete mode 100644 module/gitlab/view/edittagpriv.html.php
create mode 100644 module/gitlab/view/managebranchpriv.html.php
create mode 100644 module/gitlab/view/managetagpriv.html.php
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index 5c8074064a..0f3d774d41 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -911,176 +911,6 @@ class gitlab extends control
$this->display();
}
- /**
- * Browse gitlab protect branch.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $orderBy
- * @param int $recTotal
- * @param int $recPerPage
- * @param int $pageID
- * @access public
- * @return void
- */
- public function browseBranchPriv($gitlabID, $projectID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1)
- {
- $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
-
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
- if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
- }
-
- $keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
- $branches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, $keyword, $orderBy);
-
- /* Pager. */
- $this->app->loadClass('pager', $static = true);
- $recTotal = count($branches);
- $pager = new pager($recTotal, $recPerPage, $pageID);
- $branchList = array_chunk($branches, $pager->recPerPage);
-
- $this->view->keyword = $keyword;
- $this->view->pager = $pager;
- $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseBranchPriv;
- $this->view->levelLang = $this->lang->gitlab->branch->branchCreationLevelList;
- $this->view->gitlabID = $gitlabID;
- $this->view->projectID = $projectID;
- $this->view->project = $project;
- $this->view->orderBy = $orderBy;
- $this->view->branchList = empty($branchList) ? $branchList: $branchList[$pageID - 1];
- $this->display();
- }
-
- /**
- * Set a gitlab protect branch.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $branch
- * @access public
- * @return void
- */
- public function createBranchPriv($gitlabID, $projectID, $branch = '')
- {
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
-
- $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
- if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
- }
-
- /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/
- if($branch) $branch = urldecode(helper::safe64Decode($branch));
-
- if($_POST)
- {
- $this->gitlab->createBranchPriv($gitlabID, $projectID, $branch);
-
- if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
- return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseBranchPriv', "gitlabID=$gitlabID&projectID=$projectID")));
- }
-
- $branchPriv = new stdClass();
- $branchPriv->name = '';
- $branchPriv->mergeAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default.
- $branchPriv->pushAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default.
-
- $title = $this->lang->gitlab->createBranchPriv;
-
- if($branch)
- {
- $title = $this->lang->gitlab->editBranchPriv;
- $branchPriv = $this->gitlab->apiGetSingleBranchPriv($gitlabID, $projectID, $branch);
- $branchPriv->name = helper::safe64Encode(urlencode($branchPriv->name));
- $branchPriv->mergeAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->merge_access_levels);
- $branchPriv->pushAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->push_access_levels);
- }
-
- $gitlabBranches = $this->gitlab->apiGetBranches($gitlabID, $projectID);
- $protectBranches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, '', 'name_asc');
- $protectNames = array_keys($protectBranches);
-
- $branches = array();
- foreach($gitlabBranches as $oneBranch)
- {
- if(!in_array($oneBranch->name, $protectNames) || $oneBranch->name == $branch)
- {
- $branchName = helper::safe64Encode(urlencode($oneBranch->name));
- $branches[$branchName] = $oneBranch->name;
- }
- }
-
- $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $title;
- $this->view->pageTitle = $title;
- $this->view->gitlabID = $gitlabID;
- $this->view->branch = $branch;
- $this->view->projectID = $projectID;
- $this->view->branches = $branches;
- $this->view->branchPriv = $branchPriv;
- $this->display();
- }
-
- /**
- * Edit a gitlab branch protect.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $branch
- * @access public
- * @return void
- */
- public function editBranchPriv($gitlabID, $projectID, $branch)
- {
- echo $this->fetch('gitlab', 'createBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch");
- }
-
- /**
- * Delete a gitlab protect branch.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $branch
- * @param string $confirm
- * @access public
- * @return void
- */
- public function deleteBranchPriv($gitlabID, $projectID, $branch, $confirm = 'no')
- {
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
-
- $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
- if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
- }
-
- if($confirm != 'yes')
- {
- $branch = urlencode($branch);
- return print(js::confirm($this->lang->gitlab->branch->confirmDelete , inlink('deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch&confirm=yes")));
- }
-
- /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/
- $branch = urldecode(helper::safe64Decode($branch));
- $reponse = $this->gitlab->apiDeleteBranchPriv($gitlabID, $projectID, $branch);
-
- /* If the status code beginning with 20 is returned or empty is returned, it is successful. */
- if(!$reponse or substr($reponse->message, 0, 2) == '20')
- {
- $this->loadModel('action')->create('gitlabbranchPriv', $branch, 'deleted', '', $branch);
- return print(js::reload('parent'));
- }
-
- echo js::alert($reponse->message);
- }
-
/**
* Browse gitlab tag.
*
@@ -1135,206 +965,6 @@ class gitlab extends control
$this->display();
}
- /**
- * Browse gitlab protect tag.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $orderBy
- * @param int $recTotal
- * @param int $recPerPage
- * @param int $pageID
- * @access public
- * @return void
- */
- public function browseTagPriv($gitlabID, $projectID, $orderBy = 'name_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
- {
- $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
-
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
-
- if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
- }
-
- $this->session->set('gitlabTagPrivList', $this->app->getURI(true));
- $keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
-
- $gitlabTags = array();
- $allTags = $this->gitlab->apiGetTags($gitlabID, $projectID);
- foreach($allTags as $tag)
- {
- $gitlabTags[$tag->name] = $tag;
- }
-
- $tagList = array();
- $gitlabProtectTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID);
- foreach($gitlabProtectTags as $gitlabProtectTag)
- {
- $tag = new stdClass();
- $tag->name = $gitlabProtectTag->name;
- $tag->lastCommitter = isset($gitlabTags[$tag->name]) ? $gitlabTags[$tag->name]->commit->committer_name : '';
- $tag->accessLevels = $gitlabProtectTag->create_access_levels;
-
- $tagList[] = $tag;
- }
-
- /* Data search. */
- if($keyword)
- {
- foreach($tagList as $key => $tag)
- {
- if(strpos($tag->name, $keyword) === false) unset($tagList[$key]);
- }
- $tagList = array_values($tagList);
- }
-
- /* Data sort. */
- list($order, $sort) = explode('_', $orderBy);
- $orderList = array();
- foreach($tagList as $tag) $orderList[] = $tag->$order;
- array_multisort($orderList, $sort == 'desc' ? SORT_DESC : SORT_ASC, $tagList);
-
- /* Pager. */
- $this->app->loadClass('pager', $static = true);
- $recTotal = count($tagList);
- $pager = new pager($recTotal, $recPerPage, $pageID);
- $tagList = array_chunk($tagList, $pager->recPerPage);
-
- $this->view->gitlab = $this->gitlab->getByID($gitlabID);
- $this->view->pager = $pager;
- $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv;
- $this->view->gitlabID = $gitlabID;
- $this->view->projectID = $projectID;
- $this->view->keyword = $keyword;
- $this->view->project = $project;
- $this->view->gitlabTagList = empty($tagList) ? $tagList: $tagList[$pageID - 1];
- $this->view->orderBy = $orderBy;
- $this->display();
- }
-
- /**
- * Set a gitlab protect tag.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @access public
- * @return void
- */
- public function createTagPriv($gitlabID, $projectID)
- {
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
-
- $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
- if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
- }
-
- if($_POST)
- {
- $this->gitlab->createTagPriv($gitlabID, $projectID);
-
- if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
- return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID")));
- }
-
- $gitlabTags = $this->gitlab->apiGetTags($gitlabID, $projectID);
- $protectTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID, '', 'name_asc');
- $protectNames = array_keys($protectTags);
-
- $tags = array();
- foreach($gitlabTags as $tag)
- {
- if(!in_array($tag->name, $protectNames)) $tags[$tag->name] = $tag->name;
- }
-
- $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->createTagPriv;
- $this->view->gitlabID = $gitlabID;
- $this->view->projectID = $projectID;
- $this->view->tags = $tags;
- $this->display();
- }
-
- /**
- * Edit a gitlab protect tag.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $tag
- * @access public
- * @return void
- */
- public function editTagPriv($gitlabID, $projectID, $tag = '')
- {
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
-
- $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
- if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
- }
-
- /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/
- $tag = urldecode(helper::safe64Decode($tag));
-
- if($_POST)
- {
- $this->gitlab->createTagPriv($gitlabID, $projectID, $tag);
-
- if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
- return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID")));
- }
-
- $tagPriv = $this->gitlab->apiGetSingleTagPriv($gitlabID, $projectID, $tag);
- $tagPriv->createAccessLevel = $this->gitlab->checkAccessLevel($tagPriv->create_access_levels);
-
- $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->editTagPriv;
- $this->view->gitlabID = $gitlabID;
- $this->view->projectID = $projectID;
- $this->view->tagPriv = $tagPriv;
- $this->view->tag = $tag;
- $this->display();
- }
-
- /**
- * Delete a gitlab protect tag.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $tag
- * @access public
- * @return void
- */
- public function deleteTagPriv($gitlabID, $projectID, $tag)
- {
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
-
- $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
- if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
- }
-
- /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/
- $tag = urldecode(helper::safe64Decode($tag));
- $reponse = $this->gitlab->apiDeleteTagPriv($gitlabID, $projectID, $tag);
-
- /* If the status code beginning with 20 is returned or empty is returned, it is successful. */
- if(!$reponse or substr($reponse->message, 0, 2) == '20')
- {
- $this->loadModel('action')->create('gitlabtagpriv', 0, 'deleted', '', $tag);
- return print(js::reload('parent'));
- }
-
- echo js::alert($reponse->message);
- }
-
/**
* Import gitlab issue to zentaopms.
*
@@ -1746,4 +1376,95 @@ class gitlab extends control
echo js::alert($reponse->message);
}
+
+ /**
+ * Manage a gitlab branch protected.
+ *
+ * @param int $repoID
+ * @param int $projectID
+ * @access public
+ * @return void
+ */
+ public function manageBranchPriv($gitlabID, $projectID)
+ {
+ if(!$this->app->user->admin)
+ {
+ $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
+ if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
+ if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
+ }
+
+ $hasAccessBranches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, '', 'name_asc');
+ foreach($hasAccessBranches as $branch)
+ {
+ $branch->pushAccess = $this->gitlab->checkAccessLevel($branch->push_access_levels);
+ $branch->mergeAccess = $this->gitlab->checkAccessLevel($branch->merge_access_levels);
+ }
+
+ if(!empty($_POST))
+ {
+ $result = $this->gitlab->manageBranchPrivs($gitlabID, $projectID, $hasAccessBranches);
+ if(!empty($result)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->gitlab->svaeFailed, implode(', ', $result))));
+
+ return $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'locate' => inlink('browseProject', "gitlabID=$gitlabID")));
+ }
+ $allBranches = $this->gitlab->apiGetBranches($gitlabID, $projectID);
+ $noAccessBranches = array();
+ foreach($allBranches as $branch)
+ {
+ if(!isset($hasAccessBranches[$branch->name])) $noAccessBranches[$branch->name] = $branch->name;
+ }
+
+ $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseBranchPriv;
+ $this->view->gitlabID = $gitlabID;
+ $this->view->projectID = $projectID;
+ $this->view->hasAccessBranches = $hasAccessBranches;
+ $this->view->noAccessBranches = $noAccessBranches;
+ $this->display();
+ }
+
+ /**
+ * Manage a gitlab tag protected.
+ *
+ * @param int $repoID
+ * @param int $projectID
+ * @access public
+ * @return void
+ */
+ public function manageTagPriv($gitlabID, $projectID)
+ {
+ if(!$this->app->user->admin)
+ {
+ $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
+ if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
+ if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
+ }
+
+ $hasAccessTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID, '', 'name_asc');
+ foreach($hasAccessTags as $tag)
+ {
+ $tag->createAccess = $this->gitlab->checkAccessLevel($tag->create_access_levels);
+ }
+
+ if(!empty($_POST))
+ {
+ $result = $this->gitlab->manageTagPrivs($gitlabID, $projectID, $hasAccessTags);
+ if(!empty($result)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->gitlab->svaeFailed, implode(', ', $result))));
+
+ return $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'locate' => inlink('browseProject', "gitlabID=$gitlabID")));
+ }
+ $allTags = $this->gitlab->apiGetTags($gitlabID, $projectID);
+ $noAccessTags = array();
+ foreach($allTags as $tag)
+ {
+ if(!isset($hasAccessTags[$tag->name])) $noAccessTags[$tag->name] = $tag->name;
+ }
+
+ $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv;
+ $this->view->gitlabID = $gitlabID;
+ $this->view->projectID = $projectID;
+ $this->view->hasAccessTags = $hasAccessTags;
+ $this->view->noAccessTags = $noAccessTags;
+ $this->display();
+ }
}
diff --git a/module/gitlab/js/managebranchpriv.js b/module/gitlab/js/managebranchpriv.js
new file mode 100644
index 0000000000..ca2a04c27b
--- /dev/null
+++ b/module/gitlab/js/managebranchpriv.js
@@ -0,0 +1,72 @@
+/* Update other picker on change */
+$.zui.Picker.DEFAULTS.onChange = function(event)
+{
+ var picker = event.picker;
+ if(!picker.$formItem.is('[name^=branches]')) return;
+
+ var select = picker.$formItem[0];
+ var newItem = event.value.length ? $.extend({}, picker.getListItem(event.value), {disabled: true}) : $.extend({}, picker.getListItem(event.oldValue), {disabled: false});
+
+ $('.user-picker[name^=branches]').each(function()
+ {
+ if(this === select) return;
+
+ var $select = $(this);
+ var selectPicker = $select.data('zui.picker');
+
+ if(selectPicker) selectPicker.updateOptionList([$.extend({}, newItem)]);
+ });
+}
+
+/**
+ * Save team members.
+ *
+ * @access public
+ * @return void
+ */
+function savePriv()
+{
+ $('#saveBtn').addClass('hidden');
+ $('#submit').removeClass('hidden');
+ $('#submit').click();
+}
+
+/**
+ * Add item.
+ *
+ * @param object $obj
+ * @access public
+ * @return void
+ */
+function addItem(obj)
+{
+ var item = $('#addItem').html().replace(/%i%/g, itemIndex);
+ var $tr = $('' + item + ' ').insertAfter($(obj).closest('tr'));
+ var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
+ itemIndex++;
+
+ var disabledItems = [];
+ $('.user-picker[name^=branches]').each(function()
+ {
+ if(this === $accounts[0]) return;
+ var $select = $(this);
+ var picker = $select.data('zui.picker');
+ if(!picker) return;
+ var selectItem = picker.getListItem(picker.getValue());
+ if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true}));
+ });
+ if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems);
+}
+
+/**
+ * Delete item.
+ *
+ * @param object $obj
+ * @access public
+ * @return void
+ */
+function deleteItem(obj)
+{
+ if($('#teamForm .table-form tbody').children().length < 2) return false;
+ $(obj).closest('tr').remove();
+}
diff --git a/module/gitlab/js/managetagpriv.js b/module/gitlab/js/managetagpriv.js
new file mode 100644
index 0000000000..6e290efb1f
--- /dev/null
+++ b/module/gitlab/js/managetagpriv.js
@@ -0,0 +1,72 @@
+/* Update other picker on change */
+$.zui.Picker.DEFAULTS.onChange = function(event)
+{
+ var picker = event.picker;
+ if(!picker.$formItem.is('[name^=tags]')) return;
+
+ var select = picker.$formItem[0];
+ var newItem = event.value.length ? $.extend({}, picker.getListItem(event.value), {disabled: true}) : $.extend({}, picker.getListItem(event.oldValue), {disabled: false});
+
+ $('.user-picker[name^=tags]').each(function()
+ {
+ if(this === select) return;
+
+ var $select = $(this);
+ var selectPicker = $select.data('zui.picker');
+
+ if(selectPicker) selectPicker.updateOptionList([$.extend({}, newItem)]);
+ });
+}
+
+/**
+ * Save team members.
+ *
+ * @access public
+ * @return void
+ */
+function savePriv()
+{
+ $('#saveBtn').addClass('hidden');
+ $('#submit').removeClass('hidden');
+ $('#submit').click();
+}
+
+/**
+ * Add item.
+ *
+ * @param object $obj
+ * @access public
+ * @return void
+ */
+function addItem(obj)
+{
+ var item = $('#addItem').html().replace(/%i%/g, itemIndex);
+ var $tr = $('' + item + ' ').insertAfter($(obj).closest('tr'));
+ var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
+ itemIndex++;
+
+ var disabledItems = [];
+ $('.user-picker[name^=tags]').each(function()
+ {
+ if(this === $accounts[0]) return;
+ var $select = $(this);
+ var picker = $select.data('zui.picker');
+ if(!picker) return;
+ var selectItem = picker.getListItem(picker.getValue());
+ if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true}));
+ });
+ if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems);
+}
+
+/**
+ * Delete item.
+ *
+ * @param object $obj
+ * @access public
+ * @return void
+ */
+function deleteItem(obj)
+{
+ if($('#teamForm .table-form tbody').children().length < 2) return false;
+ $(obj).closest('tr').remove();
+}
diff --git a/module/gitlab/lang/de.php b/module/gitlab/lang/de.php
index 169875c665..41d82d8582 100644
--- a/module/gitlab/lang/de.php
+++ b/module/gitlab/lang/de.php
@@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User";
$lang->gitlab->browseGroup = "Group";
$lang->gitlab->browseBranch = "GitLab Branch List";
$lang->gitlab->browseTag = "GitLab Tag List";
-$lang->gitlab->browseTagPriv = "GitLab Tag protected List";
+$lang->gitlab->browseTagPriv = "Protected tag";
$lang->gitlab->gitlabIssue = "GitLab Issue";
$lang->gitlab->zentaoProduct = 'Zentao Product';
$lang->gitlab->objectType = 'Type'; // task, bug, story
@@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch';
$lang->gitlab->manageGroupMembers = 'Manage group member';
$lang->gitlab->createWebhook = 'Create Webhook';
$lang->gitlab->browseBranchPriv = 'Protect branch';
-$lang->gitlab->createBranchPriv = 'Cerate branch protected';
-$lang->gitlab->editBranchPriv = 'Edit branch protected';
-$lang->gitlab->deleteBranchPriv = 'Delete branch protected';
$lang->gitlab->createTag = 'Create Tag';
$lang->gitlab->deleteTag = 'Delete tag';
-$lang->gitlab->createTagPriv = 'Create tag protected';
-$lang->gitlab->editTagPriv = 'Edit tag protected';
-$lang->gitlab->deleteTagPriv = 'Delete tag protected';
+$lang->gitlab->svaeFailed = '『%s』save failed';
$lang->gitlab->id = 'ID';
$lang->gitlab->name = "Server Name";
diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php
index 169875c665..41d82d8582 100644
--- a/module/gitlab/lang/en.php
+++ b/module/gitlab/lang/en.php
@@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User";
$lang->gitlab->browseGroup = "Group";
$lang->gitlab->browseBranch = "GitLab Branch List";
$lang->gitlab->browseTag = "GitLab Tag List";
-$lang->gitlab->browseTagPriv = "GitLab Tag protected List";
+$lang->gitlab->browseTagPriv = "Protected tag";
$lang->gitlab->gitlabIssue = "GitLab Issue";
$lang->gitlab->zentaoProduct = 'Zentao Product';
$lang->gitlab->objectType = 'Type'; // task, bug, story
@@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch';
$lang->gitlab->manageGroupMembers = 'Manage group member';
$lang->gitlab->createWebhook = 'Create Webhook';
$lang->gitlab->browseBranchPriv = 'Protect branch';
-$lang->gitlab->createBranchPriv = 'Cerate branch protected';
-$lang->gitlab->editBranchPriv = 'Edit branch protected';
-$lang->gitlab->deleteBranchPriv = 'Delete branch protected';
$lang->gitlab->createTag = 'Create Tag';
$lang->gitlab->deleteTag = 'Delete tag';
-$lang->gitlab->createTagPriv = 'Create tag protected';
-$lang->gitlab->editTagPriv = 'Edit tag protected';
-$lang->gitlab->deleteTagPriv = 'Delete tag protected';
+$lang->gitlab->svaeFailed = '『%s』save failed';
$lang->gitlab->id = 'ID';
$lang->gitlab->name = "Server Name";
diff --git a/module/gitlab/lang/fr.php b/module/gitlab/lang/fr.php
index 169875c665..41d82d8582 100644
--- a/module/gitlab/lang/fr.php
+++ b/module/gitlab/lang/fr.php
@@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User";
$lang->gitlab->browseGroup = "Group";
$lang->gitlab->browseBranch = "GitLab Branch List";
$lang->gitlab->browseTag = "GitLab Tag List";
-$lang->gitlab->browseTagPriv = "GitLab Tag protected List";
+$lang->gitlab->browseTagPriv = "Protected tag";
$lang->gitlab->gitlabIssue = "GitLab Issue";
$lang->gitlab->zentaoProduct = 'Zentao Product';
$lang->gitlab->objectType = 'Type'; // task, bug, story
@@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch';
$lang->gitlab->manageGroupMembers = 'Manage group member';
$lang->gitlab->createWebhook = 'Create Webhook';
$lang->gitlab->browseBranchPriv = 'Protect branch';
-$lang->gitlab->createBranchPriv = 'Cerate branch protected';
-$lang->gitlab->editBranchPriv = 'Edit branch protected';
-$lang->gitlab->deleteBranchPriv = 'Delete branch protected';
$lang->gitlab->createTag = 'Create Tag';
$lang->gitlab->deleteTag = 'Delete tag';
-$lang->gitlab->createTagPriv = 'Create tag protected';
-$lang->gitlab->editTagPriv = 'Edit tag protected';
-$lang->gitlab->deleteTagPriv = 'Delete tag protected';
+$lang->gitlab->svaeFailed = '『%s』save failed';
$lang->gitlab->id = 'ID';
$lang->gitlab->name = "Server Name";
diff --git a/module/gitlab/lang/vi.php b/module/gitlab/lang/vi.php
index 169875c665..41d82d8582 100644
--- a/module/gitlab/lang/vi.php
+++ b/module/gitlab/lang/vi.php
@@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User";
$lang->gitlab->browseGroup = "Group";
$lang->gitlab->browseBranch = "GitLab Branch List";
$lang->gitlab->browseTag = "GitLab Tag List";
-$lang->gitlab->browseTagPriv = "GitLab Tag protected List";
+$lang->gitlab->browseTagPriv = "Protected tag";
$lang->gitlab->gitlabIssue = "GitLab Issue";
$lang->gitlab->zentaoProduct = 'Zentao Product';
$lang->gitlab->objectType = 'Type'; // task, bug, story
@@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch';
$lang->gitlab->manageGroupMembers = 'Manage group member';
$lang->gitlab->createWebhook = 'Create Webhook';
$lang->gitlab->browseBranchPriv = 'Protect branch';
-$lang->gitlab->createBranchPriv = 'Cerate branch protected';
-$lang->gitlab->editBranchPriv = 'Edit branch protected';
-$lang->gitlab->deleteBranchPriv = 'Delete branch protected';
$lang->gitlab->createTag = 'Create Tag';
$lang->gitlab->deleteTag = 'Delete tag';
-$lang->gitlab->createTagPriv = 'Create tag protected';
-$lang->gitlab->editTagPriv = 'Edit tag protected';
-$lang->gitlab->deleteTagPriv = 'Delete tag protected';
+$lang->gitlab->svaeFailed = '『%s』save failed';
$lang->gitlab->id = 'ID';
$lang->gitlab->name = "Server Name";
diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php
index d9ac66d15f..7273c0c8ef 100644
--- a/module/gitlab/lang/zh-cn.php
+++ b/module/gitlab/lang/zh-cn.php
@@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "用户";
$lang->gitlab->browseGroup = "群组";
$lang->gitlab->browseBranch = "GitLab分支列表";
$lang->gitlab->browseTag = "GitLab标签列表";
-$lang->gitlab->browseTagPriv = "GitLab标签保护列表";
+$lang->gitlab->browseTagPriv = "标签保护管理";
$lang->gitlab->gitlabIssue = "{$lang->gitlab->common} issue";
$lang->gitlab->zentaoProduct = '禅道产品';
$lang->gitlab->objectType = '类型'; // task, bug, story
@@ -52,14 +52,9 @@ $lang->gitlab->createBranch = '添加分支';
$lang->gitlab->manageGroupMembers = '群组成员管理';
$lang->gitlab->createWebhook = '创建Webhook';
$lang->gitlab->browseBranchPriv = '分支保护管理';
-$lang->gitlab->createBranchPriv = '创建分支保护';
-$lang->gitlab->editBranchPriv = '编辑分支保护';
-$lang->gitlab->deleteBranchPriv = '删除分支保护';
$lang->gitlab->createTag = '创建标签';
$lang->gitlab->deleteTag = '删除标签';
-$lang->gitlab->createTagPriv = '创建标签保护';
-$lang->gitlab->editTagPriv = '编辑标签保护';
-$lang->gitlab->deleteTagPriv = '删除标签保护';
+$lang->gitlab->svaeFailed = '『%s』保存失败';
$lang->gitlab->id = 'ID';
$lang->gitlab->name = "服务器名称";
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index aa7d73dca6..6cef6d84c1 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -2549,59 +2549,54 @@ class gitlabModel extends model
}
/**
- * Get single protct branch by API.
+ * Manage branch privs.
*
* @param int $gitlabID
* @param int $projectID
- * @param string $branch
+ * @param array $protected
* @access public
- * @return object
+ * @return array
*/
- public function apiGetSingleBranchPriv($gitlabID, $projectID, $branch)
+ public function manageBranchPrivs($gitlabID, $projectID, $protected = array())
{
- if(empty($gitlabID)) return false;
- $branch = urlencode($branch);
- $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/protected_branches/$branch");
- return json_decode(commonModel::http($url));
- }
+ $data = (array)fixer::input('post')->get();
+ extract($data);
+ $failure = array();
- /**
- * Create gitlab potect branch.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $branch
- * @access public
- * @return bool
- */
- public function createBranchPriv($gitlabID, $projectID, $branch = '')
- {
- $priv = fixer::input('post')->get();
- if(empty($priv->name))
+ /* Remove privs. */
+ foreach($protected as $name => $branch)
{
- dao::$errors['name'][] = $this->lang->gitlab->branch->emptyPrivNameError;
- return false;
+ if(!in_array($name, $branches))
+ {
+ $result = $this->apiDeleteBranchPriv($gitlabID, $projectID, $name);
+ if($result and substr($result->message, 0, 2) != '20') $failure[] = $name;
+ }
}
- $priv->name = urldecode(helper::safe64Decode($priv->name));
- $singleBranch = $this->apiGetSingleBranchPriv($gitlabID, $projectID, $priv->name);
- if(empty($branch) && !empty($singleBranch->id))
+ $priv = new stdClass();
+ foreach($branches as $key => $name)
{
- dao::$errors['name'][] = $this->lang->gitlab->branch->issetPrivNameError;
- return false;
+ /* Process exists data. */
+ if(isset($protected[$name]))
+ {
+ if($protected[$name]->pushAccess == $pushLevels[$key] and $protected[$name]->mergeAccess == $mergeLevels[$key])
+ {
+ continue;
+ }
+ else
+ {
+ $result = $this->apiDeleteBranchPriv($gitlabID, $projectID, $name);
+ if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name;
+ }
+ }
+
+ $priv->name = $name;
+ $priv->push_access_level = $pushLevels[$key];
+ $priv->merge_access_level = $mergeLevels[$key];
+ $response = $this->apiCreateBranchPriv($gitlabID, $projectID, $priv);
+ if(isset($response->message) and substr($response->message, 0, 2) != '20') $failure[] = $name;
}
-
- if(!empty($branch) && !empty($singleBranch->id)) $this->apiDeleteBranchPriv($gitlabID, $projectID, $branch);
- $response = $this->apiCreateBranchPriv($gitlabID, $projectID, $priv);
-
- if(!empty($response->id))
- {
- $action = empty($branch) ? 'created' : 'edited';
- $this->loadModel('action')->create('gitlabbranchpriv', $response->id, $action, '', $response->name);
- return true;
- }
-
- return $this->apiErrorHandling($response);
+ return array_unique($failure);
}
/**
@@ -2630,7 +2625,7 @@ class gitlabModel extends model
* @param int $projectID
* @param string $branch
* @access public
- * @return object
+ * @return array
*/
public function apiDeleteBranchPriv($gitlabID, $projectID, $branch)
{
@@ -2642,58 +2637,53 @@ class gitlabModel extends model
}
/**
- * Create gitlab protect tag.
+ * Manage tag privs.
*
* @param int $gitlabID
* @param int $projectID
- * @param string $tag
+ * @param array $protected
* @access public
- * @return bool
+ * @return array
*/
- public function createTagPriv($gitlabID, $projectID, $tag = '')
+ public function manageTagPrivs($gitlabID, $projectID, $protected = array())
{
- $priv = fixer::input('post')->get();
- if(empty($priv->name))
+ $data = (array)fixer::input('post')->get();
+ extract($data);
+ $failure = array();
+
+ /* Remove privs. */
+ foreach($protected as $name => $tag)
{
- dao::$errors['name'][] = $this->lang->gitlab->tag->emptyPrivNameError;
- return false;
+ if(!in_array($name, $tags))
+ {
+ $result = $this->apiDeleteTagPriv($gitlabID, $projectID, $name);
+ if($result and substr($result->message, 0, 2) != '20') $failure[] = $name;
+ }
}
- $singleTag = $this->apiGetSingleTagPriv($gitlabID, $projectID, $priv->name);
- if(empty($tag) && !empty($singleTag->id))
+ $priv = new stdClass();
+ foreach($tags as $key => $name)
{
- dao::$errors['name'][] = $this->lang->gitlab->tag->issetPrivNameError;
- return false;
+ /* Process exists data. */
+ if(isset($protected[$name]))
+ {
+ if($protected[$name]->createAccess == $createLevels[$key])
+ {
+ continue;
+ }
+ else
+ {
+ $result = $this->apiDeleteTagPriv($gitlabID, $projectID, $name);
+ if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name;
+ }
+ }
+
+ $priv->name = $name;
+ $priv->create_access_level = $createLevels[$key];
+ $response = $this->apiCreateTagPriv($gitlabID, $projectID, $priv);
+ if(isset($response->message) and substr($response->message, 0, 2) != '20') $failure[] = $name;
}
-
- if(!empty($tag) && !empty($singleTag->name)) $this->apiDeleteTagPriv($gitlabID, $projectID, $tag);
- $response = $this->apiCreateTagPriv($gitlabID, $projectID, $priv);
-
- if(!empty($response->id))
- {
- $action = empty($tag) ? 'created' : 'edited';
- $this->loadModel('action')->create('gitlabtagpriv', $response->id, $action, '', $response->name);
- return true;
- }
-
- return $this->apiErrorHandling($response);
- }
-
- /**
- * Get single protct tag by API.
- *
- * @param int $gitlabID
- * @param int $projectID
- * @param string $tag
- * @access public
- * @return object
- */
- public function apiGetSingleTagPriv($gitlabID, $projectID, $tag)
- {
- if(empty($gitlabID)) return false;
- $tag = urlencode($tag);
- $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/protected_tags/$tag");
- return json_decode(commonModel::http($url));
+ return array_unique($failure);
}
/**
diff --git a/module/gitlab/view/browsebranchpriv.html.php b/module/gitlab/view/browsebranchpriv.html.php
deleted file mode 100644
index 181c913742..0000000000
--- a/module/gitlab/view/browsebranchpriv.html.php
+++ /dev/null
@@ -1,81 +0,0 @@
-
- * @package gitlab
- * @version $Id$
- * @link http://www.zentao.net
- */
-?>
-
-
-
- createLink('gitlab', 'browseProject', "gitlabID=$gitlabID"), " " . $lang->goback, '', "class='btn btn-secondary'");?>
-
-
-
-
- " . $lang->gitlab->createBranchPriv, '', "class='btn btn-primary'");?>
-
-
-
-
-
- noData;?>
-
- createLink('gitlab', 'createBranchPriv', "gitlabID=$gitlabID&projectID=$projectID"), " " . $lang->gitlab->createBranchPriv, '', "class='btn btn-info'");?>
-
-
-
-
-
-
-
diff --git a/module/gitlab/view/browseproject.html.php b/module/gitlab/view/browseproject.html.php
index 93fddbd2f7..e2e9c57d1d 100644
--- a/module/gitlab/view/browseproject.html.php
+++ b/module/gitlab/view/browseproject.html.php
@@ -60,8 +60,8 @@
last_activity_at, 0, 10);?> |
id", '', 'list', 'branch-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch));
- echo common::buildIconButton('gitlab', 'browseTagPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'tag-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch));
+ echo common::buildIconButton('gitlab', 'manageBranchPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'branch-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch));
+ echo common::buildIconButton('gitlab', 'manageTagPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'tag-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch));
echo common::buildIconButton('gitlab', 'manageProjectMembers', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'team', '', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id]));
echo common::buildIconButton('gitlab', 'createWebhook', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'change', 'hiddenwin', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id]));
echo common::buildIconButton('gitlab', 'importIssue', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'link', '', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id]));
diff --git a/module/gitlab/view/browsetagpriv.html.php b/module/gitlab/view/browsetagpriv.html.php
deleted file mode 100644
index 792e05531e..0000000000
--- a/module/gitlab/view/browsetagpriv.html.php
+++ /dev/null
@@ -1,82 +0,0 @@
-
- * @package gitlab
- * @version $Id$
- * @link http://www.zentao.net
- */
-?>
-
-recTotal}&recPerPage={$pager->recPerPage}&pageID=1")?>
-
-
-
- ' . $lang->goback, $this->createLink('gitlab', 'browseProject', "gitlabID=$gitlabID"), 'self', '','btn btn-secondary');?>
-
-
-
-
- " . $lang->gitlab->createTagPriv, '', "class='btn btn-primary'");?>
-
-
-
-
-
- noData;?>
-
- createLink('gitlab', 'createTagPriv', "gitlabID=$gitlabID&projectID=$projectID"), " " . $lang->gitlab->createTagPriv, '', "class='btn btn-info'");?>
-
-
-
-
-
-
-
diff --git a/module/gitlab/view/createbranchpriv.html.php b/module/gitlab/view/createbranchpriv.html.php
deleted file mode 100644
index 52c3e691f2..0000000000
--- a/module/gitlab/view/createbranchpriv.html.php
+++ /dev/null
@@ -1,47 +0,0 @@
-
- * @package gitlab
- * @version $Id$
- * @link http://www.zentao.net
- */
-?>
-
-
-
diff --git a/module/gitlab/view/createtagpriv.html.php b/module/gitlab/view/createtagpriv.html.php
deleted file mode 100644
index cf45b66372..0000000000
--- a/module/gitlab/view/createtagpriv.html.php
+++ /dev/null
@@ -1,43 +0,0 @@
-
- * @package gitlab
- * @version $Id$
- * @link https://www.zentao.net
- */
-?>
-
-
-
-
-
- gitlab->createTagPriv;?>
-
-
-
-
-
-
diff --git a/module/gitlab/view/edittagpriv.html.php b/module/gitlab/view/edittagpriv.html.php
deleted file mode 100644
index aec4bbcbf2..0000000000
--- a/module/gitlab/view/edittagpriv.html.php
+++ /dev/null
@@ -1,44 +0,0 @@
-
- * @package gitlab
- * @version $Id$
- * @link https://www.zentao.net
- */
-?>
-
-
-
-
-
- gitlab->editTagPriv;?>
-
-
-
-
-
-
diff --git a/module/gitlab/view/managebranchpriv.html.php b/module/gitlab/view/managebranchpriv.html.php
new file mode 100644
index 0000000000..c33f4272ff
--- /dev/null
+++ b/module/gitlab/view/managebranchpriv.html.php
@@ -0,0 +1,82 @@
+
+
+
+
+ {$lang->gitlab->browseBranchPriv}");?>
+
+
+
+
+
+
+
+
+ | '') + $noAccessBranches, '', "class='form-control'");?> |
+ gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?> |
+ gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?> |
+
+ ", '', "onclick='addItem(this)' class='btn btn-link'");?>
+ ", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
+ |
+
+
+
+
diff --git a/module/gitlab/view/managetagpriv.html.php b/module/gitlab/view/managetagpriv.html.php
new file mode 100644
index 0000000000..c22ed7462a
--- /dev/null
+++ b/module/gitlab/view/managetagpriv.html.php
@@ -0,0 +1,76 @@
+
+
+
+
+ {$lang->gitlab->browseTagPriv}");?>
+
+
+
+
+
+
+
+
+ | '') + $noAccessTags, '', "class='form-control'");?> |
+ gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?> |
+
+ ", '', "onclick='addItem(this)' class='btn btn-link'");?>
+ ", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
+ |
+
+
+
+
diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php
index 9893779893..361267c995 100644
--- a/module/group/lang/resource.php
+++ b/module/group/lang/resource.php
@@ -1344,17 +1344,11 @@ $lang->resource->gitlab->browseBranch = 'browseBranch';
$lang->resource->gitlab->webhook = 'webhook';
$lang->resource->gitlab->createWebhook = 'createWebhook';
$lang->resource->gitlab->manageProjectMembers = 'manageProjectMembers';
-$lang->resource->gitlab->browseBranchPriv = 'browseBranchPriv';
-$lang->resource->gitlab->createBranchPriv = 'createBranchPriv';
-$lang->resource->gitlab->editBranchPriv = 'editBranchPriv';
-$lang->resource->gitlab->deleteBranchPriv = 'deleteBranchPriv';
+$lang->resource->gitlab->manageBranchPriv = 'browseBranchPriv';
+$lang->resource->gitlab->manageTagPriv = 'browseTagPriv';
$lang->resource->gitlab->browseTag = 'browseTag';
$lang->resource->gitlab->createTag = 'createTag';
$lang->resource->gitlab->deleteTag = 'deleteTag';
-$lang->resource->gitlab->browseTagPriv = 'browseTagPriv';
-$lang->resource->gitlab->createTagPriv = 'createTagPriv';
-$lang->resource->gitlab->editTagPriv = 'editTagPriv';
-$lang->resource->gitlab->deleteTagPriv = 'deleteTagPriv';
$lang->gitlab->methodOrder[5] = 'browse';
$lang->gitlab->methodOrder[10] = 'create';
@@ -1381,9 +1375,11 @@ $lang->gitlab->methodOrder[115] = 'browseBranch';
$lang->gitlab->methodOrder[120] = 'webhook';
$lang->gitlab->methodOrder[125] = 'createWebhook';
$lang->gitlab->methodOrder[130] = 'manageProjectMembers';
-$lang->gitlab->methodOrder[135] = 'browseTag';
-$lang->gitlab->methodOrder[140] = 'browseTagPriv';
-$lang->gitlab->methodOrder[145] = 'deleteTagPriv';
+$lang->gitlab->methodOrder[135] = 'manageBranchPriv';
+$lang->gitlab->methodOrder[140] = 'manageTagPriv';
+$lang->gitlab->methodOrder[145] = 'browseTag';
+$lang->gitlab->methodOrder[150] = 'createTag';
+$lang->gitlab->methodOrder[155] = 'deleteTag';
/* Gitea. */
$lang->resource->gitea = new stdclass();
From 8e2c8317227fb8b939551924addcc4d6657fcfa6 Mon Sep 17 00:00:00 2001
From: caoyanyi
Date: Tue, 12 Jul 2022 09:51:36 +0800
Subject: [PATCH 04/85] * Modify param name.
---
module/gitlab/js/managebranchpriv.js | 4 ++--
module/gitlab/js/managetagpriv.js | 4 ++--
module/gitlab/view/managebranchpriv.html.php | 2 +-
module/gitlab/view/managetagpriv.html.php | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/module/gitlab/js/managebranchpriv.js b/module/gitlab/js/managebranchpriv.js
index ca2a04c27b..b00adf44e6 100644
--- a/module/gitlab/js/managebranchpriv.js
+++ b/module/gitlab/js/managebranchpriv.js
@@ -19,7 +19,7 @@ $.zui.Picker.DEFAULTS.onChange = function(event)
}
/**
- * Save team members.
+ * Save branch priv.
*
* @access public
* @return void
@@ -67,6 +67,6 @@ function addItem(obj)
*/
function deleteItem(obj)
{
- if($('#teamForm .table-form tbody').children().length < 2) return false;
+ if($('#privForm .table-form tbody').children().length < 2) return false;
$(obj).closest('tr').remove();
}
diff --git a/module/gitlab/js/managetagpriv.js b/module/gitlab/js/managetagpriv.js
index 6e290efb1f..1afcbfd09a 100644
--- a/module/gitlab/js/managetagpriv.js
+++ b/module/gitlab/js/managetagpriv.js
@@ -19,7 +19,7 @@ $.zui.Picker.DEFAULTS.onChange = function(event)
}
/**
- * Save team members.
+ * Save tag priv.
*
* @access public
* @return void
@@ -67,6 +67,6 @@ function addItem(obj)
*/
function deleteItem(obj)
{
- if($('#teamForm .table-form tbody').children().length < 2) return false;
+ if($('#privForm .table-form tbody').children().length < 2) return false;
$(obj).closest('tr').remove();
}
diff --git a/module/gitlab/view/managebranchpriv.html.php b/module/gitlab/view/managebranchpriv.html.php
index c33f4272ff..714a03bda1 100644
--- a/module/gitlab/view/managebranchpriv.html.php
+++ b/module/gitlab/view/managebranchpriv.html.php
@@ -7,7 +7,7 @@
| |