Skip to content

Commit

Permalink
[MM-21749] [MM-22214] Add "Beta" and "Community" label (#37)
Browse files Browse the repository at this point in the history
* Add beta and community label

* wording

* Feedback
  • Loading branch information
hanzei authored Feb 5, 2020
1 parent 5cd1b46 commit 66ba199
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
35 changes: 33 additions & 2 deletions cmd/generator/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (

func init() {
generatorCmd.AddCommand(addCmd)

addCmd.Flags().Bool("beta", false, "Mark release as Beta")
addCmd.Flags().Bool("official", false, "Mark this plugin as maintanied by Mattermost")
addCmd.Flags().Bool("community", false, "Mark this plugin as maintanied by the Open Source Community")
}

var addCmd = &cobra.Command{
Expand All @@ -28,11 +32,29 @@ var addCmd = &cobra.Command{
RunE: func(command *cobra.Command, args []string) error {
command.SilenceUsage = true

err := InitCommand(command)
official, err := command.Flags().GetBool("official")
if err != nil {
return err
}

community, err := command.Flags().GetBool("community")
if err != nil {
return err
}

if official == community {
return errors.New("you must either set the release as a official or as a community plugin")
}

beta, err := command.Flags().GetBool("beta")
if err != nil {
return err
}

if err = InitCommand(command); err != nil {
return err
}

dbFile, err := command.Flags().GetString("database")
if err != nil {
return err
Expand Down Expand Up @@ -81,12 +103,21 @@ var addCmd = &cobra.Command{
return errors.Wrap(err, "failed to download plugin signature")
}

labels := []model.Label{}
if beta {
labels = append(labels, model.BetaLabel)
}

if community {
labels = append(labels, model.CommunityLabel)
}

plugin := &model.Plugin{
HomepageURL: manifest.HomepageURL,
IconData: iconData,
DownloadURL: bundleURL,
ReleaseNotesURL: manifest.ReleaseNotesURL,
Labels: nil,
Labels: labels,
Signature: signature,
Manifest: manifest,
UpdatedAt: time.Now().In(time.UTC),
Expand Down
2 changes: 1 addition & 1 deletion internal/api/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func initLabels(apiRouter *mux.Router, context *Context) {

// handleGetPlugins responds to GET /api/v1/labels, returning a list of all defined labels.
func handleGetLabels(c *Context, w http.ResponseWriter, r *http.Request) {
response := []model.Label{}
response := model.AllLabels

w.Header().Set("Content-Type", "application/json")
outputJSON(c, w, response)
Expand Down
5 changes: 1 addition & 4 deletions internal/api/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ func TestGetLabels(t *testing.T) {
var respose []model.Label
err := json.NewDecoder(result.Body).Decode(&respose)
require.NoError(t, err)

expectedResponse := []model.Label{}

assert.Equal(t, expectedResponse, respose)
assert.Equal(t, model.AllLabels, respose)
}
17 changes: 17 additions & 0 deletions internal/model/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ type Label struct {
URL string `json:"url"`
Color string `json:"color"`
}

var AllLabels = []Label{
CommunityLabel,
BetaLabel,
}

var CommunityLabel Label = Label{
Name: "Community",
Description: "This plugin is maintained by the Open Source Community.",
URL: "https://mattermost.com/pl/default-community-plugins",
}

var BetaLabel Label = Label{
Name: "Beta",
Description: "This plugin is currently in Beta and is not recommended for use in production.",
URL: "https://mattermost.com/pl/default-beta-plugins",
}

0 comments on commit 66ba199

Please sign in to comment.