implement releases=all|latest

This commit is contained in:
Tilman Kranz 2021-11-27 16:50:41 +01:00
parent 165ebeb13d
commit 520bf8d107
4 changed files with 118 additions and 15 deletions

View File

@ -96,3 +96,27 @@ msgstr "im Branch"
#: linuxfoo-gitlab.php:146 #: linuxfoo-gitlab.php:146
msgid "Last %d commits" msgid "Last %d commits"
msgstr "Letzte %d Commits" msgstr "Letzte %d Commits"
#: linuxfoo-gitlab.php:172
msgid "Invalid value for parameter \"releases\"."
msgstr "Unzulässiger Wert für Parameter \"releases\"."
#: linuxfoo-gitlab.php:179
msgid "Releases URL not reachable."
msgstr "Releases-URL nicht erreichbar."
#: linuxfoo-gitlab.php:185
msgid "Releases information not readable."
msgstr "Releases-Information nicht lesbar."
#: linuxfoo-gitlab.php:189
msgid "This project has currently no releases."
msgstr "Dieses Projekt hat derzeit keine Releases."
#: linuxfoo-gitlab.php:194
msgid "Latest release"
msgstr "Neueste Release"
#: linuxfoo-gitlab.php:201
msgid "Releases"
msgstr "Releases"

View File

@ -9,7 +9,7 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2021-11-27T12:01:58+01:00\n" "POT-Creation-Date: 2021-11-27T16:45:29+01:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.5.0\n" "X-Generator: WP-CLI 2.5.0\n"
"X-Domain: linuxfoo-gitlab\n" "X-Domain: linuxfoo-gitlab\n"
@ -51,49 +51,73 @@ msgstr ""
msgid "since %d %s ago" msgid "since %d %s ago"
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:59 #: linuxfoo-gitlab.php:63
msgid "Required parameter missing." msgid "Required parameter missing."
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:62 #: linuxfoo-gitlab.php:66
#: linuxfoo-gitlab.php:68 #: linuxfoo-gitlab.php:72
msgid "Invalid value for parameter \"project_id\"." msgid "Invalid value for parameter \"project_id\"."
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:65 #: linuxfoo-gitlab.php:69
msgid "Invalid value for parameter \"url\"." msgid "Invalid value for parameter \"url\"."
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:75 #: linuxfoo-gitlab.php:79
msgid "Project URL not reachable." msgid "Project URL not reachable."
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:86 #: linuxfoo-gitlab.php:90
msgid "Gitlab project" msgid "Gitlab project"
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:93 #: linuxfoo-gitlab.php:97
msgid "Invalid value for parameter \"since\"." msgid "Invalid value for parameter \"since\"."
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:115 #: linuxfoo-gitlab.php:119
msgid "Commits URL not reachable." msgid "Commits URL not reachable."
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:121 #: linuxfoo-gitlab.php:125
msgid "Commits information not readable." msgid "Commits information not readable."
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:132 #: linuxfoo-gitlab.php:136
msgid "No commits" msgid "No commits"
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:133 #: linuxfoo-gitlab.php:137
#: linuxfoo-gitlab.php:147 #: linuxfoo-gitlab.php:151
msgid "in branch" msgid "in branch"
msgstr "" msgstr ""
#. translators: %d: maximum number of commits displayed #. translators: %d: maximum number of commits displayed
#: linuxfoo-gitlab.php:146 #: linuxfoo-gitlab.php:150
msgid "Last %d commits" msgid "Last %d commits"
msgstr "" msgstr ""
#: linuxfoo-gitlab.php:172
msgid "Invalid value for parameter \"releases\"."
msgstr ""
#: linuxfoo-gitlab.php:179
msgid "Releases URL not reachable."
msgstr ""
#: linuxfoo-gitlab.php:185
msgid "Releases information not readable."
msgstr ""
#: linuxfoo-gitlab.php:189
msgid "This project has currently no releases."
msgstr ""
#: linuxfoo-gitlab.php:194
msgid "Latest release"
msgstr ""
#: linuxfoo-gitlab.php:201
msgid "Releases"
msgstr ""

View File

@ -50,6 +50,10 @@ class LinuxfooGitlab {
} }
static function list_commits($atts, $content, $tag) { static function list_commits($atts, $content, $tag) {
return self::show_project($atts, $content, $tag);
}
static function show_project($atts, $content, $tag) {
global $post; global $post;
if( if(
@ -117,7 +121,7 @@ class LinuxfooGitlab {
$commits = json_decode($commits_json); $commits = json_decode($commits_json);
if(is_null($project)) { if(is_null($commits)) {
return self::error(__('Commits information not readable.', 'linuxfoo-gitlab')); return self::error(__('Commits information not readable.', 'linuxfoo-gitlab'));
} }
@ -162,6 +166,53 @@ class LinuxfooGitlab {
} }
$out .= '</ul>'; $out .= '</ul>';
if(!is_null($atts['releases'])) {
if(!preg_match('/^(all|latest)$/', $atts['releases'])) {
return self::error(__('Invalid value for parameter "releases".', 'linuxfoo-gitlab'));
}
$releases_url = $project_url.'/releases?';
$releases_json = file_get_contents($releases_url);
if(is_null($releases_json)) {
return self::error(__('Releases URL not reachable.', 'linuxfoo-gitlab'));
}
$releases = json_decode($releases_json);
if(is_null($releases)) {
return self::error(__('Releases information not readable.', 'linuxfoo-gitlab'));
}
if(count($releases)==0) {
$out .= '<p class="releases">'.__('This project has currently no releases.', 'linuxfoo-gitlab').'</p>';
}
elseif($atts['releases']=='latest') {
$out .=
'<p class="releases">'.
__('Latest release', 'linuxfoo-gitlab').': '.
'<a href="'.$releases[0]->evidences->_links->self.'">'.$releases[0]->name.'</a>'.
'</p>';
}
elseif($atts['releases']=='all') {
$out .=
'<p class="releases">'.
__('Releases', 'linuxfoo-gitlab').': '.
'</p>'.
'<ul class="releases">';
foreach($releases as $release) {
$out .=
'<li>'.
'<a href="'.$release->evidences->_links->self.'">'.$release->name.'</a>'.
'</li>';
}
$out .= '</ul>';
}
}
$out .= '</div>'; $out .= '</div>';
return $out; return $out;
@ -171,4 +222,5 @@ class LinuxfooGitlab {
add_action('plugins_loaded', 'LinuxfooGitlab::load_textdomain'); add_action('plugins_loaded', 'LinuxfooGitlab::load_textdomain');
add_action('wp_enqueue_scripts', 'LinuxfooGitlab::css' ); add_action('wp_enqueue_scripts', 'LinuxfooGitlab::css' );
add_shortcode('gitlab-list-commits', 'LinuxfooGitlab::list_commits'); add_shortcode('gitlab-list-commits', 'LinuxfooGitlab::list_commits');
add_shortcode('gitlab-show-project', 'LinuxfooGitlab::show_project');

View File

@ -6,6 +6,9 @@
.linuxfoo_gitlab .commits { .linuxfoo_gitlab .commits {
margin: .25em 0 .25em 0; margin: .25em 0 .25em 0;
} }
.linuxfoo_gitlab .releases {
margin: .25em 0 .25em 0;
}
.linuxfoo_gitlab .project_header { .linuxfoo_gitlab .project_header {
display: block; display: block;
} }