port from gitlab to gitea (done, untested)

Done: port to gitea API; Broken: filter commits since date
This commit is contained in:
root 2023-09-23 15:26:08 +02:00
parent 18f7d56fcd
commit 7642f91b18

View File

@ -32,7 +32,7 @@ class LinuxfooGitlab {
return
'<span class="project_header">'.
__('Gitea project', 'linuxfoo-gitea').' '.
'<a href="'.$project->web_url.'">'.$project->name.'</a>'.
'<a href="'.$project->html_url.'">'.$project->name.'</a>'.
'</span>';
}
@ -62,12 +62,12 @@ class LinuxfooGitlab {
if($atts['author']==null || $atts['author']!='none')
$result .=
__('by', 'linuxfoo-gitea').' '.$commit->author_name;
__('by', 'linuxfoo-gitea').' '.$commit->commit->author->name;
$result .=
': '.
'<a href="'.$commit->web_url.'">'.$commit->short_id.'</a> '.
htmlspecialchars($commit->title, ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE);
'<a href="'.$commit->html_url.'">'.substr($commit->sha, 0, 8).'</a> '.
htmlspecialchars(explode("\n", $commit->message)[0], ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE);
return $result;
}
@ -93,29 +93,17 @@ class LinuxfooGitlab {
elseif(!is_null($atts['commits']) && $atts['commits']!='all') {
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 = '';
$commits_url = $project_url.'/repository/commits?';
if(!is_null($since)) {
$commits_url .= '&since='.$since;
}
$commits_url = $project_url.'/commits?stat=false&verification=false&files=false';
if(!is_null($atts['ref_name'])) {
$commits_url .= '&ref_name='.$atts['ref_name'];
$commits_url .= '&sha='.$atts['ref_name'];
$branch = $atts['ref_name'];
}
elseif(!is_null($atts['default_branch'])) {
$commits_url .= '&ref_name='.$project->default_branch;
elseif(!is_null($project->default_branch)) {
$commits_url .= '&sha='.$project->default_branch;
$branch = $project->default_branch;
}
else {
@ -191,7 +179,7 @@ class LinuxfooGitlab {
$out .=
'<span class="releases">'.
__('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>';
}
elseif($atts['releases']=='all') {
@ -204,7 +192,7 @@ class LinuxfooGitlab {
foreach($releases as $release) {
$out .=
'<span class="release">'.
'<a href="'.$release->_links->self.'">'.$release->name.'</a>'.
'<a href="'.$release->html_url.'">'.$release->name.'</a>'.
'</span>';
}
@ -228,21 +216,16 @@ class LinuxfooGitlab {
if(
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'));
}
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)) {
$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 {
$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);
if(is_null($project_json)) {