Skip to content

Commit

Permalink
Merge pull request #22 from ewohltman/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ewohltman authored Apr 2, 2024
2 parents 1a5311e + 6579afb commit 558b53e
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 79 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Go 1.19
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.22'
check-latest: true

- name: Download dependencies
Expand All @@ -26,7 +26,7 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49
version: v1.57

- name: Run tests
run: make test
Expand All @@ -36,7 +36,7 @@ jobs:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PATH="${PATH}:$(go env GOPATH)/bin"
GO111MODULE=off go get -u github.com/mattn/goveralls
go install github.com/mattn/goveralls@latest
goveralls -coverprofile=coverage.out -service=github
- name: Initialize CodeQL
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pullRequestMaster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Go 1.19
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.22'
check-latest: true

- name: Download dependencies
Expand All @@ -26,7 +26,7 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49
version: v1.57

- name: Run tests
run: make test
Expand All @@ -36,7 +36,7 @@ jobs:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PATH="${PATH}:$(go env GOPATH)/bin"
GO111MODULE=off go get -u github.com/mattn/goveralls
go install github.com/mattn/goveralls@latest
goveralls -coverprofile=coverage.out -service=github
- name: Initialize CodeQL
Expand Down
90 changes: 40 additions & 50 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
linters-settings:
dupl:
threshold: 100
cyclop:
max-complexity: 15
package-average: 0.0
skip-tests: true
funlen:
lines: 100
statements: 50
Expand All @@ -15,72 +17,60 @@ linters-settings:
- opinionated
- performance
- style
disabled-checks:
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/ewohltman/discordgo-mock
golint:
min-confidence: 0.8
govet:
check-shadowing: true
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US

linters:
disable-all: true
enable:
- bodyclose
enable-all: true
disable:
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godox
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- revive
- rowserrcheck
- staticcheck
- exhaustivestruct
- exhaustruct
- gci
- goerr113
- gofumpt
- golint
- ifshort
- interfacer
- ireturn
- maligned
- nonamedreturns
- nosnakecase
- scopelint
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- tagliatelle
- varcheck
- whitespace
- wsl
- varnamelen
- wrapcheck

run:
timeout: 5m
skip-dirs:
- .github
- build
- web

issues:
max-same-issues: 0
exclude-use-default: false
exclude-dirs:
- .github
- build
- web
exclude-files:
- zz_generated.*
exclude-rules:
- path: _test\.go
linters:
- bodyclose
- cyclop
- dupl
- errcheck
- errchkjson
- forcetypeassert
- gocyclo
- gosec
- nosnakecase
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/ewohltman/discordgo-mock

go 1.19
go 1.22

require (
github.com/bwmarrin/discordgo v0.26.1
github.com/gorilla/mux v1.8.0
github.com/bwmarrin/discordgo v0.28.1
github.com/gorilla/mux v1.8.1
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/bwmarrin/discordgo v0.26.1 h1:AIrM+g3cl+iYBr4yBxCBp9tD9jR3K7upEjl0d89FRkE=
github.com/bwmarrin/discordgo v0.26.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
Expand Down
29 changes: 21 additions & 8 deletions mockrest/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package mockrest
import (
"encoding/json"
"fmt"
"net/http"

"github.com/ewohltman/discordgo-mock/mockconstants"

"net/http"

"github.com/bwmarrin/discordgo"
"github.com/gorilla/mux"
)
Expand All @@ -17,7 +16,7 @@ func (roundTripper *RoundTripper) addHandlersChannels(apiVersion string) {

subrouter := roundTripper.router.PathPrefix(pathChannels).Subrouter()

pathChannelID := fmt.Sprintf("/%s", resourceChannelID)
pathChannelID := "/" + resourceChannelID
pathChannelIDMessages := fmt.Sprintf("%s/%s", pathChannelID, resourceMessages)
pathChannelIDInvites := fmt.Sprintf("%s/%s", pathChannelID, resourceInvites)

Expand All @@ -44,6 +43,7 @@ func (roundTripper *RoundTripper) channelsResponseGET(w http.ResponseWriter, r *
channel, err := roundTripper.state.Channel(channelID)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -57,6 +57,7 @@ func (roundTripper *RoundTripper) channelsResponseDelete(w http.ResponseWriter,
channel, err := roundTripper.state.Channel(channelID)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -70,6 +71,7 @@ func (roundTripper *RoundTripper) channelsResponsePatch(w http.ResponseWriter, r
channel, err := roundTripper.state.Channel(channelID)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -78,21 +80,23 @@ func (roundTripper *RoundTripper) channelsResponsePatch(w http.ResponseWriter, r
dec := json.NewDecoder(r.Body)
dec.DisallowUnknownFields()

if err = dec.Decode(&c); err != nil {
err = dec.Decode(&c)
if err != nil {
sendError(w, err)

return
}

channel.Name = c.Name
channel.Topic = c.Topic
channel.MessageCount = c.Position
channel.MessageCount = *c.Position

if c.NSFW != nil {
channel.NSFW = *c.NSFW
}

channel.Icon = c.ParentID
channel.Position = c.Position
channel.Position = *c.Position
channel.Bitrate = c.Bitrate
channel.PermissionOverwrites = c.PermissionOverwrites
channel.UserLimit = c.UserLimit
Expand All @@ -112,6 +116,7 @@ func (roundTripper *RoundTripper) channelMessagesResponseGET(w http.ResponseWrit
channel, err := roundTripper.state.Channel(channelID)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -125,6 +130,7 @@ func (roundTripper *RoundTripper) channelMessagesResponsePOST(w http.ResponseWri
channel, err := roundTripper.state.Channel(channelID)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -133,8 +139,10 @@ func (roundTripper *RoundTripper) channelMessagesResponsePOST(w http.ResponseWri
dec := json.NewDecoder(r.Body)
dec.DisallowUnknownFields()

if err = dec.Decode(&message); err != nil {
err = dec.Decode(&message)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -148,6 +156,7 @@ func (roundTripper *RoundTripper) channelMessagesResponsePOST(w http.ResponseWri
err = roundTripper.state.MessageAdd(message)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -161,12 +170,14 @@ func (roundTripper *RoundTripper) channelInvitesResponsePOST(w http.ResponseWrit
channel, err := roundTripper.state.Channel(channelID)
if err != nil {
sendError(w, err)

return
}

guild, err := roundTripper.state.Guild(channel.GuildID)
if err != nil {
sendError(w, err)

return
}

Expand All @@ -175,8 +186,10 @@ func (roundTripper *RoundTripper) channelInvitesResponsePOST(w http.ResponseWrit
dec := json.NewDecoder(r.Body)
dec.DisallowUnknownFields()

if err := dec.Decode(&invite); err != nil {
err = dec.Decode(&invite)
if err != nil {
sendError(w, err)

return
}

Expand Down
Loading

0 comments on commit 558b53e

Please sign in to comment.