From 726c8605fcbe85cb0601fcad0f8146e1ea315821 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 10 Jan 2022 09:03:26 -0300 Subject: [PATCH] Bug 29787: Add plugin version to plugin search results This patch adds a new column to plugins search results: 'Latest version'. It takes the tag_name in both GitHub and GitLab cases and passes it to the template. To test: 1. Have this on your koha-conf.xml file: ByWater Solutions bywatersolutions github Theke Solutions thekesolutions gitlab PTFS Europe ptfs-europe github 2. Restart all services: $ restart_all 3. Search for the term 'barclaycard' => SUCCESS: You get results from PTFS Europe (Github) => FAIL: They don't include plugin version 4. Search for the term 'innreach' => SUCCESS: You get results from Theke (Gitlab) => FAIL: They don't include plugin version 5. Apply this patch 6. Repeat 2-4 => SUCCESS: Results show up => SUCCESS: Results include the plugin version 7. Sign off :-D Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- .../prog/en/modules/plugins/plugins-home.tt | 2 ++ plugins/plugins-home.pl | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt index 08e78a0c2a..715c91a033 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt @@ -77,6 +77,7 @@ Name Description Organization + Latest version   @@ -86,6 +87,7 @@ [% sr.result.name | html %] [% sr.result.description | html %] [% sr.repo.name | html %] + [% sr.result.tag_name | html %] Install [% END %] diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl index da892ba1f2..c67156222d 100755 --- a/plugins/plugins-home.pl +++ b/plugins/plugins-home.pl @@ -77,11 +77,13 @@ if ($plugins_enabled) { foreach my $result ( @{ $response->{items} } ) { next unless $result->{name} =~ /^koha-plugin-/; my $releases = $result->{url} . "/releases/latest"; - my $release = from_json( get($releases) ); + my $release = from_json( get($releases) ); + my $tag_name = $release->{tag_name}; for my $asset ( @{$release->{assets}} ) { if ($asset->{browser_download_url} =~ m/\.kpz$/) { $result->{install_name} = $asset->{name}; - $result->{install_url} = $asset->{browser_download_url}; + $result->{install_url} = $asset->{browser_download_url}; + $result->{tag_name} = $tag_name; } } push( @results, { repo => $r, result => $result } ); @@ -100,12 +102,14 @@ if ($plugins_enabled) { my @releases = @{ from_json( get($releases_url) ) }; if ( scalar @releases > 0 ) { + # Pick the first one, the latest release - my $latest = $releases[0]; - my $name = $latest->{name}; - my @links = @{$latest->{assets}->{links}}; - my $url = $links[0]->{direct_asset_url}; - my @parts = split( '/', $url); + my $latest = $releases[0]; + my $name = $latest->{name}; + my $tag_name = $latest->{tag_name}; + my @links = @{ $latest->{assets}->{links} }; + my $url = $links[0]->{direct_asset_url}; + my @parts = split( '/', $url ); my $filename = $parts[-1]; next unless $url =~ m/\.kpz$/; my $result = { @@ -114,6 +118,7 @@ if ($plugins_enabled) { install_url => $url, html_url => $web_url, name => $name, + tag_name => $tag_name, }; push @results, { repo => $r, result => $result }; } -- 2.39.5