Skip to content

Commit

Permalink
Support Rocket.Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Jan 8, 2021
1 parent 95f0c1c commit 8d6782b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ This client implements all NewReleases API features.
- Get added Hangouts Chat webhooks
- Get added Microsoft Teams webhooks
- Get added Mattermost webhooks
- Get added Rocket.Chat webhooks
- Get added custom Webhooks
- Get auth keys

Expand Down
2 changes: 2 additions & 0 deletions newreleases.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Client struct {
HangoutsChatWebhooks *HangoutsChatWebhooksService
MicrosoftTeamsWebhooks *MicrosoftTeamsWebhooksService
MattermostWebhooks *MattermostWebhooksService
RocketchatWebhooks *RocketchatWebhooksService
Webhooks *WebhooksService
}

Expand Down Expand Up @@ -93,6 +94,7 @@ func newClient(httpClient *http.Client) (c *Client) {
c.HangoutsChatWebhooks = (*HangoutsChatWebhooksService)(&c.service)
c.MicrosoftTeamsWebhooks = (*MicrosoftTeamsWebhooksService)(&c.service)
c.MattermostWebhooks = (*MattermostWebhooksService)(&c.service)
c.RocketchatWebhooks = (*RocketchatWebhooksService)(&c.service)
c.Webhooks = (*WebhooksService)(&c.service)
return c
}
Expand Down
2 changes: 2 additions & 0 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Project struct {
HangoutsChatWebhookIDs []string `json:"hangouts_chat_webhooks,omitempty"`
MSTeamsWebhookIDs []string `json:"microsoft_teams_webhooks,omitempty"`
MattermostWebhookIDs []string `json:"mattermost_webhooks,omitempty"`
RocketchatWebhookIDs []string `json:"rocketchat_webhooks,omitempty"`
WebhookIDs []string `json:"webhooks,omitempty"`
Exclusions []Exclusion `json:"exclude_version_regexp,omitempty"`
ExcludePrereleases bool `json:"exclude_prereleases,omitempty"`
Expand Down Expand Up @@ -156,6 +157,7 @@ type ProjectOptions struct {
HangoutsChatWebhookIDs []string `json:"hangouts_chat_webhooks"`
MSTeamsWebhookIDs []string `json:"microsoft_teams_webhooks"`
MattermostWebhookIDs []string `json:"mattermost_webhooks"`
RocketchatWebhookIDs []string `json:"rocketchat_webhooks"`
WebhookIDs []string `json:"webhooks"`
Exclusions []Exclusion `json:"exclude_version_regexp"`
ExcludePrereleases *bool `json:"exclude_prereleases"`
Expand Down
2 changes: 2 additions & 0 deletions projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ var (
HangoutsChatWebhookIDs: []string{"hangouts123"},
MSTeamsWebhookIDs: []string{"teams123"},
MattermostWebhookIDs: []string{"matt123"},
RocketchatWebhookIDs: []string{"rchat123"},
WebhookIDs: []string{"webhook123", "webhook124"},
Exclusions: []newreleases.Exclusion{{Value: "^1.9", Inverse: true}},
ExcludePrereleases: true,
Expand All @@ -422,6 +423,7 @@ var (
HangoutsChatWebhookIDs: []string{"hangouts123"},
MSTeamsWebhookIDs: []string{"teams123"},
MattermostWebhookIDs: []string{"matt123"},
RocketchatWebhookIDs: []string{"rchat123"},
WebhookIDs: []string{"webhook123", "webhook124"},
Exclusions: []newreleases.Exclusion{{Value: "^1.9", Inverse: true}},
ExcludePrereleases: newreleases.Bool(true),
Expand Down
22 changes: 22 additions & 0 deletions webhooks_rocketchat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2021, NewReleases Go client 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 newreleases

import (
"context"
"net/http"
)

// RocketchatWebhooksService provides information about Rocket.Chat
// Webhooks notifications.
type RocketchatWebhooksService service

// List returns all Rocket.Chat webhooks.
func (s *RocketchatWebhooksService) List(ctx context.Context) (webhooks []Webhook, err error) {
var r webhooksResponse
err = s.client.request(ctx, http.MethodGet, "v1/rocketchat-webhooks", nil, &r)
return r.Webhooks, err
}
51 changes: 51 additions & 0 deletions webhooks_rocketchat_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2021, NewReleases Go client 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 newreleases_test

import (
"context"
"fmt"
"net/http"
"testing"

"newreleases.io/newreleases"
)

func TestRocketchatWebhooksService_List(t *testing.T) {
client, mux, _, teardown := newClient(t, "")
defer teardown()

mux.HandleFunc("/v1/rocketchat-webhooks", requireMethod("GET", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", jsonContentType)
fmt.Fprintln(w, rocketchatWebhooksServiceList)
}))

got, err := client.RocketchatWebhooks.List(context.Background())
if err != nil {
t.Fatal(err)
}

assertEqual(t, "", got, rocketchatWebhooksServiceListWant)
}

var (
rocketchatWebhooksServiceList = `
{
"webhooks": [
{
"id": "lst4ezma884w1a56q4es0dvttd",
"name": "My Channel"
}
]
}
`
rocketchatWebhooksServiceListWant = []newreleases.Webhook{
{
ID: "lst4ezma884w1a56q4es0dvttd",
Name: "My Channel",
},
}
)

0 comments on commit 8d6782b

Please sign in to comment.