aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
25 files changed, 65 insertions, 39 deletions
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 02e231a3..7100cab0 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -7,10 +7,13 @@ on:
paths:
- '**.go'
- 'go.mod'
+ - '.golangci.yml'
+ - '.github/workflows/go.yml'
pull_request:
paths:
- '**.go'
- 'go.mod'
+ - '.golangci.yml'
- '.github/workflows/go.yml'
env:
GOPROXY: "https://proxy.golang.org"
@@ -22,31 +25,25 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Run golangci-lint
- uses: actions-contrib/golangci-lint@v1
+ uses: golangci/golangci-lint-action@v2
with:
- args: 'run --timeout=30m'
+ version: latest
+ args: --timeout=30m
test:
name: Test
strategy:
matrix:
- go-version: [1.14.x, 1.15.x]
+ go-version: [1.14.x, 1.15.x, 1.16.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
- uses: actions/setup-go@v1
+ uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- - name: Run unit tests
- run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
- - name: Upload coverage report to Codecov
- uses: codecov/codecov-action@v1.0.6
- with:
- file: ./coverage
- flags: unittests
- name: Cache downloaded modules
uses: actions/cache@v1
with:
@@ -54,4 +51,11 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
+ - name: Run unit tests
+ run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
+ - name: Upload coverage report to Codecov
+ uses: codecov/codecov-action@v1.5.0
+ with:
+ file: ./coverage
+ flags: unittests
diff --git a/.golangci.yml b/.golangci.yml
new file mode 100644
index 00000000..b7256bae
--- /dev/null
+++ b/.golangci.yml
@@ -0,0 +1,21 @@
+linters-settings:
+ nakedret:
+ max-func-lines: 0 # Disallow any unnamed return statement
+
+linters:
+ enable:
+ - deadcode
+ - errcheck
+ - gosimple
+ - govet
+ - ineffassign
+ - staticcheck
+ - structcheck
+ - typecheck
+ - unused
+ - varcheck
+ - nakedret
+ - gofmt
+ - rowserrcheck
+ - unconvert
+ - goimports
diff --git a/docker/s6/crond/run b/docker/s6/crond/run
index ada467e1..6232dd26 100755
--- a/docker/s6/crond/run
+++ b/docker/s6/crond/run
@@ -3,7 +3,7 @@
# The default configuration is also calling all the scripts in /etc/periodic/${period}
if test -f ./setup; then
- # shellcheck disable=SC2039,SC1091
+ # shellcheck disable=SC2039,SC1091,SC3046
source ./setup
fi
diff --git a/docker/s6/gogs/run b/docker/s6/gogs/run
index 72db3f05..eae716e7 100755
--- a/docker/s6/gogs/run
+++ b/docker/s6/gogs/run
@@ -1,7 +1,7 @@
#!/bin/sh
if test -f ./setup; then
- # shellcheck disable=SC2039,SC1091
+ # shellcheck disable=SC2039,SC1091,SC3046
source ./setup
fi
diff --git a/docker/s6/openssh/run b/docker/s6/openssh/run
index d7a538dd..c293e67b 100755
--- a/docker/s6/openssh/run
+++ b/docker/s6/openssh/run
@@ -1,7 +1,7 @@
#!/bin/sh
if test -f ./setup; then
- # shellcheck disable=SC2039,SC1091
+ # shellcheck disable=SC2039,SC1091,SC3046
source ./setup
fi
diff --git a/docker/s6/syslogd/run b/docker/s6/syslogd/run
index 5c3bbefb..de605fce 100755
--- a/docker/s6/syslogd/run
+++ b/docker/s6/syslogd/run
@@ -1,7 +1,7 @@
#!/bin/sh
if test -f ./setup; then
- # shellcheck disable=SC2039,SC1091
+ # shellcheck disable=SC2039,SC1091,SC3046
source ./setup
fi
diff --git a/docker/start.sh b/docker/start.sh
index e10feb20..b37acfe2 100755
--- a/docker/start.sh
+++ b/docker/start.sh
@@ -12,7 +12,7 @@ create_socat_links() {
SERV_FOLDER=/app/gogs/docker/s6/SOCAT_${NAME}_${PORT}
mkdir -p "${SERV_FOLDER}"
CMD="socat -ls TCP4-LISTEN:${PORT},fork,reuseaddr TCP4:${ADDR}:${PORT}"
- # shellcheck disable=SC2039
+ # shellcheck disable=SC2039,SC3037
echo -e "#!/bin/sh\nexec $CMD" > "${SERV_FOLDER}"/run
chmod +x "${SERV_FOLDER}"/run
USED_PORT="${USED_PORT}:${PORT}"
@@ -24,7 +24,7 @@ EOT
}
cleanup() {
- # Cleanup SOCAT services and s6 event folder
+ # Cleanup SOCAT services and s6 event folder
# On start and on shutdown in case container has been killed
rm -rf "$(find /app/gogs/docker/s6/ -name 'event')"
rm -rf /app/gogs/docker/s6/SOCAT_*
@@ -67,7 +67,7 @@ if [ "$CROND" = "true" ] || [ "$CROND" = "1" ]; then
rm -f /app/gogs/docker/s6/crond/down
/bin/sh /app/gogs/docker/runtime/backup-init.sh "${PUID}"
else
- # Tell s6 not to run the crond service
+ # Tell s6 not to run the crond service
touch /app/gogs/docker/s6/crond/down
fi
diff --git a/internal/cron/cron.go b/internal/cron/cron.go
index 9d45cd15..2228b6a4 100644
--- a/internal/cron/cron.go
+++ b/internal/cron/cron.go
@@ -11,8 +11,8 @@ import (
"github.com/gogs/cron"
- "gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/conf"
+ "gogs.io/gogs/internal/db"
)
var c = cron.New()
diff --git a/internal/db/action.go b/internal/db/action.go
index b44af9c7..292e936a 100644
--- a/internal/db/action.go
+++ b/internal/db/action.go
@@ -11,7 +11,7 @@ import (
"time"
"unicode"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
"github.com/unknwon/com"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
diff --git a/internal/db/models.go b/internal/db/models.go
index f80cad92..3c2b6280 100644
--- a/internal/db/models.go
+++ b/internal/db/models.go
@@ -227,7 +227,7 @@ func GetStatistic() (stats Statistic) {
stats.Counter.HookTask, _ = x.Count(new(HookTask))
stats.Counter.Team, _ = x.Count(new(Team))
stats.Counter.Attachment, _ = x.Count(new(Attachment))
- return
+ return stats
}
func Ping() error {
diff --git a/internal/db/ssh_key.go b/internal/db/ssh_key.go
index 379c5b1d..2f783a9f 100644
--- a/internal/db/ssh_key.go
+++ b/internal/db/ssh_key.go
@@ -221,7 +221,7 @@ func SSHKeyGenParsePublicKey(key string) (string, int, error) {
func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
fields := strings.Fields(keyLine)
if len(fields) < 2 {
- return "", 0, fmt.Errorf("not enough fields in public key line: %s", string(keyLine))
+ return "", 0, fmt.Errorf("not enough fields in public key line: %s", keyLine)
}
raw, err := base64.StdEncoding.DecodeString(fields[1])
diff --git a/internal/db/webhook.go b/internal/db/webhook.go
index 61602ef9..457fa6cb 100644
--- a/internal/db/webhook.go
+++ b/internal/db/webhook.go
@@ -14,7 +14,7 @@ import (
"strings"
"time"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
gouuid "github.com/satori/go.uuid"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
diff --git a/internal/db/webhook_dingtalk.go b/internal/db/webhook_dingtalk.go
index e747ae14..13287f5e 100644
--- a/internal/db/webhook_dingtalk.go
+++ b/internal/db/webhook_dingtalk.go
@@ -8,7 +8,7 @@ import (
"fmt"
"strings"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
"github.com/gogs/git-module"
api "github.com/gogs/go-gogs-client"
diff --git a/internal/db/webhook_discord.go b/internal/db/webhook_discord.go
index 4725f867..f149b11e 100644
--- a/internal/db/webhook_discord.go
+++ b/internal/db/webhook_discord.go
@@ -9,7 +9,7 @@ import (
"strconv"
"strings"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
"github.com/gogs/git-module"
api "github.com/gogs/go-gogs-client"
diff --git a/internal/db/webhook_slack.go b/internal/db/webhook_slack.go
index f824e9bc..a42fb8d8 100644
--- a/internal/db/webhook_slack.go
+++ b/internal/db/webhook_slack.go
@@ -8,7 +8,7 @@ import (
"fmt"
"strings"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
"github.com/gogs/git-module"
api "github.com/gogs/go-gogs-client"
diff --git a/internal/httplib/httplib.go b/internal/httplib/httplib.go
index 1fca7fa7..1062d220 100644
--- a/internal/httplib/httplib.go
+++ b/internal/httplib/httplib.go
@@ -24,7 +24,7 @@ import (
"sync"
"time"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
)
var defaultSetting = Settings{false, "GogsServer", 60 * time.Second, 60 * time.Second, nil, nil, nil, false}
diff --git a/internal/markup/markup.go b/internal/markup/markup.go
index ad9d7fa1..788708e7 100644
--- a/internal/markup/markup.go
+++ b/internal/markup/markup.go
@@ -216,7 +216,7 @@ func wrapImgWithLink(urlPrefix string, buf *bytes.Buffer, token html.Token) {
buf.WriteString(`">`)
if needPrepend {
- src = strings.Replace(urlPrefix+string(src), " ", "%20", -1)
+ src = strings.Replace(urlPrefix+src, " ", "%20", -1)
buf.WriteString(`<img src="`)
buf.WriteString(src)
buf.WriteString(`"`)
diff --git a/internal/markup/sanitizer.go b/internal/markup/sanitizer.go
index 4a8f6c28..2bd7f2da 100644
--- a/internal/markup/sanitizer.go
+++ b/internal/markup/sanitizer.go
@@ -9,8 +9,8 @@ import (
"github.com/microcosm-cc/bluemonday"
- "gogs.io/gogs/internal/lazyregexp"
"gogs.io/gogs/internal/conf"
+ "gogs.io/gogs/internal/lazyregexp"
)
// Sanitizer is a protection wrapper of *bluemonday.Policy which does not allow
diff --git a/internal/route/admin/admin.go b/internal/route/admin/admin.go
index d1b3bdbf..325876d9 100644
--- a/internal/route/admin/admin.go
+++ b/internal/route/admin/admin.go
@@ -10,7 +10,7 @@ import (
"strings"
"time"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/context"
diff --git a/internal/route/admin/notice.go b/internal/route/admin/notice.go
index 94fc22cd..5e1f377f 100644
--- a/internal/route/admin/notice.go
+++ b/internal/route/admin/notice.go
@@ -64,7 +64,7 @@ func DeleteNotices(c *context.Context) {
func EmptyNotices(c *context.Context) {
if err := db.DeleteNotices(0, 0); err != nil {
- c.Error(err,"delete notices")
+ c.Error(err, "delete notices")
return
}
diff --git a/internal/route/admin/orgs.go b/internal/route/admin/orgs.go
index e2fd4be5..fd034027 100644
--- a/internal/route/admin/orgs.go
+++ b/internal/route/admin/orgs.go
@@ -5,10 +5,10 @@
package admin
import (
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/context"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/route"
- "gogs.io/gogs/internal/conf"
)
const (
diff --git a/internal/route/api/v1/repo/branch.go b/internal/route/api/v1/repo/branch.go
index 3ddf62cc..eb19c657 100644
--- a/internal/route/api/v1/repo/branch.go
+++ b/internal/route/api/v1/repo/branch.go
@@ -25,7 +25,7 @@ func GetBranch(c *context.APIContext) {
return
}
- c.JSONSuccess( convert.ToBranch(branch, commit))
+ c.JSONSuccess(convert.ToBranch(branch, commit))
}
// https://github.com/gogs/go-gogs-client/wiki/Repositories#list-branches
@@ -46,5 +46,5 @@ func ListBranches(c *context.APIContext) {
apiBranches[i] = convert.ToBranch(branches[i], commit)
}
- c.JSONSuccess( &apiBranches)
+ c.JSONSuccess(&apiBranches)
}
diff --git a/internal/route/api/v1/repo/hook.go b/internal/route/api/v1/repo/hook.go
index d5730165..6aa3feb5 100644
--- a/internal/route/api/v1/repo/hook.go
+++ b/internal/route/api/v1/repo/hook.go
@@ -7,11 +7,12 @@ package repo
import (
"net/http"
- api "github.com/gogs/go-gogs-client"
- "github.com/json-iterator/go"
+ jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/unknwon/com"
+ api "github.com/gogs/go-gogs-client"
+
"gogs.io/gogs/internal/context"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/route/api/v1/convert"
diff --git a/internal/route/repo/branch.go b/internal/route/repo/branch.go
index 17630554..dd2508dd 100644
--- a/internal/route/repo/branch.go
+++ b/internal/route/repo/branch.go
@@ -91,7 +91,7 @@ func Branches(c *context.Context) {
c.Data["ActiveBranches"] = activeBranches
c.Data["StaleBranches"] = staleBranches
- c.Success( BRANCHES_OVERVIEW)
+ c.Success(BRANCHES_OVERVIEW)
}
func AllBranches(c *context.Context) {
@@ -104,7 +104,7 @@ func AllBranches(c *context.Context) {
}
c.Data["Branches"] = branches
- c.Success( BRANCHES_ALL)
+ c.Success(BRANCHES_ALL)
}
func DeleteBranchPost(c *context.Context) {
diff --git a/internal/route/repo/release.go b/internal/route/repo/release.go
index 0aeace9a..1b3de8a5 100644
--- a/internal/route/repo/release.go
+++ b/internal/route/repo/release.go
@@ -320,7 +320,7 @@ func DeleteRelease(c *context.Context) {
c.Flash.Success(c.Tr("repo.release.deletion_success"))
}
- c.JSONSuccess( map[string]interface{}{
+ c.JSONSuccess(map[string]interface{}{
"redirect": c.Repo.RepoLink + "/releases",
})
}