Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #41 - Migrate to use go-whatsup-client #45

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/quality-and-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.1
go-version: 1.21.1
- name: Install gotestsum
run: make install-gotestsum
- name: Install revive
run: go get -u github.com/mgechev/revive
run: go install github.com/mgechev/revive@latest
- name: go mod tidy
run: go mod tidy
- name: go mod vendor
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v0.8.3
hooks:
- id: go-imports
# - id: go-imports
- id: go-vet-mod
- id: go-revive
args: ['-config', '.revive.toml', '--']
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
golang 1.20.1
golang 1.21.1
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ as examples, we would create an entry in the configuration file like this:

## Usage

Clone this repo and build the plugin.
Clone this repo, install dependencies, and build the plugin.

```shell
git clone [email protected]:sprak3000/xbar-whats-up.git
make setup-osx-env
make build
```

Expand Down
11 changes: 5 additions & 6 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ When you write your tests, please make sure they're in line with the existing te

## Bug Reports

When the inevitable happens and you discover a bug in the documentation or the code, please follow the process below to
help us out.
If you discover a bug in the documentation or the code, please follow the process below to help us out.

- Search the existing issues to see if the issue has already been filed
- Make sure the issue is a bug and not simply a preference
- If you have found a new issue, please file it

From that point, if you are interest in contributing some code, ask in the issue if we are willing to accept a failing
test case, and/or a fix. If we are, then follow the steps for contributing and we can go from there!
From that point, if you are interested in contributing some code, ask in the issue if we are willing to accept a failing
test case and/or a fix. If we are, then follow the steps for contributing, and we can go from there!

## Feature Requests

Every new feature request will be scrutinized to make sure we are not going to experience feature bloat. Every new
feature should fit the Vision for the project. If you have got an idea for a new feature and you feel it fits the
vision, file an issue and we can discuss it.
feature should fit the Vision for the project. If you have an idea for a new feature and feel it fits the vision, file
an issue, and we can discuss it.

Make sure any feature request you make fits the [INVEST](http://en.wikipedia.org/wiki/INVEST_(mnemonic)) mnemonic.

Expand Down
16 changes: 10 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
module github.com/sprak3000/xbar-whats-up

go 1.17
go 1.21

require github.com/sprak3000/go-client v1.0.1
toolchain go1.21.1

require github.com/sprak3000/go-client v1.1.0

require (
github.com/sprak3000/go-glitch v1.0.1
github.com/stretchr/testify v1.7.1
github.com/sprak3000/go-glitch v1.1.0
github.com/sprak3000/go-whatsup-client v1.1.0
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
25 changes: 13 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sprak3000/go-client v1.0.1 h1:zHTtanfkNrVFae6y+zqsY2B+LrPkxWCZlK5F3uOnkc4=
github.com/sprak3000/go-client v1.0.1/go.mod h1:ch8ZmYJ0gEvm6cn5pXQb/2FE/jkzEgkBpWj6QePBPi0=
github.com/sprak3000/go-glitch v1.0.1 h1:fI5HjMmib3jq/9p/ccL1d+CtdP20Xc7QUTlNUpty5GI=
github.com/sprak3000/go-glitch v1.0.1/go.mod h1:gAghf5TnJBpx+SwVPviNhUD7qeeqBy8hB1W7V+z/wrU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/sprak3000/go-client v1.1.0 h1:RxcuubHsRAJuby8JHOiR1Uzg7QjJLeFF19X+nb6D1Bk=
github.com/sprak3000/go-client v1.1.0/go.mod h1:g2/5bTIZIkQa44cGKRRSq87NIDFpysfJG/9YvM4Tc1g=
github.com/sprak3000/go-glitch v1.1.0 h1:6haWWwI/X12nT/1metfmuIJ55glM8n8Y9MAjOBgwGyo=
github.com/sprak3000/go-glitch v1.1.0/go.mod h1:YiS3Au3XFzjkfGFzEWCR/j7WZq5+fhgZotchT4yYblY=
github.com/sprak3000/go-whatsup-client v1.1.0 h1:FsjLJcF4IPyCld6PvRiAVxoCSZgvDsuJo1AbobOzBnQ=
github.com/sprak3000/go-whatsup-client v1.1.0/go.mod h1:r8h5Herq50rVll/Tn8kLioCd3eu/4VpgkvLS8AXUo1g=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -36,5 +37,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
47 changes: 0 additions & 47 deletions service/client.go

This file was deleted.

113 changes: 0 additions & 113 deletions service/client_test.go

This file was deleted.

27 changes: 22 additions & 5 deletions service/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"encoding/json"
"net/url"

"github.com/sprak3000/go-client/client"
"github.com/sprak3000/go-glitch/glitch"
"github.com/sprak3000/go-whatsup-client/whatsup"

"github.com/sprak3000/xbar-whats-up/configuration"
"github.com/sprak3000/xbar-whats-up/slack"
"github.com/sprak3000/xbar-whats-up/status"
"github.com/sprak3000/xbar-whats-up/statuspageio"
)

// Error codes
Expand All @@ -17,6 +20,11 @@ const (
ErrorUnableToParseConfiguration = "UNABLE_TO_PARSE_CONFIGURATION"
)

// Reader provides the requirements for anyone implementing reading a service's status
type Reader interface {
ReadStatus(client whatsup.StatusPageClient) (status.Details, glitch.DataError)
}

// Site holds the data for service status pages
type Site struct {
URL url.URL `json:"url,string"`
Expand Down Expand Up @@ -53,22 +61,31 @@ func (s *Site) UnmarshalJSON(data []byte) error {
type Sites map[string]Site

// GetOverview returns the details about the services monitored
func (sites Sites) GetOverview(serviceFinder client.ServiceFinder, readerFinder ReaderServiceFinder) status.Overview {
func (sites Sites) GetOverview(client whatsup.StatusPageClient) status.Overview {
overview := status.Overview{
OverallStatus: "none",
List: map[string][]status.Details{},
Errors: []string{},
}

for k, v := range sites {
reader, rfErr := readerFinder(v.Type)
if rfErr != nil {
var reader Reader

switch v.Type {
case statuspageio.ServiceType:
reader = statuspageio.ClientReader{
ServiceName: k,
PageURL: v.URL.String(),
}
case slack.ServiceType:
reader = slack.ClientReader{}
default:
overview.Errors = append(overview.Errors, k+" uses an unsupported service type "+v.Type)
// Unsupported at this time
continue
}

resp, rErr := reader.ReadStatus(serviceFinder, k, v.URL.Path)
resp, rErr := reader.ReadStatus(client)
if rErr != nil {
overview.Errors = append(overview.Errors, rErr.Error())
continue
Expand Down
Loading
Loading