forked from tk-sls.de/linuxfoo-gitlab
port from gitlab to gitea (done, untested)
Done: port to gitea API; Broken: filter commits since date
This commit is contained in:
parent
18f7d56fcd
commit
7642f91b18
@ -32,7 +32,7 @@ class LinuxfooGitlab {
|
|||||||
return
|
return
|
||||||
'<span class="project_header">'.
|
'<span class="project_header">'.
|
||||||
__('Gitea project', 'linuxfoo-gitea').' '.
|
__('Gitea project', 'linuxfoo-gitea').' '.
|
||||||
'<a href="'.$project->web_url.'">'.$project->name.'</a>'.
|
'<a href="'.$project->html_url.'">'.$project->name.'</a>'.
|
||||||
'</span>';
|
'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,12 +62,12 @@ class LinuxfooGitlab {
|
|||||||
|
|
||||||
if($atts['author']==null || $atts['author']!='none')
|
if($atts['author']==null || $atts['author']!='none')
|
||||||
$result .=
|
$result .=
|
||||||
__('by', 'linuxfoo-gitea').' '.$commit->author_name;
|
__('by', 'linuxfoo-gitea').' '.$commit->commit->author->name;
|
||||||
|
|
||||||
$result .=
|
$result .=
|
||||||
': '.
|
': '.
|
||||||
'<a href="'.$commit->web_url.'">'.$commit->short_id.'</a> '.
|
'<a href="'.$commit->html_url.'">'.substr($commit->sha, 0, 8).'</a> '.
|
||||||
htmlspecialchars($commit->title, ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE);
|
htmlspecialchars(explode("\n", $commit->message)[0], ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -93,29 +93,17 @@ class LinuxfooGitlab {
|
|||||||
elseif(!is_null($atts['commits']) && $atts['commits']!='all') {
|
elseif(!is_null($atts['commits']) && $atts['commits']!='all') {
|
||||||
return self::error(__('Invalid value for parameter "commits".', 'linuxfoo-gitea'));
|
return self::error(__('Invalid value for parameter "commits".', 'linuxfoo-gitea'));
|
||||||
}
|
}
|
||||||
elseif(!is_null($atts['since'])) {
|
|
||||||
if(!preg_match('/^[1-9][0-9]*\s+(days|months|years)$/', $atts['since'])) {
|
|
||||||
return self::error(__('Invalid value for parameter "since".', 'linuxfoo-gitea'));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$since = date(DATE_ISO8601, strtotime('-'.$atts['since']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$out = '';
|
$out = '';
|
||||||
|
|
||||||
$commits_url = $project_url.'/repository/commits?';
|
$commits_url = $project_url.'/commits?stat=false&verification=false&files=false';
|
||||||
|
|
||||||
if(!is_null($since)) {
|
|
||||||
$commits_url .= '&since='.$since;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!is_null($atts['ref_name'])) {
|
if(!is_null($atts['ref_name'])) {
|
||||||
$commits_url .= '&ref_name='.$atts['ref_name'];
|
$commits_url .= '&sha='.$atts['ref_name'];
|
||||||
$branch = $atts['ref_name'];
|
$branch = $atts['ref_name'];
|
||||||
}
|
}
|
||||||
elseif(!is_null($atts['default_branch'])) {
|
elseif(!is_null($project->default_branch)) {
|
||||||
$commits_url .= '&ref_name='.$project->default_branch;
|
$commits_url .= '&sha='.$project->default_branch;
|
||||||
$branch = $project->default_branch;
|
$branch = $project->default_branch;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -191,7 +179,7 @@ class LinuxfooGitlab {
|
|||||||
$out .=
|
$out .=
|
||||||
'<span class="releases">'.
|
'<span class="releases">'.
|
||||||
__('Latest release', 'linuxfoo-gitea').': '.
|
__('Latest release', 'linuxfoo-gitea').': '.
|
||||||
'<a href="'.$releases[0]->_links->self.'">'.$releases[0]->name.'</a>'.
|
'<a href="'.$releases[0]->html_url.'">'.$releases[0]->name.'</a>'.
|
||||||
'</span>';
|
'</span>';
|
||||||
}
|
}
|
||||||
elseif($atts['releases']=='all') {
|
elseif($atts['releases']=='all') {
|
||||||
@ -204,7 +192,7 @@ class LinuxfooGitlab {
|
|||||||
foreach($releases as $release) {
|
foreach($releases as $release) {
|
||||||
$out .=
|
$out .=
|
||||||
'<span class="release">'.
|
'<span class="release">'.
|
||||||
'<a href="'.$release->_links->self.'">'.$release->name.'</a>'.
|
'<a href="'.$release->html_url.'">'.$release->name.'</a>'.
|
||||||
'</span>';
|
'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,21 +216,16 @@ class LinuxfooGitlab {
|
|||||||
|
|
||||||
if(
|
if(
|
||||||
is_null($atts['url']) ||
|
is_null($atts['url']) ||
|
||||||
is_null($atts['project_id'])
|
is_null($atts['project_owner']) ||
|
||||||
|
is_null($atts['project_repo'])
|
||||||
) {
|
) {
|
||||||
$out .= self::error(__('Required parameter missing.', 'linuxfoo-gitea'));
|
$out .= self::error(__('Required parameter missing.', 'linuxfoo-gitea'));
|
||||||
}
|
}
|
||||||
elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) {
|
|
||||||
$out .= self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitea'));
|
|
||||||
}
|
|
||||||
elseif(!filter_var($atts['url'], FILTER_VALIDATE_URL)) {
|
elseif(!filter_var($atts['url'], FILTER_VALIDATE_URL)) {
|
||||||
$out .= self::error(__('Invalid value for parameter "url".', 'linuxfoo-gitea'));
|
$out .= self::error(__('Invalid value for parameter "url".', 'linuxfoo-gitea'));
|
||||||
}
|
}
|
||||||
elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) {
|
|
||||||
$out .= self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitea'));
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
$project_url = $atts['url'].'/api/v4/projects/'.$atts['project_id'];
|
$project_url = $atts['url'].'/api/v1/repos/'.$atts['project_owner'].'/'.$atts['project_repo'];
|
||||||
$project_json = file_get_contents($project_url);
|
$project_json = file_get_contents($project_url);
|
||||||
|
|
||||||
if(is_null($project_json)) {
|
if(is_null($project_json)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user