Merge branch 'zenops_38' into 'master'

Zenops 38

See merge request easycorp/zentaopms!4597
This commit is contained in:
王怡栋
2022-07-20 00:28:11 +00:00
62 changed files with 2064 additions and 971 deletions
+1
View File
@@ -377,6 +377,7 @@ $config->objectTables['gitlab'] = TABLE_PIPELINE;
$config->objectTables['jebkins'] = TABLE_PIPELINE;
$config->objectTables['stage'] = TABLE_STAGE;
$config->objectTables['apistruct'] = TABLE_APISTRUCT;
$config->objectTables['repo'] = TABLE_REPO;
$config->newFeatures = array('introduction', 'tutorial', 'youngBlueTheme', 'visions');
+815
View File
@@ -0,0 +1,815 @@
<?php
class gitea
{
public $client;
public $projectID;
private $pageLimit = 50;
/**
* Construct
*
* @param string $client gitea api url.
* @param string $root id of gitea project.
* @param string $username null
* @param string $password token of gitea api.
* @param string $encoding
* @access public
* @return void
*/
public function __construct($client, $root, $username, $password, $encoding = 'UTF-8')
{
$this->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 = "contents";
$path = ltrim($path, '/');
if($path) $api .= "/$path";
$param = new stdclass();
$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;
if($file->type == 'file')
{
$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, 1);
if(empty($commits) or !is_array($commits)) continue;
$commit = $commits[0];
$info->revision = $commit->sha;
$info->comment = $commit->commit->message;
$info->account = $commit->commit->author->name;
$info->date = date('Y-m-d H:i:s', strtotime($commit->commit->author->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.gitea.com/ee/api/repository_files.html
*/
public function files($path, $ref = 'master')
{
$path = urlencode($path);
$api = "contents/$path";
$file = $this->fetch($api, array('ref' => $ref));
if(!isset($file->name)) return false;
$commits = $this->getCommitsByPath($path, '', '', 1, 1);
$file->revision = $file->sha;
$file->size = $this->formatBytes($file->size);
if(!empty($commits))
{
$commit = $commits[0];
$file->revision = $commit->sha;
$file->committer = $commit->commit->author->name;
$file->comment = $commit->commit->message;
$file->date = date('Y-m-d H:i:s', strtotime($commit->commit->author->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['limit'] = $this->pageLimit;
for($page = 1; true; $page ++)
{
$params['page'] = $page;
$list = $this->fetch($api, $params);
if(empty($list) or $list == '[]') break;
foreach($list as $tag) $tags[] = $tag->name;
if(count($list) < $params['limit']) break;
}
return $tags;
}
/**
* Get branches.
*
* @access public
* @return array
*/
public function branch()
{
/* Max size of limit in gitea API is 50. */
$params = array();
$params['limit'] = $this->pageLimit;
/* Get default branch. */
$project = $this->fetch('');
$defaultBranch = $project->default_branch;
$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->name == $defaultBranch)
{
$default[$branch->name] = $branch->name;
}
else
{
$branches[$branch->name] = $branch->name;
}
}
/* Last page. */
if(count($branchList) < $params['limit']) 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, 1, 1);
foreach($list as $commit)
{
if(isset($commit->sha)) $commit->diffs = $this->getFilesByCommit($commit->sha);
}
return $this->parseLog($list);
}
/**
* Blame file
*
* @param string $path
* @param string $revision
* @access public
* @return array
*/
public function blame($path, $revision)
{
return array();
}
/**
* 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();
$diffApi = "{$this->root}git/commits/$toRevision.diff?token={$this->token}";
$diffs = commonModel::http($diffApi);
$lines = explode("\n", $diffs);
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 gitea 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 = $this->pageLimit;
if(!empty($version) and $count == 1)
{
$commits = $this->fetch($api, array('limit' => 1, 'sha' => $version));
$commit = $commits[0];
if(isset($commit->sha))
{
$log = new stdclass;
$log->committer = $commit->commit->author->name;
$log->revision = $commit->sha;
$log->comment = $commit->commit->message;
$log->time = date('Y-m-d H:i:s', strtotime($commit->commit->author->date));
$commits[$commit->sha] = $log;
$files[$commit->sha] = $this->getFilesByCommit($log->revision);
return array('commits' => $commits, 'files' => $files);
}
}
$params['sha'] = $branch;
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(!isset($commit->commit) or !is_object($commit->commit)) continue;
$log = new stdclass;
$log->committer = $commit->commit->author->name;
$log->revision = $commit->sha;
$log->comment = $commit->commit->message;
$log->time = date('Y-m-d H:i:s', strtotime($commit->commit->author->date));
$commits[$commit->sha] = $log;
$files[$commit->sha] = $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));
$params = array();
$params['sha'] = $sha;
$params['limit'] = 1;
$result = $this->fetch("commits", $params);
return (isset($resulti[0]->created)) ? date('Y-m-d H:i:s', strtotime($result->created)) : 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, $limit = 0)
{
$path = ltrim($path, DIRECTORY_SEPARATOR);
$api = "commits";
if(!$limit) $limit = $this->pageLimit;
$param = new stdclass();
$param->path = urldecode($path);
$param->limit = $limit;
$param->sha = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch;
if($perPage) $param->page = $perPage;
return $this->fetch($api, $param);
}
/**
* Get diff files by reviesion.
*
* @param int $reviesion
* @access public
* @return array
*/
public function getDiffFiles($revision)
{
$diffApi = "{$this->root}git/commits/$revision.patch?token={$this->token}";
$diffs = commonModel::http($diffApi);
$newFiles = array();
$delFiles = array();
if(!empty($diffs))
{
$diffs = explode("\n", $diffs);
foreach($diffs as $row)
{
preg_match('/^(\s)(create|delete)\smode\s\d+\s(.+)$/', $row, $matches);
if(count($matches) == 4 and !in_array($matches[3], $newFiles) and !in_array($matches[3], $delFiles))
{
if($matches[2] == 'create')
{
$newFiles[] = $matches[3];
}
elseif($matches[2] == 'delete')
{
$delFiles[] = $matches[3];
}
}
}
}
return array('newFiles' => $newFiles, 'delFiles' => $delFiles);
}
/**
* Get files by commit.
*
* @param string $commit
* @access public
* @return void
*/
public function getFilesByCommit($revision)
{
if(!scm::checkRevision($revision)) return array();
$api = "git/commits/$revision";
$results = $this->fetch($api);
if(empty($results)) return array();
$diffFiles = $this->getDiffFiles($revision);
$files = array();
foreach($results->files as $row)
{
$file = new stdclass();
$file->revision = $revision;
$file->type = 'file';
$file->path = '/' . $row->filename;
$file->action = 'M';
if(in_array($row->filename, $diffFiles['newFiles']))
{
$file->action = 'A';
}
elseif(in_array($row->filename, $diffFiles['delFiles']))
{
$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 = "contents";
$params = array();
$params['path'] = ltrim($path, '/');
$params['ref'] = $this->branch;
$params['recursive'] = (int) $recursive;
return $this->fetch($api, $params);
}
/**
* Fetch data from gitea api.
*
* @param string $api
* @access public
* @return mixed
*/
public function fetch($api, $params = array(), $needToLoop = false)
{
$params = (array) $params;
$params['token'] = $this->token;
$params['limit'] = isset($params['limit']) ? $params['limit'] : $this->pageLimit;
$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) < $this->pageLimit) 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->sha)) continue;
$parsedLog = new stdclass();
$parsedLog->revision = $commit->sha;
$parsedLog->committer = $commit->commit->author->name;
$parsedLog->time = date('Y-m-d H:i:s', strtotime($commit->commit->author->date));
$parsedLog->comment = $commit->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;
}
/**
* Get download url.
*
* @param string $branch
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = 'master', $ext = 'zip')
{
$params['token'] = $this->token;
return "{$this->root}archive/" . urlencode($branch) . ".{$ext}" . '?' . http_build_query($params);
}
}
+17
View File
@@ -834,4 +834,21 @@ class gitlab
return $parsedLogs;
}
/**
* Get download url.
*
* @param string $branch
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = 'master', $ext = 'zip')
{
$params = (array) $params;
$params['private_token'] = $this->token;
$params['sha'] = $branch;
return "{$this->root}archive.{$ext}" . '?' . http_build_query($params);
}
}
+13
View File
@@ -244,6 +244,19 @@ class scm
if(preg_match('/[^a-z0-9\-_\.\^\w][\x{4e00}-\x{9fa5}]/ui', $revision)) return false;
return true;
}
/**
* Get download url.
*
* @param string $branch
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = '', $ext = 'zip')
{
return $this->engine->getDownloadUrl($branch, $ext);
}
}
/**
+2 -1
View File
@@ -46,6 +46,7 @@ $config->action->objectNameFields['gitlab'] = 'name';
$config->action->objectNameFields['gitea'] = 'name';
$config->action->objectNameFields['stage'] = 'name';
$config->action->objectNameFields['apistruct'] = 'name';
$config->action->objectNameFields['repo'] = 'name';
$config->action->commonImgSize = 870;
@@ -61,7 +62,7 @@ $config->action->majorList['execution'] = array('opened', 'edited');
$config->action->needGetProjectType = 'build,task,bug,case,testcase,caselib,testtask,testsuite,testreport,doc,issue,release,risk,design,opportunity,trainplan,gapanalysis,researchplan,researchreport,';
$config->action->needGetRelateField = ',story,productplan,release,task,build,bug,testcase,case,testtask,testreport,doc,doclib,issue,risk,opportunity,trainplan,gapanalysis,team,whitelist,researchplan,researchreport,meeting,kanbanlane,kanbancolumn,module,';
$config->action->noLinkModules = ',doclib,module,webhook,gitlab,gitea,sonarqube,pipeline,jenkins,kanban,kanbanspace,kanbancolumn,kanbanlane,kanbanregion,kanbancard,execution,project,traincategory,apistruct,program,product,user,entry,';
$config->action->noLinkModules = ',doclib,module,webhook,gitlab,gitea,sonarqube,pipeline,jenkins,kanban,kanbanspace,kanbancolumn,kanbanlane,kanbanregion,kanbancard,execution,project,traincategory,apistruct,program,product,user,entry,repo,';
$config->action->preferredTypeNum = 10;
+2
View File
@@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches';
$lang->action->objectTypes['gitlabtag'] = 'GitLab Tag';
$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected';
$lang->action->objectTypes['giteauser'] = 'Gitea User';
$lang->action->objectTypes['kanbanspace'] = 'Kanban Space';
$lang->action->objectTypes['kanban'] = 'Kanban';
$lang->action->objectTypes['kanbanregion'] = 'Kanban Region';
@@ -143,6 +144,7 @@ $lang->action->objectTypes['sonarqube'] = 'SonarQube Server';
$lang->action->objectTypes['sonarqubeproject'] = 'SonarQube Project';
$lang->action->objectTypes['stage'] = 'Stage';
$lang->action->objectTypes['patch'] = 'Patch';
$lang->action->objectTypes['repo'] = 'Repo';
/* Used to describe operation history. */
$lang->action->desc = new stdclass();
+2
View File
@@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches';
$lang->action->objectTypes['gitlabtag'] = 'GitLab Tag';
$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected';
$lang->action->objectTypes['giteauser'] = 'Gitea User';
$lang->action->objectTypes['kanbanspace'] = 'Kanban Space';
$lang->action->objectTypes['kanban'] = 'Kanban';
$lang->action->objectTypes['kanbanregion'] = 'Kanban Region';
@@ -143,6 +144,7 @@ $lang->action->objectTypes['sonarqube'] = 'SonarQube Server';
$lang->action->objectTypes['sonarqubeproject'] = 'SonarQube Project';
$lang->action->objectTypes['stage'] = 'Stage';
$lang->action->objectTypes['patch'] = 'Patch';
$lang->action->objectTypes['repo'] = 'Repo';
/* Used to describe operation history. */
$lang->action->desc = new stdclass();
+2
View File
@@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches';
$lang->action->objectTypes['gitlabtag'] = 'GitLab Tag';
$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected';
$lang->action->objectTypes['giteauser'] = 'Gitea User';
$lang->action->objectTypes['kanbanspace'] = 'Kanban Space';
$lang->action->objectTypes['kanban'] = 'Kanban';
$lang->action->objectTypes['kanbanregion'] = 'Kanban Region';
@@ -143,6 +144,7 @@ $lang->action->objectTypes['sonarqube'] = 'SonarQube Server';
$lang->action->objectTypes['sonarqubeproject'] = 'SonarQube Project';
$lang->action->objectTypes['stage'] = 'Stage';
$lang->action->objectTypes['patch'] = 'Patch';
$lang->action->objectTypes['repo'] = 'Repo';
/* Used to describe operation history. */
$lang->action->desc = new stdclass();
+2
View File
@@ -111,6 +111,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches';
$lang->action->objectTypes['gitlabtag'] = 'GitLab Tag';
$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected';
$lang->action->objectTypes['giteauser'] = 'Gitea User';
$lang->action->objectTypes['kanbanspace'] = 'Kanban Space';
$lang->action->objectTypes['kanban'] = 'Kanban';
$lang->action->objectTypes['kanbanregion'] = 'Kanban Region';
@@ -121,6 +122,7 @@ $lang->action->objectTypes['sonarqube'] = 'SonarQube Server';
$lang->action->objectTypes['sonarqubeproject'] = 'SonarQube Project';
$lang->action->objectTypes['stage'] = 'Stage';
$lang->action->objectTypes['patch'] = 'Patch';
$lang->action->objectTypes['repo'] = 'Repo';
/* Used to describe operation history. */
$lang->action->desc = new stdclass();
+2
View File
@@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab分支';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab保护分支';
$lang->action->objectTypes['gitlabtag'] = 'GitLab标签';
$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab标签保护';
$lang->action->objectTypes['giteauser'] = 'Gitea用户';
$lang->action->objectTypes['kanbanspace'] = '看板空间';
$lang->action->objectTypes['kanban'] = '看板';
$lang->action->objectTypes['kanbanregion'] = '看板区域';
@@ -143,6 +144,7 @@ $lang->action->objectTypes['sonarqube'] = 'SonarQube服务器';
$lang->action->objectTypes['sonarqubeproject'] = 'SonarQube项目';
$lang->action->objectTypes['stage'] = '阶段';
$lang->action->objectTypes['patch'] = '补丁';
$lang->action->objectTypes['repo'] = '代码库';
/* 用来描述操作历史记录。*/
$lang->action->desc = new stdclass();
+2
View File
@@ -127,12 +127,14 @@ $lang->action->objectTypes['gitlabgroup'] = 'GitLab群組';
$lang->action->objectTypes['gitlabbranch'] = 'GitLab分支';
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab保護分支';
$lang->action->objectTypes['gitlabtag'] = 'GitLab標籤';
$lang->action->objectTypes['giteauser'] = 'Gitea用戶';
$lang->action->objectTypes['kanbanspace'] = '看板空間';
$lang->action->objectTypes['kanban'] = '看板';
$lang->action->objectTypes['kanbanregion'] = '看板區域';
$lang->action->objectTypes['kanbanlane'] = '看板泳道';
$lang->action->objectTypes['kanbancolumn'] = '看板列';
$lang->action->objectTypes['kanbancard'] = '看板卡片';
$lang->action->objectTypes['repo'] = '代码库';
/* 用來描述操作歷史記錄。*/
$lang->action->desc = new stdclass();
+2 -2
View File
@@ -1254,8 +1254,8 @@ class actionModel extends model
/* If action type is login or logout, needn't link. */
if($actionType == 'svncommited' or $actionType == 'gitcommited') $action->actor = zget($commiters, $action->actor);
/* Get gitlab objectname. */
if(empty($action->objectName) and substr($objectType, 0, 6) == 'gitlab') $action->objectName = $action->extra;
/* Get gitlab or gitea objectname. */
if(empty($action->objectName) and (substr($objectType, 0, 6) == 'gitlab' or substr($objectType, 0, 5) == 'gitea')) $action->objectName = $action->extra;
/* Other actions, create a link. */
if(!$this->setObjectLink($action, $deptUsers))
+7 -1
View File
@@ -26,7 +26,13 @@ class ciModel extends model
}
common::setMenuVars('devops', $this->session->repoID);
$this->lang->switcherMenu = $this->loadModel('repo')->getSwitcher($this->session->repoID);
if($this->session->repoID)
{
$repo = $this->loadModel('repo')->getRepoByID($this->session->repoID);
if($repo->SCM != 'Gitlab') unset($this->lang->devops->menu->mr);
$this->lang->switcherMenu = $this->loadModel('repo')->getSwitcher($this->session->repoID);
}
}
/**
+2
View File
@@ -46,6 +46,8 @@ class compile extends control
$this->view->job = $job;
}
$this->app->loadLang('job');
$this->loadModel('ci')->setMenu($repoID);
$this->app->loadClass('pager', $static = true);
+8 -2
View File
@@ -131,8 +131,14 @@ class gitModel extends model
$gitlabAccountPairs = array();
if($repo->SCM == 'Gitlab')
{
$gitlabUserList = $this->loadModel('gitlab')->apiGetUsers($repo->gitlab);
$acountIDPairs = $this->gitlab->getUserIdAccountPairs($repo->gitlab);
$gitlabUserList = $this->loadModel('gitlab')->apiGetUsers($repo->gitService);
$acountIDPairs = $this->gitlab->getUserIdAccountPairs($repo->gitService);
foreach($gitlabUserList as $gitlabUser) $gitlabAccountPairs[$gitlabUser->realname] = zget($acountIDPairs, $gitlabUser->id, '');
}
elseif($repo->SCM == 'Gitea')
{
$gitlabUserList = $this->loadModel('gitea')->apiGetUsers($repo->gitService);
$acountIDPairs = $this->gitea->getUserAccountIdPairs($repo->gitService, 'openID,account');
foreach($gitlabUserList as $gitlabUser) $gitlabAccountPairs[$gitlabUser->realname] = zget($acountIDPairs, $gitlabUser->id, '');
}
+33
View File
@@ -43,6 +43,12 @@ class gitea extends control
/* Admin user don't need bind. */
$giteaList = $this->gitea->getList($orderBy, $pager);
$myGiteas = $this->gitea->getGiteaListByAccount();
foreach($giteaList as $gitea)
{
$gitea->isBindUser = true;
if(!$this->app->user->admin and !isset($myGiteas[$gitea->id])) $gitea->isBindUser = false;
}
$this->view->title = $this->lang->gitea->common . $this->lang->colon . $this->lang->gitea->browse;
$this->view->giteaList = $giteaList;
@@ -164,4 +170,31 @@ class gitea extends control
return true;
}
/**
* Bind gitea user to zentao users.
*
* @param int $giteaID
* @access public
* @return void
*/
public function bindUser($giteaID)
{
$zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
$userPairs = $this->loadModel('user')->getPairs('noclosed|noletter');
if($_POST)
{
$this->gitea->bindUser($giteaID);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer));
}
$this->view->title = $this->lang->gitea->bindUser;
$this->view->userPairs = $userPairs;
$this->view->giteaUsers = $this->gitea->apiGetUsers($giteaID);
$this->view->bindedUsers = $this->gitea->getUserAccountIdPairs($giteaID);
$this->view->matchedResult = $this->gitea->getMatchedUsers($giteaID, $this->view->giteaUsers, $zentaoUsers);
$this->display();
}
}
+10 -2
View File
@@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea';
$lang->gitea->view = 'View Gitea';
$lang->gitea->delete = 'Delete Gitea';
$lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?';
$lang->gitea->bindUser = 'Bind User';
$lang->gitea->giteaAccount = 'Gitea Account';
$lang->gitea->zentaoAccount = 'Zentao Account';
$lang->gitea->bindingStatus = 'Binding Status';
$lang->gitea->notBind = 'Not bind';
$lang->gitea->binded = 'Binded';
$lang->gitea->bindDynamic = '%s and Zentao user %s';
$lang->gitea->browseAction = 'Gitea List';
$lang->gitea->deleteAction = 'Delete Gitea';
@@ -17,8 +24,9 @@ $lang->gitea->name = "Server Name";
$lang->gitea->url = 'Server URL';
$lang->gitea->token = 'Token';
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->bindUserError = "Can not bind users repeatedly %s";
$lang->gitea->server = "Server List";
$lang->gitea->lblCreate = 'Create Gitea Server';
+10 -2
View File
@@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea';
$lang->gitea->view = 'View Gitea';
$lang->gitea->delete = 'Delete Gitea';
$lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?';
$lang->gitea->bindUser = 'Bind User';
$lang->gitea->giteaAccount = 'Gitea Account';
$lang->gitea->zentaoAccount = 'Zentao Account';
$lang->gitea->bindingStatus = 'Binding Status';
$lang->gitea->notBind = 'Not bind';
$lang->gitea->binded = 'Binded';
$lang->gitea->bindDynamic = '%s and Zentao user %s';
$lang->gitea->browseAction = 'Gitea List';
$lang->gitea->deleteAction = 'Delete Gitea';
@@ -17,8 +24,9 @@ $lang->gitea->name = "Server Name";
$lang->gitea->url = 'Server URL';
$lang->gitea->token = 'Token';
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->bindUserError = "Can not bind users repeatedly %s";
$lang->gitea->server = "Server List";
$lang->gitea->lblCreate = 'Create Gitea Server';
+10 -2
View File
@@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea';
$lang->gitea->view = 'View Gitea';
$lang->gitea->delete = 'Delete Gitea';
$lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?';
$lang->gitea->bindUser = 'Bind User';
$lang->gitea->giteaAccount = 'Gitea Account';
$lang->gitea->zentaoAccount = 'Zentao Account';
$lang->gitea->bindingStatus = 'Binding Status';
$lang->gitea->notBind = 'Not bind';
$lang->gitea->binded = 'Binded';
$lang->gitea->bindDynamic = '%s and Zentao user %s';
$lang->gitea->browseAction = 'Gitea List';
$lang->gitea->deleteAction = 'Delete Gitea';
@@ -17,8 +24,9 @@ $lang->gitea->name = "Server Name";
$lang->gitea->url = 'Server URL';
$lang->gitea->token = 'Token';
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->bindUserError = "Can not bind users repeatedly %s";
$lang->gitea->server = "Server List";
$lang->gitea->lblCreate = 'Create Gitea Server';
+10 -2
View File
@@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea';
$lang->gitea->view = 'View Gitea';
$lang->gitea->delete = 'Delete Gitea';
$lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?';
$lang->gitea->bindUser = 'Bind User';
$lang->gitea->giteaAccount = 'Gitea Account';
$lang->gitea->zentaoAccount = 'Zentao Account';
$lang->gitea->bindingStatus = 'Binding Status';
$lang->gitea->notBind = 'Not bind';
$lang->gitea->binded = 'Binded';
$lang->gitea->bindDynamic = '%s and Zentao user %s';
$lang->gitea->browseAction = 'Gitea List';
$lang->gitea->deleteAction = 'Delete Gitea';
@@ -17,8 +24,9 @@ $lang->gitea->name = "Server Name";
$lang->gitea->url = 'Server URL';
$lang->gitea->token = 'Token';
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->tokenLimit = "The current token has no admin privilege. Please regenerate one with root user in Gitea.";
$lang->gitea->hostError = "So the current Gitea server address is invalid, please confirm that the current server can be accessed and try again.";
$lang->gitea->bindUserError = "Can not bind users repeatedly %s";
$lang->gitea->server = "Server List";
$lang->gitea->lblCreate = 'Create Gitea Server';
+10 -2
View File
@@ -8,6 +8,13 @@ $lang->gitea->edit = '编辑Gitea';
$lang->gitea->view = '查看Gitea';
$lang->gitea->delete = '删除Gitea';
$lang->gitea->confirmDelete = '确认删除该Gitea吗?';
$lang->gitea->bindUser = '绑定用户';
$lang->gitea->giteaAccount = 'Gitea用户';
$lang->gitea->zentaoAccount = '禅道用户';
$lang->gitea->bindingStatus = '绑定状态';
$lang->gitea->notBind = '未绑定';
$lang->gitea->binded = '已绑定';
$lang->gitea->bindDynamic = '%s与禅道用户%s';
$lang->gitea->browseAction = 'Gitea列表';
$lang->gitea->deleteAction = '删除Gitea';
@@ -17,8 +24,9 @@ $lang->gitea->name = "服务器名称";
$lang->gitea->url = '服务器地址';
$lang->gitea->token = 'Token';
$lang->gitea->tokenLimit = "Gitea Token权限不足。";
$lang->gitea->hostError = "当前Gitea服务器地址无效,请确认当前服务器可被访问";
$lang->gitea->tokenLimit = "Gitea Token权限不足。";
$lang->gitea->hostError = "当前Gitea服务器地址无效,请确认当前服务器可被访问";
$lang->gitea->bindUserError = "不能重复绑定用户 %s";
$lang->gitea->server = "服务器列表";
$lang->gitea->lblCreate = '添加Gitea服务器';
+7
View File
@@ -8,6 +8,13 @@ $lang->gitea->edit = '编辑Gitea';
$lang->gitea->view = '查看Gitea';
$lang->gitea->delete = '删除Gitea';
$lang->gitea->confirmDelete = '确认删除该Gitea吗?';
$lang->gitea->bindUser = '绑定用户';
$lang->gitea->giteaAccount = 'Gitea用户';
$lang->gitea->zentaoAccount = '禅道用户';
$lang->gitea->bindingStatus = '绑定状态';
$lang->gitea->notBind = '未绑定';
$lang->gitea->binded = '已绑定';
$lang->gitea->bindDynamic = '%s与禅道用户%s';
$lang->gitea->browseAction = 'Gitea列表';
$lang->gitea->deleteAction = '删除Gitea';
+230
View File
@@ -104,6 +104,63 @@ class giteaModel extends model
return $this->loadModel('pipeline')->update($id);
}
/**
* Bind users.
*
* @param int $giteaID
* @access public
* @return array
*/
public function bindUser($giteaID)
{
$userPairs = $this->loadModel('user')->getPairs('noclosed|noletter');
$users = $this->post->zentaoUsers;
$giteaNames = $this->post->giteaUserNames;
$accountList = array();
$repeatUsers = array();
foreach($users as $openID => $user)
{
if(empty($user)) continue;
if(isset($accountList[$user])) $repeatUsers[] = zget($userPairs, $user);
$accountList[$user] = $openID;
}
if(count($repeatUsers))
{
dao::$errors[] = sprintf($this->lang->gitea->bindUserError, join(',', $repeatUsers));
return false;
}
$user = new stdclass;
$user->providerID = $giteaID;
$user->providerType = 'gitea';
$oldUsers = $this->dao->select('*')->from(TABLE_OAUTH)->where('providerType')->eq($user->providerType)->andWhere('providerID')->eq($user->providerID)->fetchAll('openID');
foreach($users as $openID => $account)
{
$existAccount = isset($oldUsers[$openID]) ? $oldUsers[$openID] : '';
if($existAccount and $existAccount->account != $account)
{
$this->dao->delete()
->from(TABLE_OAUTH)
->where('openID')->eq($openID)
->andWhere('providerType')->eq($user->providerType)
->andWhere('providerID')->eq($user->providerID)
->exec();
$this->loadModel('action')->create('giteauser', $giteaID, 'unbind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$existAccount->account]->realname));
}
if(!$existAccount or $existAccount->account != $account)
{
if(!$account) continue;
$user->account = $account;
$user->openID = $openID;
$this->dao->insert(TABLE_OAUTH)->data($user)->exec();
$this->loadModel('action')->create('giteauser', $giteaID, 'bind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$account]->realname));
}
}
}
/**
* Api error handling.
*
@@ -224,4 +281,177 @@ class giteaModel extends model
->andWhere('account')->eq($account)
->fetchPairs('providerID');
}
/**
* Get zentao account gitea user id pairs of one gitea.
*
* @param int $giteaID
* @access public
* @return array
*/
public function getUserAccountIdPairs($giteaID, $fields = 'account,openID')
{
return $this->dao->select($fields)->from(TABLE_OAUTH)
->where('providerType')->eq('gitea')
->andWhere('providerID')->eq($giteaID)
->fetchPairs();
}
/**
* Get gitea user id by zentao account.
*
* @param int $giteaID
* @param string $zentaoAccount
* @access public
* @return array
*/
public function getUserIDByZentaoAccount($giteaID, $zentaoAccount)
{
return $this->dao->select('openID')->from(TABLE_OAUTH)
->where('providerType')->eq('gitea')
->andWhere('providerID')->eq($giteaID)
->andWhere('account')->eq($zentaoAccount)
->fetch('openID');
}
/**
* Get matched gitea users.
*
* @param int $giteaID
* @param array $giteaUsers
* @param array $zentaoUsers
* @access public
* @return array
*/
public function getMatchedUsers($giteaID, $giteaUsers, $zentaoUsers)
{
$matches = new stdclass;
foreach($giteaUsers as $giteaUser)
{
foreach($zentaoUsers as $zentaoUser)
{
if($giteaUser->account == $zentaoUser->account) $matches->accounts[$giteaUser->account][] = $zentaoUser->account;
if($giteaUser->realname == $zentaoUser->realname) $matches->names[$giteaUser->realname][] = $zentaoUser->account;
if($giteaUser->email == $zentaoUser->email) $matches->emails[$giteaUser->email][] = $zentaoUser->account;
}
}
$bindedUsers = $this->getUserAccountIdPairs($giteaID, 'openID,account');
$matchedUsers = array();
foreach($giteaUsers as $giteaUser)
{
if(isset($bindedUsers[$giteaUser->account]))
{
$giteaUser->zentaoAccount = $bindedUsers[$giteaUser->account];
$matchedUsers[] = $giteaUser;
continue;
}
$matchedZentaoUsers = array();
if(isset($matches->accounts[$giteaUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$giteaUser->account]);
if(isset($matches->emails[$giteaUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$giteaUser->email]);
if(isset($matches->names[$giteaUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$giteaUser->realname]);
$matchedZentaoUsers = array_unique($matchedZentaoUsers);
if(count($matchedZentaoUsers) == 1)
{
$giteaUser->zentaoAccount = current($matchedZentaoUsers);
$matchedUsers[] = $giteaUser;
}
}
return $matchedUsers;
}
/**
* 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");
$allResults = array();
for($page = 1; true; $page++)
{
$results = json_decode(commonModel::http($url . "&page={$page}&limit=50"));
if(!is_array($results->data)) break;
if(!empty($results->data)) $allResults = array_merge($allResults, $results->data);
if(count($results->data) < 50) break;
}
return $allResults;
}
/**
* Get gitea user list.
*
* @param int $giteaID
* @param bool $onlyLinked
* @access public
* @return array
*/
public function apiGetUsers($giteaID, $onlyLinked = false)
{
$response = array();
$apiRoot = $this->getApiRoot($giteaID);
for($page = 1; true; $page++)
{
$url = sprintf($apiRoot, "/users/search") . "&page={$page}&limit=50";
$result = json_decode(commonModel::http($url));
if(empty($result->data)) break;
$response = array_merge($response, $result->data);
$page += 1;
}
if(empty($response)) return array();
/* Get linked users. */
$linkedUsers = array();
if($onlyLinked) $linkedUsers = $this->getUserAccountIdPairs($giteaID, 'openID,account');
$users = array();
foreach($response as $giteaUser)
{
if($onlyLinked and !isset($linkedUsers[$giteaUser->id])) continue;
$user = new stdclass;
$user->id = $giteaUser->id;
$user->realname = $giteaUser->full_name ? $giteaUser->full_name : $giteaUser->username;
$user->account = $giteaUser->username;
$user->email = zget($giteaUser, 'email', '');
$user->avatar = $giteaUser->avatar_url;
$user->createdAt = zget($giteaUser, 'created', '');
$user->lastActivityOn = zget($giteaUser, 'last_login', '');
$users[] = $user;
}
return $users;
}
}
+83
View File
@@ -0,0 +1,83 @@
<?php
/**
* The bind user view of gitea module of ZenTaoPMS.
*
* @copyright Copyright 2009-2022 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yuchun Li <liyuchun@easycorp.ltd>
* @package gitea
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id="mainContent" class="main-content">
<div class="main-header">
<h2><?php echo $lang->gitea->bindUser;?></h2>
</div>
<form method='post' class='load-indicator main-form form-ajax' enctype='multipart/form-data'>
<div class="table-responsive">
<table class="table table-borderless w-600px">
<thead>
<tr>
<th colspan='2'><?php echo $lang->gitea->giteaAccount;?></th>
<th class='w-150px'><?php echo $lang->gitea->zentaoAccount;?></th>
<th class='w-150px'><?php echo $lang->gitea->bindingStatus;?></th>
</tr>
</thead>
<tbody>
<?php foreach($giteaUsers as $giteaUser):?>
<?php if(isset($giteaUser->zentaoAccount)) continue;?>
<?php echo html::hidden("giteaUserNames[$giteaUser->account]", $giteaUser->realname);?>
<tr>
<td class='w-60px'><?php echo html::image($giteaUser->avatar, "height=40");?></td>
<td class='text-left'>
<strong><?php echo $giteaUser->realname;?></strong>
<br>
<?php echo $giteaUser->account;?>
<?php if($giteaUser->email) echo " &lt;" . $giteaUser->email . "&gt;";?>
</td>
<td><?php echo html::select("zentaoUsers[$giteaUser->account]", $userPairs, '', "class='form-control select chosen'" );?></td>
<td><?php echo $lang->gitea->notBind;?></td>
</tr>
<?php endforeach;?>
<?php foreach($giteaUsers as $giteaUser):?>
<?php if(!isset($giteaUser->zentaoAccount)) continue;?>
<?php echo html::hidden("giteaUserNames[$giteaUser->account]", $giteaUser->realname);?>
<tr>
<td class='w-60px'><?php echo html::image($giteaUser->avatar, "height=40");?></td>
<td>
<strong><?php echo $giteaUser->realname;?></strong>
<br>
<?php echo $giteaUser->account;?>
<?php if($giteaUser->email) echo " &lt;" . $giteaUser->email . "&gt;";?>
</td>
<td><?php echo html::select("zentaoUsers[$giteaUser->account]", $userPairs, $giteaUser->zentaoAccount, "class='form-control select chosen'" );?></td>
<td>
<?php if(isset($bindedUsers[$giteaUser->zentaoAccount])):?>
<?php $zentaoAccount = zget($userPairs, $giteaUser->zentaoAccount, '');?>
<?php if(!empty($zentaoAccount)):?>
<?php echo $lang->gitea->binded;?>
<?php else:?>
<?php echo '<span class="text-red">' . $lang->gitea->bindedError . '</span>';?>
<?php endif;?>
<?php else:?>
<?php echo $lang->gitea->notBind;?>
<?php endif;?>
</td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan="3" class="text-center form-actions">
<?php echo html::submitButton();?>
<?php if(!isonlybody()) echo html::a(inlink('browse', ""), $lang->goback, '', 'class="btn btn-wide"');?>
</td>
</tr>
</tfoot>
</table>
</div>
</form>
</div>
<?php include '../../common/view/footer.html.php';?>
+1
View File
@@ -56,6 +56,7 @@
<td class='c-actions text-left'>
<?php
common::printIcon('gitea', 'edit', "giteaID=$id", '', 'list', 'edit');
echo common::buildIconButton('gitea', 'bindUser', "giteaID=$id", '', 'list', 'link', '', '', false, '', '', 0, $gitea->isBindUser);
common::printIcon('gitea', 'delete', "giteaID=$id", '', 'list', 'trash', 'hiddenwin');
?>
</td>
+104 -381
View File
@@ -47,9 +47,7 @@ class gitlab extends control
foreach($gitlabList as $gitlab)
{
$token = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token);
$gitlab->isAdminToken = (isset($token->is_admin) and $token->is_admin);
$gitlab->isBindUser = true;
$gitlab->isBindUser = true;
if(!$this->app->user->admin and !isset($myGitLabs[$gitlab->id])) $gitlab->isBindUser = false;
}
@@ -911,176 +909,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 +963,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.
*
@@ -1346,7 +974,7 @@ class gitlab extends control
{
$repo = $this->loadModel('repo')->getRepoByID($repoID);
$productIDList = explode(',', $repo->product);
$gitlabID = $repo->gitlab;
$gitlabID = $repo->gitService;
$projectID = $repo->project;
$gitlab = $this->gitlab->getByID($gitlabID);
@@ -1491,7 +1119,7 @@ class gitlab extends control
$bindedUsers = $this->dao->select('account,openID')
->from(TABLE_OAUTH)
->where('providerType')->eq('gitlab')
->andWhere('providerID')->eq($repo->gitlab)
->andWhere('providerID')->eq($repo->gitService)
->fetchPairs();
if(empty($repo->acl))
@@ -1511,7 +1139,7 @@ class gitlab extends control
}
}
$gitlabCurrentMembers = $this->gitlab->apiGetProjectMembers($repo->gitlab, $repo->project);
$gitlabCurrentMembers = $this->gitlab->apiGetProjectMembers($repo->gitService, $repo->project);
$addedMembers = $updatedMembers = $deletedMembers = array();
/* Get the updated data. */
@@ -1570,17 +1198,17 @@ class gitlab extends control
foreach($addedMembers as $addedMember)
{
$this->gitlab->apiCreateProjectMember($repo->gitlab, $repo->project, $addedMember);
$this->gitlab->apiCreateProjectMember($repo->gitService, $repo->project, $addedMember);
}
foreach($updatedMembers as $updatedMember)
{
$this->gitlab->apiUpdateProjectMember($repo->gitlab, $repo->project, $updatedMember);
$this->gitlab->apiUpdateProjectMember($repo->gitService, $repo->project, $updatedMember);
}
foreach($deletedMembers as $deletedMemberID)
{
$this->gitlab->apiDeleteProjectMember($repo->gitlab, $repo->project, $deletedMemberID);
$this->gitlab->apiDeleteProjectMember($repo->gitService, $repo->project, $deletedMemberID);
}
$repo->acl->users = array_values($accounts);
@@ -1590,7 +1218,7 @@ class gitlab extends control
$repo = $this->loadModel('repo')->getRepoByID($repoID);
$users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted|noclosed');
$projectMembers = $this->gitlab->apiGetProjectMembers($repo->gitlab, $repo->project);
$projectMembers = $this->gitlab->apiGetProjectMembers($repo->gitService, $repo->project);
if(!is_array($projectMembers)) $projectMembers = array();
/* Get users accesslevel. */
@@ -1598,7 +1226,7 @@ class gitlab extends control
$bindedUsers = $this->dao->select('openID,account')
->from(TABLE_OAUTH)
->where('providerType')->eq('gitlab')
->andWhere('providerID')->eq($repo->gitlab)
->andWhere('providerID')->eq($repo->gitService)
->fetchPairs();
foreach($projectMembers as $projectMember)
@@ -1746,4 +1374,99 @@ 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')));
$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')));
}
$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')));
$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')));
}
$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();
}
}
+74
View File
@@ -0,0 +1,74 @@
/* 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 branch priv.
*
* @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 = $('<tr class="addedItem">' + item + '</tr>').insertAfter($(obj).closest('tr'));
var $branches = $tr.find('select').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
itemIndex++;
var disabledItems = [];
$('.user-picker[name^=branches]').each(function()
{
if(this === $branches[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) $branches.data('zui.picker').updateOptionList(disabledItems);
}
/**
* Delete item.
*
* @param object $obj
* @access public
* @return void
*/
function deleteItem(obj)
{
if($('#privForm .table tbody').children().length < 2) return false;
$(obj).closest('tr').find('.picker .picker-selection-remove').click();
$(obj).closest('tr').remove();
}
+74
View File
@@ -0,0 +1,74 @@
/* 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 tag priv.
*
* @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 = $('<tr class="addedItem">' + item + '</tr>').insertAfter($(obj).closest('tr'));
var $tags = $tr.find('select').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
itemIndex++;
var disabledItems = [];
$('.user-picker[name^=tags]').each(function()
{
if(this === $tags[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) $tags.data('zui.picker').updateOptionList(disabledItems);
}
/**
* Delete item.
*
* @param object $obj
* @access public
* @return void
*/
function deleteItem(obj)
{
if($('#privForm .table tbody').children().length < 2) return false;
$(obj).closest('tr').find('.picker .picker-selection-remove').click();
$(obj).closest('tr').remove();
}
+2 -7
View File
@@ -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";
+2 -7
View File
@@ -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";
+2 -7
View File
@@ -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";
+2 -7
View File
@@ -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";
+2 -7
View File
@@ -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 = "服务器名称";
+65 -104
View File
@@ -1203,7 +1203,7 @@ class gitlabModel extends model
/* Return an empty array if where is one existing webhook. */
if($this->isWebhookExists($repo, $hook->url)) return array();
$result = $this->apiCreateHook($repo->gitlab, $repo->project, $hook);
$result = $this->apiCreateHook($repo->gitService, $repo->project, $hook);
if(!empty($result->id)) return true;
return false;
@@ -1218,7 +1218,7 @@ class gitlabModel extends model
*/
public function isWebhookExists($repo, $url = '')
{
$hookList = $this->apiGetHooks($repo->gitlab, $repo->project);
$hookList = $this->apiGetHooks($repo->gitService, $repo->project);
foreach($hookList as $hook)
{
if($hook->url == $url) return true;
@@ -2549,59 +2549,49 @@ 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;
$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 +2620,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 +2632,48 @@ 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;
$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);
}
/**
@@ -2896,23 +2876,4 @@ class gitlabModel extends model
$html .= '</div>';
return $html;
}
/**
* Download zip code.
*
* @param int $gitlabID
* @param int $projectID
* @param string $branch
* @param string $ext tar.gz|tar.bz2|tbz|tbz2|tb2|bz2|tar|zip
* @access public
* @return string
*/
public function downloadCode($gitlabID = 0, $projectID = 0, $branch = '', $ext = 'zip')
{
if(empty($gitlabID) or empty($projectID)) return false;
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/repository/archive." . $ext);
if($branch) $url .= '&sha=' . $branch;
return $url;
}
}
+2 -2
View File
@@ -43,7 +43,7 @@
</thead>
<tbody>
<?php foreach ($gitlabList as $id => $gitlab): ?>
<tr class='text' title='<?php if(!$gitlab->isAdminToken) echo $lang->gitlab->tokenLimit;?>'>
<tr class='text'>
<td class='text-center'><?php echo $id;?></td>
<td class='text-c-name' title='<?php echo $gitlab->name;?>'>
<?php if(common::hasPriv('gitlab', 'browseProject')):?>
@@ -55,7 +55,7 @@
<td class='text' title='<?php echo $gitlab->url;?>'><?php echo html::a($gitlab->url, $gitlab->url, '_target');?></td>
<td class='c-actions text-left'>
<?php
$disabled = (empty($gitlab->isAdminToken) or !$gitlab->isBindUser) ? false : true;
$disabled = $gitlab->isBindUser ? true : false;
common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit');
echo common::buildIconButton('gitlab', 'bindUser', "gitlabID=$id", '', 'list', 'link', '', '', false, '', '', 0, $disabled);
common::printIcon('gitlab', 'delete', "gitlabID=$id", '', 'list', 'trash', 'hiddenwin');
@@ -1,81 +0,0 @@
<?php
/**
* The browse view file of gitlab protext branch of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yanyi Cao <caoyanyi@easycorp.ltd>
* @package gitlab
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id="mainMenu" class="clearfix">
<div class='pull-left'>
<?php echo html::a($this->createLink('gitlab', 'browseProject', "gitlabID=$gitlabID"), "<i class='icon icon-back icon-sm'></i> " . $lang->goback, '', "class='btn btn-secondary'");?>
</div>
<div id="sidebarHeader">
<div class="title" title="<?php echo $project->name_with_namespace; ?>"><?php echo $project->name_with_namespace; ?></div>
</div>
<div class="btn-toolbar pull-left">
<div>
<form id='branchPrivForm' method='post'>
<?php echo html::input('keyword', $keyword, "class='form-control' placeholder='{$lang->gitlab->branch->placeholderSearch}' style='display: inline-block;width:auto;margin:0 10px'");?>
<a id="branchSearch" class="btn btn-primary"><?php echo $lang->gitlab->search?></a>
</form>
</div>
</div>
<div class="btn-toolbar pull-right">
<?php if(common::hasPriv('gitlab', 'createBranchPriv')) common::printLink('gitlab', 'createBranchPriv', "gitlabID=$gitlabID&projectID=$projectID", "<i class='icon icon-plus'></i> " . $lang->gitlab->createBranchPriv, '', "class='btn btn-primary'");?>
</div>
</div>
<?php if(empty($branchList)):?>
<div class="table-empty-tip">
<p>
<span class="text-muted"><?php echo $lang->noData;?></span>
<?php if(empty($keyword) and common::hasPriv('gitlab', 'createBranchPriv')):?>
<?php echo html::a($this->createLink('gitlab', 'createBranchPriv', "gitlabID=$gitlabID&projectID=$projectID"), "<i class='icon icon-plus'></i> " . $lang->gitlab->createBranchPriv, '', "class='btn btn-info'");?>
<?php endif;?>
</p>
</div>
<?php else:?>
<div id='mainContent' class='main-row'>
<form class='main-table' id='ajaxForm' method='post'>
<table id='branchList' class='table has-sort-head table-fixed'>
<?php $vars = "gitlabID={$gitlabID}&projectID={$projectID}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
<thead>
<tr>
<th class='c-name text-left'><?php common::printOrderLink('name', $orderBy, $vars, $lang->gitlab->branch->name);?></th>
<th class='text-left'><?php echo $lang->gitlab->branch->mergeAllowed;?></th>
<th class='text-left'><?php echo $lang->gitlab->branch->pushAllowed;?></th>
<th class='c-actions-4'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php foreach ($branchList as $id => $branch): ?>
<?php $branch->merge_access_level = $this->gitlab->checkAccessLevel($branch->merge_access_levels); ?>
<?php $branch->push_access_level = $this->gitlab->checkAccessLevel($branch->push_access_levels); ?>
<tr class='text'>
<td class='text-c-name' title='<?php echo $branch->name;?>'><?php echo $branch->name;?></td>
<td class-'text' title="<?php echo $levelLang[$branch->merge_access_level];?>"><?php echo $levelLang[$branch->merge_access_level];?></td>
<td class='text' title="<?php echo $levelLang[$branch->push_access_level];?>"><?php echo $levelLang[$branch->push_access_level];?></td>
<td class='c-actions text-left'>
<?php
/* Fix error when request type is PATH_INFO and the branch name contains '-'.*/
$branchName = helper::safe64Encode(urlencode($branch->name));
if(common::hasPriv('gitlab', 'editBranchPriv')) common::printLink('gitlab', 'editBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branchName", "<i class='icon icon-edit'></i> ", '', "title={$lang->gitlab->editBranchPriv} class='btn btn-primary'");
if(common::hasPriv('gitlab', 'deleteBranchPriv')) echo html::a($this->createLink('gitlab', 'deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branchName"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->gitlab->deleteBranchPriv}' class='btn'");
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php if($branchList):?>
<div class='table-footer'><?php $pager->show('right', 'pagerjs');?></div>
<?php endif;?>
</form>
</div>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
+2 -2
View File
@@ -60,8 +60,8 @@
<td class='text' title='<?php echo substr($gitlabProject->last_activity_at, 0, 10);?>'><?php echo substr($gitlabProject->last_activity_at, 0, 10);?></td>
<td class='c-actions text-left'>
<?php
echo common::buildIconButton('gitlab', 'browseBranchPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->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, '', $this->lang->gitlab->browseBranchPriv, 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch));
echo common::buildIconButton('gitlab', 'manageTagPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'tag-lock', '', '', false, '', $this->lang->gitlab->browseTagPriv, 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]));
-82
View File
@@ -1,82 +0,0 @@
<?php
/**
* The browse view file of gitlab module of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Gang Zeng <zenggang@easycorp.ltd>
* @package gitlab
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('vars', "keyword=%s&orderBy=id_desc&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID=1")?>
<?php js::set('gitlabID', $gitlabID)?>
<div id="mainMenu" class="clearfix">
<div class='pull-left'>
<?php echo html::linkButton('<i class="icon icon-back icon-sm"></i> ' . $lang->goback, $this->createLink('gitlab', 'browseProject', "gitlabID=$gitlabID"), 'self', '','btn btn-secondary');?>
</div>
<div id="sidebarHeader">
<div class="title" title="<?php echo $project->name_with_namespace; ?>"><?php echo $project->name_with_namespace; ?></div>
</div>
<div class="btn-toolbar pull-left">
<div>
<form id='tagForm' method='post'>
<?php echo html::input('keyword', $keyword, "class='form-control' placeholder='{$lang->gitlab->tag->placeholderSearch}' style='display: inline-block;width:auto;margin:0 10px'");?>
<a id="tagSearch" class="btn btn-primary"><?php echo $lang->gitlab->search?></a>
</form>
</div>
</div>
<div class="btn-toolbar pull-right">
<?php common::printLink('gitlab', 'createTagPriv', "gitlabID=$gitlabID&projectID=$projectID", "<i class='icon icon-plus'></i> " . $lang->gitlab->createTagPriv, '', "class='btn btn-primary'");?>
</div>
</div>
<?php if(empty($gitlabTagList)):?>
<div class="table-empty-tip">
<p>
<span class="text-muted"><?php echo $lang->noData;?></span>
<?php if(empty($keyword) and common::hasPriv('gitlab', 'createTag')):?>
<?php echo html::a($this->createLink('gitlab', 'createTagPriv', "gitlabID=$gitlabID&projectID=$projectID"), "<i class='icon icon-plus'></i> " . $lang->gitlab->createTagPriv, '', "class='btn btn-info'");?>
<?php endif;?>
</p>
</div>
<?php else:?>
<div id='mainContent' class='main-row'>
<form class='main-table' id='ajaxForm' method='post'>
<table id='gitlabTagList' class='table has-sort-head table-fixed'>
<?php $vars = "gitlabID={$gitlabID}&projectID={$projectID}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
<thead>
<tr>
<th class='c-name text-left'><?php common::printOrderLink('name', $orderBy, $vars, $lang->gitlab->tag->name);?></th>
<th class='text-left'><?php echo $lang->gitlab->tag->lastCommitter;?></th>
<th class='text-left'><?php common::printOrderLink('accessLevels', $orderBy, $vars, $lang->gitlab->tag->accessLevel);?></th>
<th class='c-actions-2'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php foreach ($gitlabTagList as $id => $gitlabTag): ?>
<?php $gitlabTag->accessLevel = $this->gitlab->checkAccessLevel($gitlabTag->accessLevels); ?>
<tr class='text'>
<td class='text-c-name' title='<?php echo $gitlabTag->name;?>'><?php echo $gitlabTag->name;?></td>
<td class='text'><?php echo $gitlabTag->lastCommitter;?></td>
<td class='text'><?php echo zget($lang->gitlab->branch->branchCreationLevelList, $gitlabTag->accessLevel);?></td>
<td class='c-actions text-left'>
<?php
/* Fix error when request type is PATH_INFO and the tag name contains '-'.*/
$tagName = helper::safe64Encode(urlencode($gitlabTag->name));
common::printLink('gitlab', 'editTagPriv', "gitlabID=$gitlabID&projectID=$projectID&tag_name=$tagName", "<i class='icon icon-edit'></i> ", '', "title={$lang->gitlab->editTagPriv} class='btn btn-primary'");
common::printLink('gitlab', 'deleteTagPriv', "gitlabID=$gitlabID&projectID={$projectID}&tag_name=$tagName", "<i class='icon icon-trash'></i> ", '', "title='{$lang->gitlab->deleteTagPriv}' class='btn btn-primary' target='hiddenwin' onclick='if(confirm(\"{$lang->gitlab->tag->protectConfirmDel}\")==false) return false;'");
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php if($gitlabTagList):?>
<div class='table-footer'><?php $pager->show('right', 'pagerjs');?></div>
<?php endif;?>
</form>
</div>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
@@ -1,47 +0,0 @@
<?php
/**
* The create view file of protext branch of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yanyi Cao <caoyanyi@easycorp.ltd>
* @package gitlab
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id='mainContent' class='main-row'>
<div class='main-col main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $pageTitle;?></h2>
</div>
<form id='branchForm' method='post' class='form-ajax' enctype="multipart/form-data">
<?php if($branchPriv->name) echo html::hidden('name', $branchPriv->name);?>
<table class='table table-form'>
<tr>
<th><?php echo $lang->gitlab->branch->name;?></th>
<td><?php echo html::select('name', $branches, $branchPriv->name, "class='form-control chosen' " . ($branch ? 'disabled' : ''));?></td>
</tr>
<tr>
<th><?php echo $lang->gitlab->branch->mergeAllowed;?></th>
<td><?php echo html::select('merge_access_level', $lang->gitlab->branch->branchCreationLevelList, $branchPriv->mergeAccessLevel, "class='form-control'");?></td>
</tr>
<tr>
<th><?php echo $lang->gitlab->branch->pushAllowed;?></th>
<td><?php echo html::select('push_access_level', $lang->gitlab->branch->branchCreationLevelList, $branchPriv->pushAccessLevel, "class='form-control'");?></td>
</tr>
<tr>
<th></th>
<td class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php if(!isonlybody()) echo html::a(inlink('browseBranchPriv', "gitlabID=$gitlabID&projectID=$projectID"), $lang->goback, '', 'class="btn btn-wide"');?>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php include '../../common/view/footer.html.php';?>
-43
View File
@@ -1,43 +0,0 @@
<?php
/**
* The create view file of protect tag of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yuchun Li <liyuchun@easycorp.ltd>
* @package gitlab
* @version $Id$
* @link https://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id='mainContent' class='main-row'>
<div class='main-col main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->gitlab->createTagPriv;?></h2>
</div>
<form id='branchForm' method='post' class='form-ajax' enctype="multipart/form-data">
<table class='table table-form'>
<tr>
<th class='w-110px'><?php echo $lang->gitlab->tag->name;?></th>
<td><?php echo html::select('name', $tags, '', "class='form-control chosen'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->gitlab->tag->accessLevel;?></th>
<td><?php echo html::select('create_access_level', $lang->gitlab->branch->branchCreationLevelList, '40', "class='form-control chosen'");?></td>
</tr>
<tr>
<th></th>
<td class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php if(!isonlybody()) echo html::a(inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID"), $lang->goback, '', 'class="btn btn-wide"');?>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php include '../../common/view/footer.html.php';?>
-44
View File
@@ -1,44 +0,0 @@
<?php
/**
* The edit view file of protect tag of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yuchun Li <liyuchun@easycorp.ltd>
* @package gitlab
* @version $Id$
* @link https://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id='mainContent' class='main-row'>
<div class='main-col main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->gitlab->editTagPriv;?></h2>
</div>
<form id='branchForm' method='post' class='form-ajax' enctype="multipart/form-data">
<table class='table table-form'>
<tr>
<th class='w-110px'><?php echo $lang->gitlab->tag->name;?></th>
<td><?php echo html::input('tagName', $tag, "class='form-control' disabled");?></td>
<td></td>
<?php echo html::hidden('name', $tag);?>
</tr>
<tr>
<th><?php echo $lang->gitlab->tag->accessLevel;?></th>
<td><?php echo html::select('create_access_level', $lang->gitlab->branch->branchCreationLevelList, $tagPriv->createAccessLevel, "class='form-control chosen'");?></td>
</tr>
<tr>
<th></th>
<td class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php if(!isonlybody()) echo html::a(inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID"), $lang->goback, '', 'class="btn btn-wide"');?>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php include '../../common/view/footer.html.php';?>
@@ -0,0 +1,82 @@
<?php include '../../common/view/header.html.php';?>
<div id='mainMenu' class='clearfix'>
<div class='btn-toolbar pull-left'>
<span class='btn btn-link btn-active-text'>
<?php echo html::a('###', "<span class='text'> {$lang->gitlab->browseBranchPriv}</span>");?>
</span>
</div>
</div>
<div id='mainContent' class='main-content'>
<form class='main-form form-ajax' method='post' id='privForm'>
<table class='table table-form'>
<thead>
<tr class='text-center'>
<th class='c-names'><?php echo $lang->gitlab->branch->name;?></th>
<th class='c-levels'><?php echo $lang->gitlab->branch->mergeAllowed;?></th>
<th class='c-levels'><?php echo $lang->gitlab->branch->pushAllowed;?></th>
<th class="c-actions"><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php $i = 0;?>
<?php if(!empty($hasAccessBranches)):?>
<?php foreach($hasAccessBranches as $branch):?>
<tr>
<td><?php echo html::input("names[$i]", $branch->name, "class='form-control' readonly");?></td>
<td><?php echo html::select("mergeLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $branch->mergeAccess, "class='form-control user-picker'");?></td>
<td>
<?php echo html::select("pushLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $branch->pushAccess, "class='form-control user-picker'");?>
<?php echo html::hidden("branches[$i]", $branch->name);?>
</td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
</td>
</tr>
<?php $i ++;?>
<?php endforeach;?>
<?php endif;?>
<?php for($j = 0; $j < 5; $j ++):?>
<tr class='addedItem'>
<td><?php echo html::select("branches[$i]", array(''=>'') + $noAccessBranches, '', "class='form-control user-picker'");?></td>
<td><?php echo html::select("mergeLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?></td>
<td><?php echo html::select("pushLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
</td>
</tr>
<?php $i ++;?>
<?php endfor;?>
</tbody>
<tfoot>
<tr>
<td colspan='4' class='text-center form-actions'>
<?php
echo html::submitButton('', '', 'hidden btn btn-wide btn-primary');
echo html::commonButton($lang->save, 'onclick="savePriv()" id="saveBtn"', 'btn btn-wide btn-primary');
echo html::backButton();
?>
</td>
</tr>
</tfoot>
</table>
<?php js::set('itemIndex', $i);?>
</form>
</div>
<div>
<?php $i = '%i%';?>
<table class='hidden'>
<tr id='addItem' class='hidden'>
<td><?php echo html::select("branches[]", array(''=>'') + $noAccessBranches, '', "class='form-control'");?></td>
<td><?php echo html::select("mergeLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control'");?></td>
<td><?php echo html::select("pushLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
</td>
</tr>
</table>
</div>
<?php include '../../common/view/footer.html.php';?>
+76
View File
@@ -0,0 +1,76 @@
<?php include '../../common/view/header.html.php';?>
<div id='mainMenu' class='clearfix'>
<div class='btn-toolbar pull-left'>
<span class='btn btn-link btn-active-text'>
<?php echo html::a('###', "<span class='text'> {$lang->gitlab->browseTagPriv}</span>");?>
</span>
</div>
</div>
<div id='mainContent' class='main-content'>
<form class='main-form form-ajax' method='post' id='privForm'>
<table class='table table-form'>
<thead>
<tr class='text-center'>
<th class='c-names'><?php echo $lang->gitlab->tag->name;?></th>
<th class='c-levels'><?php echo $lang->gitlab->tag->accessLevel;?></th>
<th class="c-actions"><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php $i = 0;?>
<?php if(!empty($hasAccessTags)):?>
<?php foreach($hasAccessTags as $tag):?>
<tr>
<td><?php echo html::input("names[$i]", $tag->name, "class='form-control' readonly");?></td>
<td><?php echo html::select("createLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $tag->createAccess, "class='form-control user-picker'");?></td>
<td class='c-actions text-center'>
<?php echo html::hidden("tags[$i]", $tag->name);?>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
</td>
</tr>
<?php $i ++;?>
<?php endforeach;?>
<?php endif;?>
<?php for($j = 0; $j < 5; $j ++):?>
<tr class='addedItem'>
<td><?php echo html::select("tags[$i]", array(''=>'') + $noAccessTags, '', "class='form-control user-picker'");?></td>
<td><?php echo html::select("createLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
</td>
</tr>
<?php $i ++;?>
<?php endfor;?>
</tbody>
<tfoot>
<tr>
<td colspan='4' class='text-center form-actions'>
<?php
echo html::submitButton('', '', 'hidden btn btn-wide btn-primary');
echo html::commonButton($lang->save, 'onclick="savePriv()" id="saveBtn"', 'btn btn-wide btn-primary');
echo html::backButton();
?>
</td>
</tr>
</tfoot>
</table>
<?php js::set('itemIndex', $i);?>
</form>
</div>
<div>
<?php $i = '%i%';?>
<table class='hidden'>
<tr id='addItem' class='hidden'>
<td><?php echo html::select("tags[]", array(''=>'') + $noAccessTags, '', "class='form-control'");?></td>
<td><?php echo html::select("createLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
</td>
</tr>
</table>
</div>
<?php include '../../common/view/footer.html.php';?>
+14 -16
View File
@@ -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,23 +1375,27 @@ $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();
$lang->resource->gitea->browse = 'browse';
$lang->resource->gitea->create = 'create';
$lang->resource->gitea->edit = 'edit';
$lang->resource->gitea->view = 'view';
$lang->resource->gitea->delete = 'delete';
$lang->resource->gitea->browse = 'browse';
$lang->resource->gitea->create = 'create';
$lang->resource->gitea->edit = 'edit';
$lang->resource->gitea->view = 'view';
$lang->resource->gitea->delete = 'delete';
$lang->resource->gitea->bindUser = 'bindUser';
$lang->gitea->methodOrder[5] = 'browse';
$lang->gitea->methodOrder[10] = 'create';
$lang->gitea->methodOrder[15] = 'edit';
$lang->gitea->methodOrder[20] = 'view';
$lang->gitea->methodOrder[25] = 'delete';
$lang->gitea->methodOrder[30] = 'bindUser';
/* SonarQube. */
$lang->resource->sonarqube = new stdclass();
+3 -3
View File
@@ -114,7 +114,7 @@ class job extends control
$repoTypes[$repo->id] = $repo->SCM;
if(strtolower($repo->SCM) == 'gitlab')
{
if(isset($repo->gitlab)) $gitlab = $this->loadModel('gitlab')->getByID($repo->gitlab);
if(isset($repo->gitService)) $gitlab = $this->loadModel('gitlab')->getByID($repo->gitService);
if(!empty($gitlab)) $tokenUser = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token);
if(!isset($tokenUser->is_admin) or !$tokenUser->is_admin) continue;
$gitlabRepos[$repo->id] = $repo->name;
@@ -180,7 +180,7 @@ class job extends control
$repo = $this->loadModel('repo')->getRepoByID($job->repo);
$this->view->repo = $this->loadModel('repo')->getRepoByID($job->repo);
if($repo->SCM == 'Gitlab') $this->view->refList = $this->loadModel('gitlab')->getReferenceOptions($repo->gitlab, $repo->project);
if($repo->SCM == 'Gitlab') $this->view->refList = $this->loadModel('gitlab')->getReferenceOptions($repo->gitService, $repo->project);
$repoList = $this->repo->getList($this->projectID);
$repoPairs = array(0 => '', $repo->id => $repo->name);
@@ -383,7 +383,7 @@ class job extends control
public function ajaxGetRefList($repoID)
{
$repo = $this->loadModel('repo')->getRepoByID($repoID);
if($repo->SCM == 'Gitlab') $refList = $this->loadModel('gitlab')->getReferenceOptions($repo->gitlab, $repo->project);
if($repo->SCM == 'Gitlab') $refList = $this->loadModel('gitlab')->getReferenceOptions($repo->gitService, $repo->project);
if($repo->SCM != 'Gitlab') $refList = $this->repo->getBranches($repo, true);
$this->send(array('result' => 'success', 'refList' => $refList));
}
+5
View File
@@ -49,6 +49,11 @@ $config->repo->gitlab = new stdclass;
$config->repo->gitlab->perPage = 300;
$config->repo->gitlab->apiPath = "%s/api/v4/projects/%s/repository/";
$config->repo->gitea = new stdclass;
$config->repo->gitea->apiPath = "%s/api/v1/repos/%s/";
$config->repo->gitServiceList = array('gitlab', 'gitea');
$config->repo->rules['module']['task'] = 'Task';
$config->repo->rules['module']['bug'] = 'Bug';
$config->repo->rules['module']['story'] = 'Story';
+79 -29
View File
@@ -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|noclosed');
$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|noclosed');
$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;
@@ -233,11 +237,7 @@ class repo extends control
if($error) return print(js::alert($error));
$this->dao->delete()->from(TABLE_REPO)->where('id')->eq($repoID)->exec();
$this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->exec();
$this->dao->delete()->from(TABLE_REPOFILES)->where('repo')->eq($repoID)->exec();
$this->dao->delete()->from(TABLE_REPOBRANCH)->where('repo')->eq($repoID)->exec();
$this->repo->delete(TABLE_REPO, $repoID);
if(dao::isError()) return print(js::error(dao::getError()));
echo js::reload('parent');
}
@@ -1166,6 +1166,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 = "<option value=''></option>";
foreach($projects as $project) $options .= "<option value='{$project->full_name}' data-name='{$project->name}'>{$project->full_name}</option>";
return print($options);
}
/**
* Ajax get gitlab projects.
*
@@ -1316,9 +1364,11 @@ class repo extends control
}
$repo = $this->repo->getRepoByID($repoID);
if($repo->SCM == 'Gitlab')
if(in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList))
{
$url = $this->loadModel('gitlab')->downloadCode($repo->gitlab, $repo->project, $branch);
$this->scm = $this->app->loadClass('scm');
$this->scm->setEngine($repo);
$url = $this->scm->getDownloadUrl($branch);
}
elseif($repo->SCM == 'Git')
{
-1
View File
@@ -85,7 +85,6 @@ h3 {font-size: 16px;}
.repoCode tr.over.commented .comment-btn {margin-left: -20px; width: 25px; height:18px;}
.repoCode tr.over.commented .comment-btn .icon-wrapper, .repoCode tr.selected.commented .comment-btn .icon-wrapper {line-height: 20px; height: 20px; background: #4183C4; color: #fff; left: -6px;}
.repoCode tr.over.commented .comment-btn .icon-wrapper {left: 13px;}
.repoCode tr.over.commented .comment-btn .icon-wrapper > i:before {font-size: 14px;}
.repoCode tr.selected.commented .comment-btn .icon-wrapper > i:before {font-size: 14px;}
.repoCode tr.over.commented .comment-btn .icon-wrapper:before, .repoCode tr.selected.commented .comment-btn .icon-wrapper:before {display: block;}
+32 -9
View File
@@ -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();
});
}
}
+36 -10
View File
@@ -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();
});
}
}
}
+4
View File
@@ -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';
+4
View File
@@ -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';
+4
View File
@@ -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';
+9
View File
@@ -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 ...';
+4
View File
@@ -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访问地址';
+4
View File
@@ -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訪問地址';
+63 -43
View File
@@ -38,6 +38,9 @@ class repoModel extends model
if(empty($repoID)) $repoID = $this->session->repoID ? $this->session->repoID : key($repos);
if(!isset($repos[$repoID])) $repoID = key($repos);
/* Init switcher menu. */
$this->lang->switcherMenu = '';
/* Check the privilege. */
if($repoID)
{
@@ -138,7 +141,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;
@@ -165,7 +168,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;
@@ -182,19 +185,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')
@@ -209,7 +213,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;
}
@@ -226,9 +230,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'")
@@ -262,17 +266,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')
@@ -307,7 +312,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;
}
@@ -315,7 +320,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')
@@ -416,10 +421,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)
{
@@ -428,6 +431,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);
@@ -455,7 +463,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;
}
@@ -882,14 +890,17 @@ class repoModel extends model
{
$commitID = $this->dao->lastInsertID();
if($branch) $this->dao->replace(TABLE_REPOBRANCH)->set('repo')->eq($repoID)->set('revision')->eq($commitID)->set('branch')->eq($branch)->exec();
foreach($logs['files'][$i] as $file)
if(!empty($logs['files']))
{
$parentPath = dirname($file->path);
foreach($logs['files'][$i] as $file)
{
$parentPath = dirname($file->path);
$file->parent = $parentPath == '\\' ? '/' : $parentPath;
$file->revision = $commitID;
$file->repo = $repoID;
$this->dao->insert(TABLE_REPOFILES)->data($file)->exec();
$file->parent = $parentPath == '\\' ? '/' : $parentPath;
$file->revision = $commitID;
$file->repo = $repoID;
$this->dao->insert(TABLE_REPOFILES)->data($file)->exec();
}
}
$revisionPairs[$commit->revision] = $commit->revision;
$version++;
@@ -1274,7 +1285,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)
@@ -2016,21 +2027,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->{$service->type}->apiPath, $service->url, $repo->path) : '';
$repo->client = $service ? $service->url : '';
$repo->password = $service ? $service->token : '';
return $repo;
}
@@ -2151,13 +2162,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');
+5 -1
View File
@@ -19,7 +19,9 @@ if(isset($entry)) $pathInfo .= '&type=file';
<table class='table table-fixed'>
<thead>
<tr>
<?php if($repo->SCM != 'Gitea'):?>
<th class='c-checkbox'></th>
<?php endif;?>
<th class='c-version'><?php echo $lang->repo->revisionA?></th>
<?php if($repo->SCM != 'Subversion'):?>
<th class='c-commit'><?php echo $lang->repo->commit?></th>
@@ -32,12 +34,14 @@ if(isset($entry)) $pathInfo .= '&type=file';
<tbody>
<?php foreach($revisions as $log):?>
<tr>
<?php if($repo->SCM != 'Gitea'):?>
<td>
<div class='checkbox-primary'>
<input type='checkbox' name='revision[]' value="<?php echo $log->revision?>" />
<label></label>
</div>
</td>
<?php endif;?>
<td class='versions'><span class="revision"><?php echo html::a($this->repo->createLink('revision', "repoID=$repoID&objectID=$objectID&revision={$log->revision}" . $pathInfo), $repo->SCM != 'Subversion' ? substr($log->revision, 0, 10) : $log->revision, '', "data-app='{$this->app->tab}'");?></span></td>
<?php if($repo->SCM != 'Subversion'):?>
<td><?php echo $log->commit?></td>
@@ -50,7 +54,7 @@ if(isset($entry)) $pathInfo .= '&type=file';
</tbody>
</table>
<div class='table-footer'>
<?php if(common::hasPriv('repo', 'diff')) echo html::submitButton($lang->repo->diff, '', count($revisions) < 2 ? 'disabled btn btn-primary' : 'btn btn-primary')?>
<?php if($repo->SCM != 'Gitea' and common::hasPriv('repo', 'diff')) echo html::submitButton($lang->repo->diff, '', count($revisions) < 2 ? 'disabled btn btn-primary' : 'btn btn-primary')?>
<?php echo html::a($this->repo->createLink('log', "repoID=$repoID&objectID=$objectID&entry=" . $this->repo->encodePath($path) . "&revision=HEAD&type=$logType"), $lang->repo->allLog, '', "class='allLogs' data-app='{$this->app->tab}'");?>
<div class='pull-right'>
<ul id="repoPageSize" class="pager" data-ride="pager" data-elements="size_menu" data-rec-total="<?php echo $pager->recTotal;?>" data-rec-per-page="<?php echo $pager->recPerPage;?>" data-page="<?php echo $pager->pageID;?>"></ul>
+10 -10
View File
@@ -32,20 +32,20 @@
<td style="width:550px"><?php echo html::select('SCM', $lang->repo->scmList, 'Gitlab', "onchange='scmChanged(this.value)' class='form-control chosen'"); ?></td>
<td class="tips-git"><?php echo $lang->repo->syncTips; ?></td>
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabHost;?></th>
<td class='required'><?php echo html::select('gitlabHost', $gitlabHosts, '', "class='form-control chosen' placeholder='{$lang->repo->placeholder->gitlabHost}'");?></td>
<tr class='service hide'>
<th><?php echo $lang->repo->serviceHost;?></th>
<td class='required'><?php echo html::select('serviceHost', $serviceHosts, '', "class='form-control chosen'");?></td>
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabProject;?></th>
<td class='required'><?php echo html::select('gitlabProject', array(''), '', "class='form-control chosen'");?></td>
<tr class='service hide'>
<th><?php echo $lang->repo->serviceProject;?></th>
<td class='required'><?php echo html::select('serviceProject', array(''), '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->repo->name; ?></th>
<td class='required'><?php echo html::input('name', '', "class='form-control'"); ?></td>
<td></td>
</tr>
<tr class='hide-gitlab'>
<tr class='hide-service'>
<th><?php echo $lang->repo->path; ?></th>
<td class='required'><?php echo html::input('path', '', "class='form-control'"); ?></td>
<td class='muted'>
@@ -58,7 +58,7 @@
<td class='required'><?php echo html::input('encoding', 'utf-8', "class='form-control'"); ?></td>
<td class='muted'><?php echo $lang->repo->encodingsTips; ?></td>
</tr>
<tr class='hide-gitlab'>
<tr class='hide-service'>
<th><?php echo $lang->repo->client;?></th>
<td class='required'><?php echo html::input('client', '', "class='form-control'")?></td>
<td class='muted'>
@@ -66,11 +66,11 @@
<span class="tips-svn"><?php echo $lang->repo->example->client->svn;?></span>
</td>
</tr>
<tr class="account-fields hide-gitlab">
<tr class="account-fields hide-service">
<th><?php echo $lang->repo->account;?></th>
<td><?php echo html::input('account', '', "class='form-control'");?></td>
</tr>
<tr class="account-fields hide-gitlab">
<tr class="account-fields hide-service">
<th><?php echo $lang->repo->password;?></th>
<td>
<div class='input-group'>
+10 -10
View File
@@ -36,20 +36,20 @@
<td style="width:550px"><?php echo html::select('SCM', $lang->repo->scmList, $repo->SCM, "onchange='scmChanged(this.value)' class='form-control chosen'"); ?></td>
<td><span class="tips-git"><?php echo $lang->repo->syncTips; ?></span></td>
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabHost;?></th>
<td class='required'><?php echo html::select('gitlabHost', $gitlabHosts, isset($repo->gitlab) ? $repo->gitlab : '', "class='form-control chosen' placeholder='{$lang->repo->placeholder->gitlabHost}'");?></td>
<tr class='service hide'>
<th><?php echo $lang->repo->serviceHost;?></th>
<td class='required'><?php echo html::select('serviceHost', $serviceHosts, isset($repo->gitService) ? $repo->gitService : '', "class='form-control chosen'");?></td>
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabProject;?></th>
<td class='required'><?php echo html::select('gitlabProject', $projects, isset($repo->project) ? $repo->project : '', "class='form-control chosen'");?></td>
<tr class='service hide'>
<th><?php echo $lang->repo->serviceProject;?></th>
<td class='required'><?php echo html::select('serviceProject', $projects, isset($repo->project) ? $repo->project : '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->repo->name; ?></th>
<td class='required'><?php echo html::input('name', $repo->name, "class='form-control'"); ?></td>
<td></td>
</tr>
<tr class='hide-gitlab'>
<tr class='hide-service'>
<th><?php echo $lang->repo->path; ?></th>
<td class='required'><?php echo html::input('path', $repo->path, "class='form-control'"); ?></td>
<td class='muted'>
@@ -62,7 +62,7 @@
<td class='required'><?php echo html::input('encoding', $repo->encoding, "class='form-control'"); ?></td>
<td class='muted'><?php echo $lang->repo->encodingsTips; ?></td>
</tr>
<tr class='hide-gitlab'>
<tr class='hide-service'>
<th><?php echo $lang->repo->client;?></th>
<td class='required'><?php echo html::input('client', $repo->client, "class='form-control'")?></td>
<td class='muted'>
@@ -70,11 +70,11 @@
<span class="tips-svn"><?php echo $lang->repo->example->client->svn;?></span>
</td>
</tr>
<tr class="account-fields hide-gitlab">
<tr class="account-fields hide-service">
<th><?php echo $lang->repo->account;?></th>
<td><?php echo html::input('account', $repo->account, "class='form-control'");?></td>
</tr>
<tr class="account-fields hide-gitlab">
<tr class="account-fields hide-service">
<th><?php echo $lang->repo->password;?></th>
<td>
<div class='input-group'>
+5 -1
View File
@@ -51,7 +51,9 @@
<table class='table table-fixed' id='logList'>
<thead>
<tr>
<?php if($repo->SCM != 'Gitea'):?>
<th class='w-40px'></th>
<?php endif;?>
<th class='w-110px'><?php echo $lang->repo->revision?></th>
<?php if($repo->SCM != 'Subversion'):?>
<th class='w-90px'><?php echo $lang->repo->commit?></th>
@@ -64,12 +66,14 @@
<tbody>
<?php foreach($logs as $log):?>
<tr>
<?php if($repo->SCM != 'Gitea'):?>
<td>
<div class='checkbox-primary'>
<input type='checkbox' name='revision[]' value="<?php echo $log->revision?>" />
<label></label>
</div>
</td>
<?php endif;?>
<td class='versions'><?php echo html::a($this->repo->createLink('revision', "repoID=$repoID&objectID=$objectID&revision=" . $log->revision), substr($log->revision, 0, 10), '', "data-app='{$app->tab}'");?></td>
<?php if($repo->SCM != 'Subversion'):?>
<td><?php echo $log->commit?></td>
@@ -82,7 +86,7 @@
</tbody>
</table>
<div class='table-footer'>
<?php if(common::hasPriv('repo', 'diff')) echo html::submitButton($lang->repo->diff, '', count($logs) < 2 ? 'disabled btn btn-primary' : 'btn btn-primary')?>
<?php if($repo->SCM != 'Gitea' and common::hasPriv('repo', 'diff')) echo html::submitButton($lang->repo->diff, '', count($logs) < 2 ? 'disabled btn btn-primary' : 'btn btn-primary')?>
<?php $pager->show('right', 'pagerjs');?>
</div>
</form>
+1 -1
View File
@@ -57,7 +57,7 @@ $version = " <span class=\"label label-info\">$revisionName</span>";
<div class='panel-actions'>
<?php if($suffix != 'binary' and strpos($config->repo->images, "|$suffix|") === false):?>
<?php
if(common::hasPriv('repo', 'blame')) echo html::a($this->repo->createLink('blame', "repoID=$repoID&objectID=$objectID&entry=$encodePath&revision=$revision&encoding=$encoding"), html::icon('random') . $lang->repo->blame, '', "class='btn btn-sm btn-primary' data-app='{$app->tab}'");
if($repo->SCM != 'Gitea' and common::hasPriv('repo', 'blame')) echo html::a($this->repo->createLink('blame', "repoID=$repoID&objectID=$objectID&entry=$encodePath&revision=$revision&encoding=$encoding"), html::icon('random') . $lang->repo->blame, '', "class='btn btn-sm btn-primary' data-app='{$app->tab}'");
if(common::hasPriv('repo', 'download')) echo html::a($this->repo->createLink('download', "repoID=$repoID&path=$encodePath&fromRevision=$revision"), html::icon('download-alt') . $lang->repo->download, 'hiddenwin', "class='btn btn-sm btn-primary'");
?>
<?php endif;?>