Chore: Avoid showing plugin version if it's %VERSION% (#75974)

This commit is contained in:
Andres Martinez Gotor 2023-10-11 10:49:30 +02:00 committed by GitHub
parent d5691e6dd1
commit 1f8b08202e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 4 deletions

View File

@ -30,6 +30,7 @@ func DefaultConstructFunc(signatureCalculator plugins.SignatureCalculator, asset
func DefaultDecorateFuncs(cfg *config.Cfg) []DecorateFunc {
return []DecorateFunc{
AppDefaultNavURLDecorateFunc,
TemplateDecorateFunc,
AppChildDecorateFunc(cfg),
}
}
@ -86,6 +87,22 @@ func AppDefaultNavURLDecorateFunc(_ context.Context, p *plugins.Plugin) (*plugin
return p, nil
}
// TemplateDecorateFunc is a DecorateFunc that removes the placeholder for the version and last_update fields.
func TemplateDecorateFunc(_ context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
// %VERSION% and %TODAY% are valid values, according to the plugin schema
// but it's meant to be replaced by the build system with the actual version and date.
// If not, it's the same than not having a version or a date.
if p.Info.Version == "%VERSION%" {
p.Info.Version = ""
}
if p.Info.Updated == "%TODAY%" {
p.Info.Updated = ""
}
return p, nil
}
func setDefaultNavURL(p *plugins.Plugin) {
// slugify pages
for _, include := range p.Includes {

View File

@ -1,6 +1,7 @@
package bootstrap
import (
"context"
"testing"
"github.com/stretchr/testify/require"
@ -66,6 +67,34 @@ func TestSetDefaultNavURL(t *testing.T) {
})
}
func TestTemplateDecorateFunc(t *testing.T) {
t.Run("Removes %VERSION%", func(t *testing.T) {
pluginWithoutVersion := &plugins.Plugin{
JSONData: plugins.JSONData{
Info: plugins.Info{
Version: "%VERSION%",
},
},
}
p, err := TemplateDecorateFunc(context.TODO(), pluginWithoutVersion)
require.NoError(t, err)
require.Equal(t, "", p.Info.Version)
})
t.Run("Removes %TODAY%", func(t *testing.T) {
pluginWithoutVersion := &plugins.Plugin{
JSONData: plugins.JSONData{
Info: plugins.Info{
Version: "%TODAY%",
},
},
}
p, err := TemplateDecorateFunc(context.TODO(), pluginWithoutVersion)
require.NoError(t, err)
require.Equal(t, "", p.Info.Updated)
})
}
func Test_configureAppChildPlugin(t *testing.T) {
t.Run("When setting paths based on core plugin on Windows", func(t *testing.T) {
child := &plugins.Plugin{

View File

@ -1335,8 +1335,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
},
Screenshots: []plugins.Screenshots{},
Description: "Grafana App Plugin Template",
Version: "%VERSION%",
Updated: "%TODAY%",
Version: "",
Updated: "",
},
Dependencies: plugins.Dependencies{
GrafanaVersion: "7.0.0",
@ -1415,8 +1415,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
},
Screenshots: []plugins.Screenshots{},
Description: "Grafana Panel Plugin Template",
Version: "%VERSION%",
Updated: "%TODAY%",
Version: "",
Updated: "",
},
Dependencies: plugins.Dependencies{
GrafanaDependency: ">=7.0.0",