diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c9cb840..8e16d79 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -34,7 +34,7 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v2 with: - version: v1.43.0 + version: v1.46.2 args: --timeout 10m - name: Vet diff --git a/README.md b/README.md index 4b9c3bc..1923abb 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,7 @@ newreleases hangouts-chat newreleases microsoft-teams newreleases mattermost newreleases rocketchat +newreleases matrix newreleases webhook ``` diff --git a/go.mod b/go.mod index 11ff2af..c348c55 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/spf13/viper v1.10.1 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 jaytaylor.com/html2text v0.0.0-20211105163654-bc68cce691ba - newreleases.io/newreleases v1.8.0 + newreleases.io/newreleases v1.9.0 ) require ( diff --git a/go.sum b/go.sum index b2cd6f6..338d835 100644 --- a/go.sum +++ b/go.sum @@ -815,8 +815,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= jaytaylor.com/html2text v0.0.0-20211105163654-bc68cce691ba h1:3xhBI8FZepFq4YtdqlW6Z8YzdKM3nAV9xpOvgzWX+us= jaytaylor.com/html2text v0.0.0-20211105163654-bc68cce691ba/go.mod h1:OxvTsCwKosqQ1q7B+8FwXqg4rKZ/UG9dUW+g/VL2xH4= -newreleases.io/newreleases v1.8.0 h1:QMf7R2hAr4kMmYcMjeWu0jiQww52GB7uohCSr3BhlRI= -newreleases.io/newreleases v1.8.0/go.mod h1:IFoaLRTd4ZNVIEIZflkjRt+0Z4BOgivteiLGs9vPobw= +newreleases.io/newreleases v1.9.0 h1:5Nuk4UBQ5WZdiuwtNCUNzCeRa/1gyK4Dp+YneRdYcYI= +newreleases.io/newreleases v1.9.0/go.mod h1:IFoaLRTd4ZNVIEIZflkjRt+0Z4BOgivteiLGs9vPobw= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/newreleases/cmd/cmd.go b/newreleases/cmd/cmd.go index 45f28a0..76156a6 100644 --- a/newreleases/cmd/cmd.go +++ b/newreleases/cmd/cmd.go @@ -47,6 +47,7 @@ type command struct { microsoftTeamsWebhooksService microsoftTeamsWebhooksService mattermostWebhooksService mattermostWebhooksService rocketchatWebhooksService rocketchatWebhooksService + matrixRoomsService matrixRoomsService webhooksService webhooksService tagsService tagsService } @@ -110,6 +111,9 @@ More information at https://newreleases.io.`, if err := c.initRocketchatCmd(); err != nil { return nil, err } + if err := c.initMatrixCmd(); err != nil { + return nil, err + } if err := c.initWebhookCmd(); err != nil { return nil, err } diff --git a/newreleases/cmd/cmd_test.go b/newreleases/cmd/cmd_test.go index 99b66f5..3f8f3e0 100644 --- a/newreleases/cmd/cmd_test.go +++ b/newreleases/cmd/cmd_test.go @@ -8,7 +8,6 @@ package cmd_test import ( "errors" "fmt" - "io/ioutil" "os" "regexp" "testing" @@ -22,7 +21,7 @@ var homeDir string var errTest = errors.New("test error") func TestMain(m *testing.M) { - dir, err := ioutil.TempDir("", "newreleases-cmd-") + dir, err := os.MkdirTemp("", "newreleases-cmd-") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/newreleases/cmd/configure_test.go b/newreleases/cmd/configure_test.go index 6a4d1b1..8d7b2f8 100644 --- a/newreleases/cmd/configure_test.go +++ b/newreleases/cmd/configure_test.go @@ -8,7 +8,6 @@ package cmd_test import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -67,11 +66,7 @@ func TestConfigureCmd(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "newreleases-cmd-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) + dir := t.TempDir() cfgFile := filepath.Join(dir, ".newreleases.yaml") if !tc.newConfig { @@ -122,7 +117,7 @@ func TestConfigureCmd(t *testing.T) { } if tc.wantData != "" { - gotData, err := ioutil.ReadFile(cfgFile) + gotData, err := os.ReadFile(cfgFile) if err != nil { t.Fatal(err) } @@ -130,7 +125,7 @@ func TestConfigureCmd(t *testing.T) { t.Errorf("got config file data %q, want %q", string(gotData), tc.wantData) } } else { - gotData, _ := ioutil.ReadFile(cfgFile) + gotData, _ := os.ReadFile(cfgFile) if string(gotData) != "" { t.Errorf("got config file data %q, but it should not be", string(gotData)) } @@ -140,11 +135,7 @@ func TestConfigureCmd(t *testing.T) { } func TestConfigureCmd_overwrite(t *testing.T) { - dir, err := ioutil.TempDir("", "newreleases-cmd-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) + dir := t.TempDir() cfgFile := filepath.Join(dir, ".newreleases.yaml") f, err := os.Create(cfgFile) @@ -175,7 +166,7 @@ func TestConfigureCmd_overwrite(t *testing.T) { t.Errorf("got output %q, want %q", gotOutput, wantOutput) } - gotData, err := ioutil.ReadFile(cfgFile) + gotData, err := os.ReadFile(cfgFile) if err != nil { t.Fatal(err) } diff --git a/newreleases/cmd/export_test.go b/newreleases/cmd/export_test.go index 14f45d1..44566e4 100644 --- a/newreleases/cmd/export_test.go +++ b/newreleases/cmd/export_test.go @@ -23,6 +23,7 @@ type ( MicrosoftTeamsWebhooksService = microsoftTeamsWebhooksService MattermostWebhooksService = mattermostWebhooksService RocketchatWebhooksService = rocketchatWebhooksService + MatrixRoomsService = matrixRoomsService WebhooksService = webhooksService TagsService = tagsService ) @@ -145,6 +146,12 @@ func WithRocketchatWebhooksService(s RocketchatWebhooksService) func(c *Command) } } +func WithMatrixRoomsService(s MatrixRoomsService) func(c *Command) { + return func(c *Command) { + c.matrixRoomsService = s + } +} + func WithWebhooksService(s WebhooksService) func(c *Command) { return func(c *Command) { c.webhooksService = s diff --git a/newreleases/cmd/get_auth_key_test.go b/newreleases/cmd/get_auth_key_test.go index 6fcf175..a16c9f3 100644 --- a/newreleases/cmd/get_auth_key_test.go +++ b/newreleases/cmd/get_auth_key_test.go @@ -9,7 +9,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -143,11 +142,7 @@ func TestGetAuthKeyCmd(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "newreleases-cmd-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) + dir := t.TempDir() cfgFile := filepath.Join(dir, ".newreleases.yaml") if !tc.newConfig { @@ -200,7 +195,7 @@ func TestGetAuthKeyCmd(t *testing.T) { } if tc.wantData != "" { - gotData, err := ioutil.ReadFile(cfgFile) + gotData, err := os.ReadFile(cfgFile) if err != nil { t.Fatal(err) } @@ -208,7 +203,7 @@ func TestGetAuthKeyCmd(t *testing.T) { t.Errorf("got config file data %q, want %q", string(gotData), tc.wantData) } } else { - gotData, _ := ioutil.ReadFile(cfgFile) + gotData, _ := os.ReadFile(cfgFile) if string(gotData) != "" { t.Errorf("got config file data %q, but it should not be", string(gotData)) } diff --git a/newreleases/cmd/matrix.go b/newreleases/cmd/matrix.go new file mode 100644 index 0000000..d042802 --- /dev/null +++ b/newreleases/cmd/matrix.go @@ -0,0 +1,72 @@ +// Copyright (c) 2022, NewReleases CLI AUTHORS. +// All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package cmd + +import ( + "context" + + "github.com/spf13/cobra" + "newreleases.io/newreleases" +) + +func (c *command) initMatrixCmd() (err error) { + cmd := &cobra.Command{ + Use: "matrix", + Short: "List Matrix integrations", + RunE: func(cmd *cobra.Command, args []string) (err error) { + ctx, cancel := newClientContext(c.config) + defer cancel() + + rooms, err := c.matrixRoomsService.List(ctx) + if err != nil { + return err + } + + if len(rooms) == 0 { + cmd.Println("No Matrix Rooms found.") + return nil + } + + printMatrixRoomsTable(cmd, rooms) + + return nil + }, + PreRunE: func(cmd *cobra.Command, args []string) error { + if err := addClientConfigOptions(cmd, c.config); err != nil { + return err + } + return c.setMatrixRoomsService(cmd, args) + }, + } + + c.root.AddCommand(cmd) + return addClientFlags(cmd) +} + +func (c *command) setMatrixRoomsService(cmd *cobra.Command, args []string) (err error) { + if c.matrixRoomsService != nil { + return nil + } + client, err := c.getClient(cmd) + if err != nil { + return err + } + c.matrixRoomsService = client.MatrixRooms + return nil +} + +type matrixRoomsService interface { + List(ctx context.Context) (rooms []newreleases.MatrixRoom, err error) +} + +func printMatrixRoomsTable(cmd *cobra.Command, rooms []newreleases.MatrixRoom) { + table := newTable(cmd.OutOrStdout()) + table.SetHeader([]string{"ID", "Name", "Homeserver URL", "Internal Room ID"}) + for _, e := range rooms { + table.Append([]string{e.ID, e.Name, e.HomeserverURL, e.InternalRoomID}) + } + table.Render() +} diff --git a/newreleases/cmd/matrix_test.go b/newreleases/cmd/matrix_test.go new file mode 100644 index 0000000..8dec2da --- /dev/null +++ b/newreleases/cmd/matrix_test.go @@ -0,0 +1,82 @@ +// Copyright (c) 2022, NewReleases CLI AUTHORS. +// All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package cmd_test + +import ( + "bytes" + "context" + "testing" + + "newreleases.io/cmd/newreleases/cmd" + "newreleases.io/newreleases" +) + +func TestMatrixCmd(t *testing.T) { + for _, tc := range []struct { + name string + matrixRoomsService cmd.MatrixRoomsService + wantOutput string + wantError error + }{ + { + name: "no rooms", + matrixRoomsService: newMockMatrixRoomsService(nil, nil), + wantOutput: "No Matrix Rooms found.\n", + }, + { + name: "with rooms", + matrixRoomsService: newMockMatrixRoomsService([]newreleases.MatrixRoom{ + { + ID: "znne04qO5y6acw7sg5a9b1pc9t16rpym8jwn", + Name: "NewReleases", + HomeserverURL: "https://matrix-client.matrix.org", + InternalRoomID: "!CklbIcwhYKygGsulFi:matrix.org", + }, + { + ID: "9t4qOp16gmcw7z8jwrpyc6anne0sn5y5a9b1", + Name: "Awesome project", + HomeserverURL: "https://matrix-client.example.com", + InternalRoomID: "!CkGsIcwhKyulFYlbgi:example.com", + }, + }, nil), + wantOutput: "ID NAME HOMESERVER URL INTERNAL ROOM ID \nznne04qO5y6acw7sg5a9b1pc9t16rpym8jwn NewReleases https://matrix-client.matrix.org !CklbIcwhYKygGsulFi:matrix.org \n9t4qOp16gmcw7z8jwrpyc6anne0sn5y5a9b1 Awesome project https://matrix-client.example.com !CkGsIcwhKyulFYlbgi:example.com \n", + }, + { + name: "error", + matrixRoomsService: newMockMatrixRoomsService(nil, errTest), + wantError: errTest, + }, + } { + t.Run(tc.name, func(t *testing.T) { + var outputBuf bytes.Buffer + if err := newCommand(t, + cmd.WithArgs("matrix"), + cmd.WithOutput(&outputBuf), + cmd.WithMatrixRoomsService(tc.matrixRoomsService), + ).Execute(); err != tc.wantError { + t.Fatalf("got error %v, want %v", err, tc.wantError) + } + + gotOutput := outputBuf.String() + if gotOutput != tc.wantOutput { + t.Errorf("got output %q, want %q", gotOutput, tc.wantOutput) + } + }) + } +} + +type mockMatrixRoomsService struct { + rooms []newreleases.MatrixRoom + err error +} + +func newMockMatrixRoomsService(rooms []newreleases.MatrixRoom, err error) mockMatrixRoomsService { + return mockMatrixRoomsService{rooms: rooms, err: err} +} + +func (s mockMatrixRoomsService) List(ctx context.Context) ([]newreleases.MatrixRoom, error) { + return s.rooms, s.err +} diff --git a/newreleases/cmd/project.go b/newreleases/cmd/project.go index f92688b..ab9bb15 100644 --- a/newreleases/cmd/project.go +++ b/newreleases/cmd/project.go @@ -79,6 +79,7 @@ func printProjectsTable(cmd *cobra.Command, projects []newreleases.Project) { hasMicrosoftTeams bool hasMattermost bool hasRocketchat bool + hasMatrix bool hasWebhook bool hasExclusions bool hasInclusions bool @@ -112,6 +113,9 @@ func printProjectsTable(cmd *cobra.Command, projects []newreleases.Project) { if len(p.RocketchatWebhookIDs) > 0 { hasRocketchat = true } + if len(p.MatrixRoomIDs) > 0 { + hasMatrix = true + } if len(p.WebhookIDs) > 0 { hasWebhook = true } @@ -167,6 +171,9 @@ func printProjectsTable(cmd *cobra.Command, projects []newreleases.Project) { if hasRocketchat { header = append(header, "Rocket.Chat") } + if hasMatrix { + header = append(header, "Matrix") + } if hasWebhook { header = append(header, "Webhook") } @@ -215,6 +222,9 @@ func printProjectsTable(cmd *cobra.Command, projects []newreleases.Project) { if hasRocketchat { r = append(r, strings.Join(p.RocketchatWebhookIDs, ", ")) } + if hasMatrix { + r = append(r, strings.Join(p.MatrixRoomIDs, ", ")) + } if hasWebhook { r = append(r, strings.Join(p.WebhookIDs, ", ")) } @@ -286,6 +296,9 @@ func printProject(cmd *cobra.Command, p *newreleases.Project) { if len(p.RocketchatWebhookIDs) > 0 { table.Append([]string{"Rocket.Chat:", strings.Join(p.RocketchatWebhookIDs, ", ")}) } + if len(p.MatrixRoomIDs) > 0 { + table.Append([]string{"Matrix:", strings.Join(p.MatrixRoomIDs, ", ")}) + } if len(p.WebhookIDs) > 0 { table.Append([]string{"Webhooks:", strings.Join(p.WebhookIDs, ", ")}) } diff --git a/newreleases/cmd/project_add.go b/newreleases/cmd/project_add.go index a734d9c..8251bfa 100644 --- a/newreleases/cmd/project_add.go +++ b/newreleases/cmd/project_add.go @@ -22,6 +22,7 @@ func (c *command) initProjectAddCmd(projectCmd *cobra.Command) (err error) { optionNameMicrosoftTeams = "microsoft-teams" optionNameMattermost = "mattermost" optionNameRocketchat = "rocketchat" + optionNameMatrix = "matrix" optionNameWebhook = "webhook" optionNameExclusions = "regex-exclude" optionNameExcludePrereleases = "exclude-prereleases" @@ -80,6 +81,10 @@ func (c *command) initProjectAddCmd(projectCmd *cobra.Command) (err error) { if err != nil { return err } + o.MatrixRoomIDs, err = flags.GetStringArray(optionNameMatrix) + if err != nil { + return err + } o.WebhookIDs, err = flags.GetStringArray(optionNameWebhook) if err != nil { return err @@ -149,6 +154,7 @@ func (c *command) initProjectAddCmd(projectCmd *cobra.Command) (err error) { cmd.Flags().StringArray(optionNameMicrosoftTeams, nil, "Microsoft Teams webhook ID") cmd.Flags().StringArray(optionNameMattermost, nil, "Mattermost webhook ID") cmd.Flags().StringArray(optionNameRocketchat, nil, "Rocket.Chat webhook ID") + cmd.Flags().StringArray(optionNameMatrix, nil, "Matrix room ID") cmd.Flags().StringArray(optionNameWebhook, nil, "Webhook ID") cmd.Flags().StringArray(optionNameExclusions, nil, "Regex version exclusion, suffix with \"-inverse\" for inclusion") cmd.Flags().Bool(optionNameExcludePrereleases, false, "exclude pre-releases") diff --git a/newreleases/cmd/project_add_test.go b/newreleases/cmd/project_add_test.go index 3ffc3e1..1efe676 100644 --- a/newreleases/cmd/project_add_test.go +++ b/newreleases/cmd/project_add_test.go @@ -39,6 +39,7 @@ func TestProjectCmd_Add(t *testing.T) { "--microsoft-teams", "0td5gwgzextbe6tyksdfey4mds", "--mattermost", "wgxtzed4yksd5dfeymsbe6t0tg", "--rocketchat", "5dfeymsbe6t0tgwgxtzed4yksd", + "--matrix", "wgxtzesbe6t05dfed4yksdmytg", "--webhook", "tbe6tyksdfey4md0td5gwgzexs", "--regex-exclude", `^0\.1`, "--regex-exclude", `^0\.3-inverse`, @@ -48,7 +49,7 @@ func TestProjectCmd_Add(t *testing.T) { "--tag", "33f1db7254b9", }, projectsService: newMockProjectsService(1, nil), - wantOutput: "ID: new \nName: golang/go \nProvider: github \nEmail: weekly \nSlack: mdsbe60td5gwgzetyksdfeyxt4 \nTelegram: sdfeyxt4mdsbe60td5gwgzetyk \nDiscord: 4mdsbe60td5gwgzetyksdfeyxt, zext4mdsbe6tyksdfey0td5gwg \nHangouts Chat: etyksdfeyxt4mdsbe60td5gwgz \nMicrosoft Teams: 0td5gwgzextbe6tyksdfey4mds \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nWebhooks: tbe6tyksdfey4md0td5gwgzexs \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Some note \nTags: 33f1db7254b9 \n", + wantOutput: "ID: new \nName: golang/go \nProvider: github \nEmail: weekly \nSlack: mdsbe60td5gwgzetyksdfeyxt4 \nTelegram: sdfeyxt4mdsbe60td5gwgzetyk \nDiscord: 4mdsbe60td5gwgzetyksdfeyxt, zext4mdsbe6tyksdfey0td5gwg \nHangouts Chat: etyksdfeyxt4mdsbe60td5gwgz \nMicrosoft Teams: 0td5gwgzextbe6tyksdfey4mds \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nMatrix: wgxtzesbe6t05dfed4yksdmytg \nWebhooks: tbe6tyksdfey4md0td5gwgzexs \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Some note \nTags: 33f1db7254b9 \n", }, { name: "error", diff --git a/newreleases/cmd/project_get_test.go b/newreleases/cmd/project_get_test.go index d2c1be9..6c4c40f 100644 --- a/newreleases/cmd/project_get_test.go +++ b/newreleases/cmd/project_get_test.go @@ -33,7 +33,7 @@ func TestProjectCmd_Get(t *testing.T) { { name: "full project", projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", + wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nMatrix: 4yksd5e6twgxtzdfeymsbed0tg \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", }, { name: "error", diff --git a/newreleases/cmd/project_list_test.go b/newreleases/cmd/project_list_test.go index 5c28b0f..12e3969 100644 --- a/newreleases/cmd/project_list_test.go +++ b/newreleases/cmd/project_list_test.go @@ -89,7 +89,7 @@ func TestProjectCmd_List(t *testing.T) { { name: "full project", projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID NAME PROVIDER EMAIL SLACK TELEGRAM DISCORD HANGOUTS CHAT MICROSOFT TEAMS MATTERMOST ROCKET CHAT WEBHOOK REGEX EXCLUDE REGEX EXCLUDE INVERSE EXCLUDE PRE-RELEASES EXCLUDE UPDATED NOTE TAGS \nmdsbe60td5gwgzetyksdfeyxt4 golang/go github daily zetyksdfeymdsbe60td5gwgxt4 sbe60td5gwgxtzetyksdfeymd4 tyksdfeymsbegxtzed460td5gw yksdfeymsbe6t0td5gzed4wgxt gwgxtzed4yksdfeymsbe6t0td5 wgxtzed4yksd5dfeymsbe6t0tg 5dfeymsbe6t0tgwgxtzed4yksd e6t0td5ykgwgxtzed4eymsbsdf ^0\\.1 ^0\\.3 yes yes Initial no... 33f1db7254b9 \n", + wantOutput: "ID NAME PROVIDER EMAIL SLACK TELEGRAM DISCORD HANGOUTS CHAT MICROSOFT TEAMS MATTERMOST ROCKET CHAT MATRIX WEBHOOK REGEX EXCLUDE REGEX EXCLUDE INVERSE EXCLUDE PRE-RELEASES EXCLUDE UPDATED NOTE TAGS \nmdsbe60td5gwgzetyksdfeyxt4 golang/go github daily zetyksdfeymdsbe60td5gwgxt4 sbe60td5gwgxtzetyksdfeymd4 tyksdfeymsbegxtzed460td5gw yksdfeymsbe6t0td5gzed4wgxt gwgxtzed4yksdfeymsbe6t0td5 wgxtzed4yksd5dfeymsbe6t0tg 5dfeymsbe6t0tgwgxtzed4yksd 4yksd5e6twgxtzdfeymsbed0tg e6t0td5ykgwgxtzed4eymsbsdf ^0\\.1 ^0\\.3 yes yes Initial no... 33f1db7254b9 \n", }, { name: "error", diff --git a/newreleases/cmd/project_search_test.go b/newreleases/cmd/project_search_test.go index 95a4979..95aac79 100644 --- a/newreleases/cmd/project_search_test.go +++ b/newreleases/cmd/project_search_test.go @@ -49,7 +49,7 @@ func TestProjectCmd_Search(t *testing.T) { name: "full project", args: []string{"golang"}, projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID NAME PROVIDER EMAIL SLACK TELEGRAM DISCORD HANGOUTS CHAT MICROSOFT TEAMS MATTERMOST ROCKET CHAT WEBHOOK REGEX EXCLUDE REGEX EXCLUDE INVERSE EXCLUDE PRE-RELEASES EXCLUDE UPDATED NOTE TAGS \nmdsbe60td5gwgzetyksdfeyxt4 golang/go github daily zetyksdfeymdsbe60td5gwgxt4 sbe60td5gwgxtzetyksdfeymd4 tyksdfeymsbegxtzed460td5gw yksdfeymsbe6t0td5gzed4wgxt gwgxtzed4yksdfeymsbe6t0td5 wgxtzed4yksd5dfeymsbe6t0tg 5dfeymsbe6t0tgwgxtzed4yksd e6t0td5ykgwgxtzed4eymsbsdf ^0\\.1 ^0\\.3 yes yes Initial no... 33f1db7254b9 \n", + wantOutput: "ID NAME PROVIDER EMAIL SLACK TELEGRAM DISCORD HANGOUTS CHAT MICROSOFT TEAMS MATTERMOST ROCKET CHAT MATRIX WEBHOOK REGEX EXCLUDE REGEX EXCLUDE INVERSE EXCLUDE PRE-RELEASES EXCLUDE UPDATED NOTE TAGS \nmdsbe60td5gwgzetyksdfeyxt4 golang/go github daily zetyksdfeymdsbe60td5gwgxt4 sbe60td5gwgxtzetyksdfeymd4 tyksdfeymsbegxtzed460td5gw yksdfeymsbe6t0td5gzed4wgxt gwgxtzed4yksdfeymsbe6t0td5 wgxtzed4yksd5dfeymsbe6t0tg 5dfeymsbe6t0tgwgxtzed4yksd 4yksd5e6twgxtzdfeymsbed0tg e6t0td5ykgwgxtzed4eymsbsdf ^0\\.1 ^0\\.3 yes yes Initial no... 33f1db7254b9 \n", }, { name: "error", diff --git a/newreleases/cmd/project_test.go b/newreleases/cmd/project_test.go index dfc29f3..e3ca6ae 100644 --- a/newreleases/cmd/project_test.go +++ b/newreleases/cmd/project_test.go @@ -30,6 +30,7 @@ var ( MSTeamsWebhookIDs: []string{"gwgxtzed4yksdfeymsbe6t0td5"}, MattermostWebhookIDs: []string{"wgxtzed4yksd5dfeymsbe6t0tg"}, RocketchatWebhookIDs: []string{"5dfeymsbe6t0tgwgxtzed4yksd"}, + MatrixRoomIDs: []string{"4yksd5e6twgxtzdfeymsbed0tg"}, WebhookIDs: []string{"e6t0td5ykgwgxtzed4eymsbsdf"}, Exclusions: []newreleases.Exclusion{ {Value: `^0\.1`}, @@ -155,6 +156,9 @@ func (s mockProjectsService) Add(ctx context.Context, provider, name string, o * if o.RocketchatWebhookIDs != nil { project.RocketchatWebhookIDs = o.RocketchatWebhookIDs } + if o.MatrixRoomIDs != nil { + project.MatrixRoomIDs = o.MatrixRoomIDs + } if o.WebhookIDs != nil { project.WebhookIDs = o.WebhookIDs } @@ -205,6 +209,9 @@ func (s mockProjectsService) UpdateByID(ctx context.Context, id string, o *newre if o.RocketchatWebhookIDs != nil { project.RocketchatWebhookIDs = o.RocketchatWebhookIDs } + if o.MatrixRoomIDs != nil { + project.MatrixRoomIDs = o.MatrixRoomIDs + } if o.WebhookIDs != nil { project.WebhookIDs = o.WebhookIDs } @@ -255,6 +262,9 @@ func (s mockProjectsService) UpdateByName(ctx context.Context, provider, name st if o.RocketchatWebhookIDs != nil { project.RocketchatWebhookIDs = o.RocketchatWebhookIDs } + if o.MatrixRoomIDs != nil { + project.MatrixRoomIDs = o.MatrixRoomIDs + } if o.WebhookIDs != nil { project.WebhookIDs = o.WebhookIDs } diff --git a/newreleases/cmd/project_update.go b/newreleases/cmd/project_update.go index 5a0310f..139b7c0 100644 --- a/newreleases/cmd/project_update.go +++ b/newreleases/cmd/project_update.go @@ -29,6 +29,8 @@ func (c *command) initProjectUpdateCmd(projectCmd *cobra.Command) (err error) { optionNameMattermostRemove = "mattermost-remove" optionNameRocketchat = "rocketchat" optionNameRocketchatRemove = "rocketchat-remove" + optionNameMatrix = "matrix" + optionNameMatrixRemove = "matrix-remove" optionNameWebhook = "webhook" optionNameWebhookRemove = "webhook-remove" optionNameExclusions = "regex-exclude" @@ -163,6 +165,21 @@ func (c *command) initProjectUpdateCmd(projectCmd *cobra.Command) (err error) { o.RocketchatWebhookIDs = rocketchatWebhookIDs } } + matrixRemove, err := flags.GetBool(optionNameMatrixRemove) + if err != nil { + return err + } + if matrixRemove { + o.MatrixRoomIDs = make([]string, 0) + } else { + matrixRoomIDs, err := flags.GetStringArray(optionNameMatrix) + if err != nil { + return err + } + if len(matrixRoomIDs) > 0 { + o.MatrixRoomIDs = matrixRoomIDs + } + } webhookRemove, err := flags.GetBool(optionNameWebhookRemove) if err != nil { return err @@ -284,6 +301,8 @@ func (c *command) initProjectUpdateCmd(projectCmd *cobra.Command) (err error) { cmd.Flags().Bool(optionNameMattermostRemove, false, "remove Mattermost notifications") cmd.Flags().StringArray(optionNameRocketchat, nil, "Rocket.Chat webhook ID") cmd.Flags().Bool(optionNameRocketchatRemove, false, "remove Rocket.Chat notifications") + cmd.Flags().StringArray(optionNameMatrix, nil, "Matrix room ID") + cmd.Flags().Bool(optionNameMatrixRemove, false, "remove Matrix notifications") cmd.Flags().StringArray(optionNameWebhook, nil, "Webhook ID") cmd.Flags().Bool(optionNameWebhookRemove, false, "remove Webhook notifications") cmd.Flags().StringArray(optionNameExclusions, nil, "Regex version exclusion, suffix with \"-inverse\" for inclusion") diff --git a/newreleases/cmd/project_update_test.go b/newreleases/cmd/project_update_test.go index 46fb42c..726b230 100644 --- a/newreleases/cmd/project_update_test.go +++ b/newreleases/cmd/project_update_test.go @@ -53,7 +53,7 @@ func TestProjectCmd_Update(t *testing.T) { "--note", "", }, projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nTags: 33f1db7254b9 \n", + wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \n\nMatrix: 4yksd5e6twgxtzdfeymsbed0tg \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nTags: 33f1db7254b9 \n", }, { name: "update email", @@ -61,7 +61,7 @@ func TestProjectCmd_Update(t *testing.T) { "--email", "weekly", }, projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: weekly \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", + wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: weekly \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nMatrix: 4yksd5e6twgxtzdfeymsbed0tg \n\nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", }, { name: "update slack", @@ -70,7 +70,7 @@ func TestProjectCmd_Update(t *testing.T) { "--slack", "gwgxt4zetyksdfeymdsbe60td5", }, projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: ymdsbe60td5gwgxt4zetyksdfe, gwgxt4zetyksdfeymdsbe60td5 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", + wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: ymdsbe60td5gwgxt4zetyksdfe, gwgxt4zetyksdfeymdsbe60td5 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nMatrix: 4yksd5e6twgxtzdfeymsbed0tg \n\nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", }, { name: "remove slack", @@ -78,7 +78,7 @@ func TestProjectCmd_Update(t *testing.T) { "--slack-remove", }, projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", + wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nMatrix: 4yksd5e6twgxtzdfeymsbed0tg \n\nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", }, { name: "include prereleases", @@ -86,7 +86,7 @@ func TestProjectCmd_Update(t *testing.T) { "--exclude-prereleases=false", }, projectsService: newMockProjectsService(1, nil, []newreleases.Project{fullProject}), - wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", + wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: daily \nSlack: zetyksdfeymdsbe60td5gwgxt4 \nTelegram: sbe60td5gwgxtzetyksdfeymd4 \nDiscord: tyksdfeymsbegxtzed460td5gw \nHangouts Chat: yksdfeymsbe6t0td5gzed4wgxt \nMicrosoft Teams: gwgxtzed4yksdfeymsbe6t0td5 \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: 5dfeymsbe6t0tgwgxtzed4yksd \nMatrix: 4yksd5e6twgxtzdfeymsbed0tg \n\nWebhooks: e6t0td5ykgwgxtzed4eymsbsdf \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Updated: yes \nNote: Initial note \nTags: 33f1db7254b9 \n", }, { name: "update all", @@ -99,6 +99,8 @@ func TestProjectCmd_Update(t *testing.T) { "--hangouts-chat", "etyksdfeyxt4mdsbe60td5gwgz", "--microsoft-teams", "0td5gwgzextbe6tyksdfey4mds", "--mattermost", "wgxtzed4yksd5dfeymsbe6t0tg", + "--rocketchat", "xteymsbed0zdf4yksd5e6twgtg", + "--matrix", "zdf4yksd5e6twgxteymsbed0tg", "--webhook", "tbe6tyksdfey4md0td5gwgzexs", "--regex-exclude", `^0\.1`, "--regex-exclude", `^0\.3-inverse`, @@ -108,7 +110,7 @@ func TestProjectCmd_Update(t *testing.T) { "--tag", "33f1db7254b9", }, projectsService: newMockProjectsService(1, nil, []newreleases.Project{minimalProject}), - wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: weekly \nSlack: mdsbe60td5gwgzetyksdfeyxt4 \nTelegram: sdfeyxt4mdsbe60td5gwgzetyk \nDiscord: 4mdsbe60td5gwgzetyksdfeyxt, zext4mdsbe6tyksdfey0td5gwg \nHangouts Chat: etyksdfeyxt4mdsbe60td5gwgz \nMicrosoft Teams: 0td5gwgzextbe6tyksdfey4mds \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nWebhooks: tbe6tyksdfey4md0td5gwgzexs \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Some note \nTags: 33f1db7254b9 \n", + wantOutput: "ID: mdsbe60td5gwgzetyksdfeyxt4 \nName: golang/go \nProvider: github \nEmail: weekly \nSlack: mdsbe60td5gwgzetyksdfeyxt4 \nTelegram: sdfeyxt4mdsbe60td5gwgzetyk \nDiscord: 4mdsbe60td5gwgzetyksdfeyxt, zext4mdsbe6tyksdfey0td5gwg \nHangouts Chat: etyksdfeyxt4mdsbe60td5gwgz \nMicrosoft Teams: 0td5gwgzextbe6tyksdfey4mds \nMattermost: wgxtzed4yksd5dfeymsbe6t0tg \nRocket.Chat: xteymsbed0zdf4yksd5e6twgtg \nMatrix: zdf4yksd5e6twgxteymsbed0tg \n\nWebhooks: tbe6tyksdfey4md0td5gwgzexs \nRegex Exclude: ^0\\.1 \nRegex Exclude Inverse: ^0\\.3 \nExclude Pre-Releases: yes \nExclude Updated: yes \nNote: Some note \nTags: 33f1db7254b9 \n", }, { name: "error",