Skip to content

Commit

Permalink
Add Discord support
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Nov 30, 2019
1 parent d9ac2a5 commit c923bec
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.12.4
- 1.13

install:
- go get -v newreleases.io/newreleases/...
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This client implements all NewReleases API features.
- Get tracked providers
- Get added Slack Channels
- Get added Telegram Chats
- Get added Dissord Channels
- Get added Hangouts Chat webhooks
- Get added Microsoft Teams webhooks
- Get added custom Webhooks
Expand Down
33 changes: 33 additions & 0 deletions discord_channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2019, 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"
)

// DiscordChannelsService provides information about Discord notifications.
type DiscordChannelsService service

// DiscordChannel holds information about a Discord Channel that is connected to the
// account.
type DiscordChannel struct {
ID string `json:"id"`
Name string `json:"name"`
}

// List returns all connected Discord Channels.
func (s *DiscordChannelsService) List(ctx context.Context) (channels []DiscordChannel, err error) {

type discordChannelsResponse struct {
Channels []DiscordChannel `json:"channels"`
}

var r discordChannelsResponse
err = s.client.request(ctx, http.MethodGet, "v1/discord-channels", nil, &r)
return r.Channels, err
}
51 changes: 51 additions & 0 deletions discord_channels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2019, 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 TestDiscordChannelsService_List(t *testing.T) {
client, mux, _, teardown := newClient(t, "")
defer teardown()

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

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

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

var (
discordChannelsServiceList = `
{
"channels": [
{
"id": "02bgrl5510q3pe8gf7322d8n5",
"name": "NewReleases Yeah"
}
]
}
`
discordChannelsServiceListWant = []newreleases.DiscordChannel{
{
ID: "02bgrl5510q3pe8gf7322d8n5",
Name: "NewReleases Yeah",
},
}
)
2 changes: 2 additions & 0 deletions newreleases.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Client struct {
Releases *ReleasesService
SlackChannels *SlackChannelsService
TelegramChats *TelegramChatsService
DiscordChannels *DiscordChannelsService
HangoutsChatWebhooks *HangoutsChatWebhooksService
MicrosoftTeamsWebhooks *MicrosoftTeamsWebhooksService
Webhooks *WebhooksService
Expand Down Expand Up @@ -87,6 +88,7 @@ func newClient(httpClient *http.Client) (c *Client) {
c.Releases = (*ReleasesService)(&c.service)
c.SlackChannels = (*SlackChannelsService)(&c.service)
c.TelegramChats = (*TelegramChatsService)(&c.service)
c.DiscordChannels = (*DiscordChannelsService)(&c.service)
c.HangoutsChatWebhooks = (*HangoutsChatWebhooksService)(&c.service)
c.MicrosoftTeamsWebhooks = (*MicrosoftTeamsWebhooksService)(&c.service)
c.Webhooks = (*WebhooksService)(&c.service)
Expand Down
2 changes: 2 additions & 0 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Project struct {
EmailNotification EmailNotification `json:"email_notification,omitempty"`
SlackIDs []string `json:"slack_channels,omitempty"`
TelegramChatIDs []string `json:"telegram_chats,omitempty"`
DiscordIDs []string `json:"discord_channels,omitempty"`
HangoutsChatWebhookIDs []string `json:"hangouts_chat_webhooks,omitempty"`
MSTeamsWebhookIDs []string `json:"microsoft_teams_webhooks,omitempty"`
WebhookIDs []string `json:"webhooks,omitempty"`
Expand Down Expand Up @@ -149,6 +150,7 @@ type ProjectOptions struct {
EmailNotification *EmailNotification `json:"email_notification"`
SlackIDs []string `json:"slack_channels"`
TelegramChatIDs []string `json:"telegram_chats"`
DiscordIDs []string `json:"discord_channels"`
HangoutsChatWebhookIDs []string `json:"hangouts_chat_webhooks"`
MSTeamsWebhookIDs []string `json:"microsoft_teams_webhooks"`
WebhookIDs []string `json:"webhooks"`
Expand Down
2 changes: 2 additions & 0 deletions projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ var (
EmailNotification: newreleases.EmailNotificationHourly,
SlackIDs: []string{"slack123"},
TelegramChatIDs: []string{"telegram123"},
DiscordIDs: []string{"discord123"},
HangoutsChatWebhookIDs: []string{"hangouts123"},
MSTeamsWebhookIDs: []string{"teams123"},
WebhookIDs: []string{"webhook123", "webhook124"},
Expand All @@ -416,6 +417,7 @@ var (
EmailNotification: &newreleases.EmailNotificationHourly,
SlackIDs: []string{"slack123"},
TelegramChatIDs: []string{"telegram123"},
DiscordIDs: []string{"discord123"},
HangoutsChatWebhookIDs: []string{"hangouts123"},
MSTeamsWebhookIDs: []string{"teams123"},
WebhookIDs: []string{"webhook123", "webhook124"},
Expand Down
8 changes: 4 additions & 4 deletions slack_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ func TestSlackChannelsService_List(t *testing.T) {

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

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

assertEqual(t, "", got, clackChannelsServiceListWant)
assertEqual(t, "", got, slackChannelsServiceListWant)
}

var (
clackChannelsServiceList = `
slackChannelsServiceList = `
{
"channels": [
{
Expand All @@ -43,7 +43,7 @@ var (
]
}
`
clackChannelsServiceListWant = []newreleases.SlackChannel{
slackChannelsServiceListWant = []newreleases.SlackChannel{
{
ID: "00q3pe8gf7322d8n52bgrl551",
Channel: "releases",
Expand Down
2 changes: 1 addition & 1 deletion telegram_chats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type TelegramChat struct {
Name string `json:"name"`
}

// List returns all connected Slack Channels.
// List returns all connected Telegram Chats.
func (s *TelegramChatsService) List(ctx context.Context) (channels []TelegramChat, err error) {

type TelegramChatsResponse struct {
Expand Down

0 comments on commit c923bec

Please sign in to comment.