summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/auth/auth.go6
-rw-r--r--services/auth/auth_test.go1
-rw-r--r--services/auth/basic.go3
-rw-r--r--services/auth/oauth2.go3
-rw-r--r--services/auth/reverseproxy.go3
-rw-r--r--services/auth/session.go3
-rw-r--r--services/auth/source/ldap/source_sync.go1
-rw-r--r--services/auth/source/oauth2/jwtsigningkey.go2
-rw-r--r--services/auth/source/oauth2/providers.go6
-rw-r--r--services/auth/source/oauth2/providers_openid.go3
-rw-r--r--services/auth/source/oauth2/providers_simple.go1
-rw-r--r--services/auth/source/oauth2/source_callout.go2
-rw-r--r--services/auth/source/smtp/auth.go6
-rw-r--r--services/comments/comments.go2
-rw-r--r--services/cron/cron.go1
-rw-r--r--services/cron/tasks.go10
-rw-r--r--services/forms/repo_form_test.go2
-rw-r--r--services/gitdiff/csv.go10
-rw-r--r--services/gitdiff/csv_test.go11
-rw-r--r--services/gitdiff/gitdiff.go20
-rw-r--r--services/gitdiff/gitdiff_test.go9
-rw-r--r--services/issue/issue.go4
-rw-r--r--services/issue/label_test.go4
-rw-r--r--services/lfs/locks.go6
-rw-r--r--services/lfs/server.go2
-rw-r--r--services/mailer/mail_issue.go1
-rw-r--r--services/mailer/mail_test.go48
-rw-r--r--services/mailer/mailer.go10
-rw-r--r--services/migrations/codebase.go12
-rw-r--r--services/migrations/dump.go12
-rw-r--r--services/migrations/error.go6
-rw-r--r--services/migrations/git.go4
-rw-r--r--services/migrations/gitbucket.go3
-rw-r--r--services/migrations/gitea_downloader.go21
-rw-r--r--services/migrations/gitea_uploader.go42
-rw-r--r--services/migrations/github.go44
-rw-r--r--services/migrations/gitlab.go45
-rw-r--r--services/migrations/gogs.go21
-rw-r--r--services/migrations/migrate.go12
-rw-r--r--services/migrations/onedev.go9
-rw-r--r--services/migrations/restore.go18
-rw-r--r--services/mirror/mirror_pull.go4
-rw-r--r--services/pull/commit_status.go2
-rw-r--r--services/pull/merge.go4
-rw-r--r--services/pull/review.go1
-rw-r--r--services/pull/temp_repo.go2
-rw-r--r--services/pull/update.go2
-rw-r--r--services/release/release.go4
-rw-r--r--services/release/release_test.go2
-rw-r--r--services/repository/adopt.go3
-rw-r--r--services/repository/adopt_test.go2
-rw-r--r--services/repository/archiver/archiver.go2
-rw-r--r--services/repository/archiver/archiver_test.go2
-rw-r--r--services/repository/push.go2
-rw-r--r--services/task/task.go2
-rw-r--r--services/webhook/deliver.go3
-rw-r--r--services/webhook/deliver_test.go2
-rw-r--r--services/webhook/dingtalk.go5
-rw-r--r--services/webhook/discord.go4
-rw-r--r--services/webhook/feishu.go6
-rw-r--r--services/webhook/matrix.go4
-rw-r--r--services/webhook/msteams.go4
-rw-r--r--services/webhook/slack.go4
-rw-r--r--services/webhook/telegram.go4
-rw-r--r--services/webhook/webhook.go70
-rw-r--r--services/webhook/wechatwork.go11
66 files changed, 273 insertions, 307 deletions
diff --git a/services/auth/auth.go b/services/auth/auth.go
index 3eb7f027d2..bdff777f50 100644
--- a/services/auth/auth.go
+++ b/services/auth/auth.go
@@ -95,8 +95,10 @@ func isAttachmentDownload(req *http.Request) bool {
return strings.HasPrefix(req.URL.Path, "/attachments/") && req.Method == "GET"
}
-var gitRawReleasePathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/)|(?:raw/)|(?:releases/download/))`)
-var lfsPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/info/lfs/`)
+var (
+ gitRawReleasePathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/)|(?:raw/)|(?:releases/download/))`)
+ lfsPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/info/lfs/`)
+)
func isGitRawReleaseOrLFSPath(req *http.Request) bool {
if gitRawReleasePathRe.MatchString(req.URL.Path) {
diff --git a/services/auth/auth_test.go b/services/auth/auth_test.go
index b0d23bb4e9..8a9dee6cef 100644
--- a/services/auth/auth_test.go
+++ b/services/auth/auth_test.go
@@ -13,7 +13,6 @@ import (
)
func Test_isGitRawOrLFSPath(t *testing.T) {
-
tests := []struct {
path string
diff --git a/services/auth/basic.go b/services/auth/basic.go
index e2448eeca0..d8667c65d5 100644
--- a/services/auth/basic.go
+++ b/services/auth/basic.go
@@ -30,8 +30,7 @@ const BasicMethodName = "basic"
// Basic implements the Auth interface and authenticates requests (API requests
// only) by looking for Basic authentication data or "x-oauth-basic" token in the "Authorization"
// header.
-type Basic struct {
-}
+type Basic struct{}
// Name represents the name of auth method
func (b *Basic) Name() string {
diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go
index fae981d800..fcff5313e3 100644
--- a/services/auth/oauth2.go
+++ b/services/auth/oauth2.go
@@ -53,8 +53,7 @@ func CheckOAuthAccessToken(accessToken string) int64 {
// OAuth2 implements the Auth interface and authenticates requests
// (API requests only) by looking for an OAuth token in query parameters or the
// "Authorization" header.
-type OAuth2 struct {
-}
+type OAuth2 struct{}
// Name represents the name of auth method
func (o *OAuth2) Name() string {
diff --git a/services/auth/reverseproxy.go b/services/auth/reverseproxy.go
index 3e44d8b863..1b151f6504 100644
--- a/services/auth/reverseproxy.go
+++ b/services/auth/reverseproxy.go
@@ -32,8 +32,7 @@ const ReverseProxyMethodName = "reverse_proxy"
// On successful authentication the proxy is expected to populate the username in the
// "setting.ReverseProxyAuthUser" header. Optionally it can also populate the email of the
// user in the "setting.ReverseProxyAuthEmail" header.
-type ReverseProxy struct {
-}
+type ReverseProxy struct{}
// getUserName extracts the username from the "setting.ReverseProxyAuthUser" header
func (r *ReverseProxy) getUserName(req *http.Request) string {
diff --git a/services/auth/session.go b/services/auth/session.go
index 256598d100..6a23a17665 100644
--- a/services/auth/session.go
+++ b/services/auth/session.go
@@ -19,8 +19,7 @@ var (
// Session checks if there is a user uid stored in the session and returns the user
// object for that uid.
-type Session struct {
-}
+type Session struct{}
// Name represents the name of auth method
func (s *Session) Name() string {
diff --git a/services/auth/source/ldap/source_sync.go b/services/auth/source/ldap/source_sync.go
index 78aa90aaa5..398d9ef798 100644
--- a/services/auth/source/ldap/source_sync.go
+++ b/services/auth/source/ldap/source_sync.go
@@ -164,7 +164,6 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
if err == nil && len(source.AttributeAvatar) > 0 {
_ = user_service.UploadAvatar(usr, su.Avatar)
}
-
}
}
}
diff --git a/services/auth/source/oauth2/jwtsigningkey.go b/services/auth/source/oauth2/jwtsigningkey.go
index 187c6999e0..24f2c41119 100644
--- a/services/auth/source/oauth2/jwtsigningkey.go
+++ b/services/auth/source/oauth2/jwtsigningkey.go
@@ -410,7 +410,7 @@ func loadOrCreateAsymmetricKey() (interface{}, error) {
return err
}
- f, err := os.OpenFile(keyPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
+ f, err := os.OpenFile(keyPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return err
}
diff --git a/services/auth/source/oauth2/providers.go b/services/auth/source/oauth2/providers.go
index 065c6884e0..45851c8799 100644
--- a/services/auth/source/oauth2/providers.go
+++ b/services/auth/source/oauth2/providers.go
@@ -139,10 +139,8 @@ func ClearProviders() {
goth.ClearProviders()
}
-var (
- // ErrAuthSourceNotActived login source is not actived error
- ErrAuthSourceNotActived = errors.New("auth source is not actived")
-)
+// ErrAuthSourceNotActived login source is not actived error
+var ErrAuthSourceNotActived = errors.New("auth source is not actived")
// used to create different types of goth providers
func createProvider(providerName string, source *Source) (goth.Provider, error) {
diff --git a/services/auth/source/oauth2/providers_openid.go b/services/auth/source/oauth2/providers_openid.go
index 838311b4a1..80ee56d4a4 100644
--- a/services/auth/source/oauth2/providers_openid.go
+++ b/services/auth/source/oauth2/providers_openid.go
@@ -13,8 +13,7 @@ import (
)
// OpenIDProvider is a GothProvider for OpenID
-type OpenIDProvider struct {
-}
+type OpenIDProvider struct{}
// Name provides the technical name for this provider
func (o *OpenIDProvider) Name() string {
diff --git a/services/auth/source/oauth2/providers_simple.go b/services/auth/source/oauth2/providers_simple.go
index a4d61eb2f3..0f118b596d 100644
--- a/services/auth/source/oauth2/providers_simple.go
+++ b/services/auth/source/oauth2/providers_simple.go
@@ -107,5 +107,4 @@ func init() {
return microsoftonline.New(clientID, secret, callbackURL, scopes...)
},
))
-
}
diff --git a/services/auth/source/oauth2/source_callout.go b/services/auth/source/oauth2/source_callout.go
index 8596dd187d..7447e5d453 100644
--- a/services/auth/source/oauth2/source_callout.go
+++ b/services/auth/source/oauth2/source_callout.go
@@ -18,7 +18,7 @@ func (source *Source) Callout(request *http.Request, response http.ResponseWrite
// don't use the default gothic begin handler to prevent issues when some error occurs
// normally the gothic library will write some custom stuff to the response instead of our own nice error page
- //gothic.BeginAuthHandler(response, request)
+ // gothic.BeginAuthHandler(response, request)
gothRWMutex.RLock()
defer gothRWMutex.RUnlock()
diff --git a/services/auth/source/smtp/auth.go b/services/auth/source/smtp/auth.go
index c5bd09b0a7..8d0cbb11cd 100644
--- a/services/auth/source/smtp/auth.go
+++ b/services/auth/source/smtp/auth.go
@@ -51,10 +51,8 @@ const (
// Authenticators contains available SMTP authentication type names.
var Authenticators = []string{PlainAuthentication, LoginAuthentication, CRAMMD5Authentication}
-var (
- // ErrUnsupportedLoginType login source is unknown error
- ErrUnsupportedLoginType = errors.New("Login source is unknown")
-)
+// ErrUnsupportedLoginType login source is unknown error
+var ErrUnsupportedLoginType = errors.New("Login source is unknown")
// Authenticate performs an SMTP authentication.
func Authenticate(a smtp.Auth, source *Source) error {
diff --git a/services/comments/comments.go b/services/comments/comments.go
index 296f06d75c..6f63060c45 100644
--- a/services/comments/comments.go
+++ b/services/comments/comments.go
@@ -40,7 +40,7 @@ func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issu
// UpdateComment updates information of comment.
func UpdateComment(c *models.Comment, doer *user_model.User, oldContent string) error {
- var needsContentHistory = c.Content != oldContent &&
+ needsContentHistory := c.Content != oldContent &&
(c.Type == models.CommentTypeComment || c.Type == models.CommentTypeReview || c.Type == models.CommentTypeCode)
if needsContentHistory {
hasContentHistory, err := issues.HasIssueContentHistory(db.DefaultContext, c.IssueID, c.ID)
diff --git a/services/cron/cron.go b/services/cron/cron.go
index ae309bd866..19f703caf1 100644
--- a/services/cron/cron.go
+++ b/services/cron/cron.go
@@ -43,7 +43,6 @@ func NewContext() {
started = false
lock.Unlock()
})
-
}
// TaskTableRow represents a task row in the tasks table
diff --git a/services/cron/tasks.go b/services/cron/tasks.go
index 29062233c8..07da2fe8d6 100644
--- a/services/cron/tasks.go
+++ b/services/cron/tasks.go
@@ -19,10 +19,12 @@ import (
"code.gitea.io/gitea/modules/setting"
)
-var lock = sync.Mutex{}
-var started = false
-var tasks = []*Task{}
-var tasksMap = map[string]*Task{}
+var (
+ lock = sync.Mutex{}
+ started = false
+ tasks = []*Task{}
+ tasksMap = map[string]*Task{}
+)
// Task represents a Cron task
type Task struct {
diff --git a/services/forms/repo_form_test.go b/services/forms/repo_form_test.go
index 4f65d59ca6..198437f7ea 100644
--- a/services/forms/repo_form_test.go
+++ b/services/forms/repo_form_test.go
@@ -13,7 +13,6 @@ import (
)
func TestSubmitReviewForm_IsEmpty(t *testing.T) {
-
cases := []struct {
form SubmitReviewForm
expected bool
@@ -43,7 +42,6 @@ func TestSubmitReviewForm_IsEmpty(t *testing.T) {
}
func TestIssueLock_HasValidReason(t *testing.T) {
-
// Init settings
_ = setting.Repository
diff --git a/services/gitdiff/csv.go b/services/gitdiff/csv.go
index 0e56ff3150..642c9937dd 100644
--- a/services/gitdiff/csv.go
+++ b/services/gitdiff/csv.go
@@ -12,9 +12,11 @@ import (
"code.gitea.io/gitea/modules/util"
)
-const unmappedColumn = -1
-const maxRowsToInspect int = 10
-const minRatioToMatch float32 = 0.8
+const (
+ unmappedColumn = -1
+ maxRowsToInspect int = 10
+ minRatioToMatch float32 = 0.8
+)
// TableDiffCellType represents the type of a TableDiffCell.
type TableDiffCellType uint8
@@ -172,7 +174,7 @@ func createCsvDiff(diffFile *DiffFile, baseReader, headReader *csv.Reader) ([]*T
// createDiffTableRow takes the row # of the `a` line and `b` line of a diff (starting from 1), 0 if the line doesn't exist (undefined)
// in the base or head respectively.
// Returns a TableDiffRow which has the row index
- createDiffTableRow := func(aLineNum int, bLineNum int) (*TableDiffRow, error) {
+ createDiffTableRow := func(aLineNum, bLineNum int) (*TableDiffRow, error) {
// diffTableCells is a row of the diff table. It will have a cells for added, deleted, changed, and unchanged content, thus either
// the same size as the head table or bigger
diffTableCells := make([]*TableDiffCell, numDiffTableCols)
diff --git a/services/gitdiff/csv_test.go b/services/gitdiff/csv_test.go
index 90d24d1c80..2c15b42d91 100644
--- a/services/gitdiff/csv_test.go
+++ b/services/gitdiff/csv_test.go
@@ -16,7 +16,7 @@ import (
)
func TestCSVDiff(t *testing.T) {
- var cases = []struct {
+ cases := []struct {
diff string
base string
head string
@@ -35,7 +35,8 @@ func TestCSVDiff(t *testing.T) {
a,a`,
cells: [][]TableDiffCellType{
{TableDiffCellAdd, TableDiffCellAdd},
- {TableDiffCellAdd, TableDiffCellAdd}},
+ {TableDiffCellAdd, TableDiffCellAdd},
+ },
},
// case 1 - adding 1 row at end
{
@@ -53,7 +54,8 @@ a,a`,
a,a
b,b`,
cells: [][]TableDiffCellType{
- {TableDiffCellUnchanged, TableDiffCellUnchanged}, {TableDiffCellUnchanged, TableDiffCellUnchanged},
+ {TableDiffCellUnchanged, TableDiffCellUnchanged},
+ {TableDiffCellUnchanged, TableDiffCellUnchanged},
{TableDiffCellAdd, TableDiffCellAdd},
},
},
@@ -72,7 +74,8 @@ b,b`,
head: `col1,col2
b,b`,
cells: [][]TableDiffCellType{
- {TableDiffCellUnchanged, TableDiffCellUnchanged}, {TableDiffCellDel, TableDiffCellDel},
+ {TableDiffCellUnchanged, TableDiffCellUnchanged},
+ {TableDiffCellDel, TableDiffCellDel},
{TableDiffCellUnchanged, TableDiffCellUnchanged},
},
},
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 43af2deb4b..25d5e139d9 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -190,9 +190,11 @@ var (
codeTagSuffix = []byte(`</span>`)
)
-var unfinishedtagRegex = regexp.MustCompile(`<[^>]*$`)
-var trailingSpanRegex = regexp.MustCompile(`<span\s*[[:alpha:]="]*?[>]?$`)
-var entityRegex = regexp.MustCompile(`&[#]*?[0-9[:alpha:]]*$`)
+var (
+ unfinishedtagRegex = regexp.MustCompile(`<[^>]*$`)
+ trailingSpanRegex = regexp.MustCompile(`<span\s*[[:alpha:]="]*?[>]?$`)
+ entityRegex = regexp.MustCompile(`&[#]*?[0-9[:alpha:]]*$`)
+)
// shouldWriteInline represents combinations where we manually write inline changes
func shouldWriteInline(diff diffmatchpatch.Diff, lineType DiffLineType) bool {
@@ -206,7 +208,6 @@ func shouldWriteInline(diff diffmatchpatch.Diff, lineType DiffLineType) bool {
}
func fixupBrokenSpans(diffs []diffmatchpatch.Diff) []diffmatchpatch.Diff {
-
// Create a new array to store our fixed up blocks
fixedup := make([]diffmatchpatch.Diff, 0, len(diffs))
@@ -658,10 +659,10 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommitID,
LastRightIdx: lastLine.RightIdx,
LeftIdx: leftLineCount,
RightIdx: rightLineCount,
- }}
+ },
+ }
tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
return tailSection
-
}
func getCommitFileLineCount(commit *git.Commit, filePath string) int {
@@ -942,8 +943,8 @@ parsingLoop:
// TODO: There are numerous issues with this:
// - we might want to consider detecting encoding while parsing but...
// - we're likely to fail to get the correct encoding here anyway as we won't have enough information
- var diffLineTypeBuffers = make(map[DiffLineType]*bytes.Buffer, 3)
- var diffLineTypeDecoders = make(map[DiffLineType]*encoding.Decoder, 3)
+ diffLineTypeBuffers := make(map[DiffLineType]*bytes.Buffer, 3)
+ diffLineTypeDecoders := make(map[DiffLineType]*encoding.Decoder, 3)
diffLineTypeBuffers[DiffLinePlain] = new(bytes.Buffer)
diffLineTypeBuffers[DiffLineAdd] = new(bytes.Buffer)
diffLineTypeBuffers[DiffLineDel] = new(bytes.Buffer)
@@ -1539,7 +1540,8 @@ func GetWhitespaceFlag(whiteSpaceBehavior string) string {
"ignore-all": "-w",
"ignore-change": "-b",
"ignore-eol": "--ignore-space-at-eol",
- "": ""}
+ "": "",
+ }
return whitespaceFlags[whiteSpaceBehavior]
}
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index 57cbb74b22..d57a3e2aba 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -504,7 +504,7 @@ index 6961180..9ba1a00 100644
// Test max lines
diffBuilder := &strings.Builder{}
- var diff = `diff --git a/newfile2 b/newfile2
+ diff := `diff --git a/newfile2 b/newfile2
new file mode 100644
index 0000000..6bb8f39
--- /dev/null
@@ -594,7 +594,7 @@ index 0000000..6bb8f39
}
println(result)
- var diff2 = `diff --git "a/A \\ B" "b/A \\ B"
+ diff2 := `diff --git "a/A \\ B" "b/A \\ B"
--- "a/A \\ B"
+++ "b/A \\ B"
@@ -1,3 +1,6 @@
@@ -611,7 +611,7 @@ index 0000000..6bb8f39
}
println(result)
- var diff2a = `diff --git "a/A \\ B" b/A/B
+ diff2a := `diff --git "a/A \\ B" b/A/B
--- "a/A \\ B"
+++ b/A/B
@@ -1,3 +1,6 @@
@@ -628,7 +628,7 @@ index 0000000..6bb8f39
}
println(result)
- var diff3 = `diff --git a/README.md b/README.md
+ diff3 := `diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
@@ -665,6 +665,7 @@ func setupDefaultDiff() *Diff {
},
}
}
+
func TestDiff_LoadComments(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
diff --git a/services/issue/issue.go b/services/issue/issue.go
index ef2894b929..8b6262c571 100644
--- a/services/issue/issue.go
+++ b/services/issue/issue.go
@@ -162,8 +162,8 @@ func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assign
// GetRefEndNamesAndURLs retrieves the ref end names (e.g. refs/heads/branch-name -> branch-name)
// and their respective URLs.
func GetRefEndNamesAndURLs(issues []*models.Issue, repoLink string) (map[int64]string, map[int64]string) {
- var issueRefEndNames = make(map[int64]string, len(issues))
- var issueRefURLs = make(map[int64]string, len(issues))
+ issueRefEndNames := make(map[int64]string, len(issues))
+ issueRefURLs := make(map[int64]string, len(issues))
for _, issue := range issues {
if issue.Ref != "" {
issueRefEndNames[issue.ID] = git.RefEndName(issue.Ref)
diff --git a/services/issue/label_test.go b/services/issue/label_test.go
index fc94749bdb..73e30e894f 100644
--- a/services/issue/label_test.go
+++ b/services/issue/label_test.go
@@ -15,7 +15,7 @@ import (
)
func TestIssue_AddLabels(t *testing.T) {
- var tests = []struct {
+ tests := []struct {
issueID int64
labelIDs []int64
doerID int64
@@ -41,7 +41,7 @@ func TestIssue_AddLabels(t *testing.T) {
}
func TestIssue_AddLabel(t *testing.T) {
- var tests = []struct {
+ tests := []struct {
issueID int64
labelID int64
doerID int64
diff --git a/services/lfs/locks.go b/services/lfs/locks.go
index c2ede20b7c..3839119b27 100644
--- a/services/lfs/locks.go
+++ b/services/lfs/locks.go
@@ -80,7 +80,7 @@ func GetListLockHandler(ctx *context.Context) {
limit = 0
}
id := ctx.FormString("id")
- if id != "" { //Case where we request a specific id
+ if id != "" { // Case where we request a specific id
v, err := strconv.ParseInt(id, 10, 64)
if err != nil {
ctx.JSON(http.StatusBadRequest, api.LFSLockError{
@@ -97,7 +97,7 @@ func GetListLockHandler(ctx *context.Context) {
}
path := ctx.FormString("path")
- if path != "" { //Case where we request a specific id
+ if path != "" { // Case where we request a specific id
lock, err := models.GetLFSLock(repository, path)
if err != nil && !models.IsErrLFSLockNotExist(err) {
log.Error("Unable to get lock for repository %-v with path %s: Error: %v", repository, path, err)
@@ -106,7 +106,7 @@ func GetListLockHandler(ctx *context.Context) {
return
}
- //If no query params path or id
+ // If no query params path or id
lockList, err := models.GetLFSLockByRepoID(repository.ID, cursor, limit)
if err != nil {
log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err)
diff --git a/services/lfs/server.go b/services/lfs/server.go
index 25882928a2..cdce0046b3 100644
--- a/services/lfs/server.go
+++ b/services/lfs/server.go
@@ -440,7 +440,7 @@ func buildObjectResponse(rc *requestContext, pointer lfs_module.Pointer, downloa
if download {
rep.Actions["download"] = &lfs_module.Link{Href: rc.DownloadLink(pointer), Header: header}
if setting.LFS.ServeDirect {
- //If we have a signed url (S3, object storage), redirect to this directly.
+ // If we have a signed url (S3, object storage), redirect to this directly.
u, err := storage.LFS.URL(pointer.RelativePath(), pointer.Oid)
if u != nil && err == nil {
rep.Actions["download"] = &lfs_module.Link{Href: u.String(), Header: header}
diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go
index 1df8332116..bd5008f076 100644
--- a/services/mailer/mail_issue.go
+++ b/services/mailer/mail_issue.go
@@ -40,7 +40,6 @@ const (
// 1. Repository watchers (except for WIP pull requests) and users who are participated in comments.
// 2. Users who are not in 1. but get mentioned in current issue/comment.
func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
-
// Required by the mail composer; make sure to load these before calling the async function
if err := ctx.Issue.LoadRepo(); err != nil {
return fmt.Errorf("LoadRepo(): %v", err)
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index 6a175337ad..07690063cd 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -44,7 +44,7 @@ const bodyTpl = `
func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment) {
assert.NoError(t, unittest.PrepareTestDatabase())
- var mailService = setting.Mailer{
+ mailService := setting.Mailer{
From: "test@gitea.com",
}
@@ -67,8 +67,10 @@ func TestComposeIssueCommentMessage(t *testing.T) {
InitMailRender(stpl, btpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
- msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
- Content: "test body", Comment: comment}, "en-US", recipients, false, "issue comment")
+ msgs, err := composeIssueCommentMessages(&mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
+ Content: "test body", Comment: comment,
+ }, "en-US", recipients, false, "issue comment")
assert.NoError(t, err)
assert.Len(t, msgs, 2)
gomailMsg := msgs[0].ToMessage()
@@ -94,8 +96,10 @@ func TestComposeIssueMessage(t *testing.T) {
InitMailRender(stpl, btpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
- msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
- Content: "test body"}, "en-US", recipients, false, "issue create")
+ msgs, err := composeIssueCommentMessages(&mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
+ Content: "test body",
+ }, "en-US", recipients, false, "issue create")
assert.NoError(t, err)
assert.Len(t, msgs, 2)
@@ -138,22 +142,30 @@ func TestTemplateSelection(t *testing.T) {
assert.Contains(t, wholemsg, expBody)
}
- msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
- Content: "test body"}, recipients, false, "TestTemplateSelection")
+ msg := testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
+ Content: "test body",
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/new/subject", "issue/new/body")
- msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
- Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
+ msg = testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
+ Content: "test body", Comment: comment,
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/default/subject", "issue/default/body")
pull := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
- msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
- Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
+ msg = testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
+ Content: "test body", Comment: comment,
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "pull/comment/subject", "pull/comment/body")
- msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
- Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
+ msg = testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
+ Content: "test body", Comment: comment,
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body")
}
@@ -162,15 +174,17 @@ func TestTemplateServices(t *testing.T) {
assert.NoError(t, issue.LoadRepo())
expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
- actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string) {
-
+ actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
+ ) {
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
btpl := template.Must(template.New("issue/default").Parse(tplBody))
InitMailRender(stpl, btpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
- msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: actionType,
- Content: "test body", Comment: comment}, recipients, fromMention, "TestTemplateServices")
+ msg := testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: actionType,
+ Content: "test body", Comment: comment,
+ }, recipients, fromMention, "TestTemplateServices")
subject := msg.ToMessage().GetHeader("Subject")
msgbuf := new(bytes.Buffer)
diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go
index e5e6272f10..eeb98b5879 100644
--- a/services/mailer/mailer.go
+++ b/services/mailer/mailer.go
@@ -141,8 +141,7 @@ func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
}
// Sender SMTP mail sender
-type smtpSender struct {
-}
+type smtpSender struct{}
// Send send email
func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
@@ -254,8 +253,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
}
// Sender sendmail mail sender
-type sendmailSender struct {
-}
+type sendmailSender struct{}
// Send send email
func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
@@ -280,7 +278,6 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
cmd := exec.CommandContext(ctx, setting.MailService.SendmailPath, args...)
pipe, err := cmd.StdinPipe()
-
if err != nil {
return err
}
@@ -314,8 +311,7 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
}
// Sender sendmail mail sender
-type dummySender struct {
-}
+type dummySender struct{}
// Send send email
func (s *dummySender) Send(from string, to []string, msg io.WriterTo) error {
diff --git a/services/migrations/codebase.go b/services/migrations/codebase.go
index 395bc6152e..13e9327c33 100644
--- a/services/migrations/codebase.go
+++ b/services/migrations/codebase.go
@@ -30,8 +30,7 @@ func init() {
}
// CodebaseDownloaderFactory defines a downloader factory
-type CodebaseDownloaderFactory struct {
-}
+type CodebaseDownloaderFactory struct{}
// New returns a downloader related to this factory according MigrateOptions
func (f *CodebaseDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
@@ -88,7 +87,7 @@ func (d *CodebaseDownloader) SetContext(ctx context.Context) {
func NewCodebaseDownloader(ctx context.Context, projectURL *url.URL, project, repoName, username, password string) *CodebaseDownloader {
baseURL, _ := url.Parse("https://api3.codebasehq.com")
- var downloader = &CodebaseDownloader{
+ downloader := &CodebaseDownloader{
ctx: ctx,
baseURL: baseURL,
projectURL: projectURL,
@@ -206,7 +205,7 @@ func (d *CodebaseDownloader) GetMilestones() ([]*base.Milestone, error) {
return nil, err
}
- var milestones = make([]*base.Milestone, 0, len(rawMilestones.TicketingMilestone))
+ milestones := make([]*base.Milestone, 0, len(rawMilestones.TicketingMilestone))
for _, milestone := range rawMilestones.TicketingMilestone {
var deadline *time.Time
if len(milestone.Deadline.Value) > 0 {
@@ -256,7 +255,7 @@ func (d *CodebaseDownloader) GetLabels() ([]*base.Label, error) {
return nil, err
}
- var labels = make([]*base.Label, 0, len(rawTypes.TicketingType))
+ labels := make([]*base.Label, 0, len(rawTypes.TicketingType))
for _, label := range rawTypes.TicketingType {
labels = append(labels, &base.Label{
Name: label.Name,
@@ -400,7 +399,8 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
Created: issue.CreatedAt.Value,
Updated: issue.UpdatedAt.Value,
Labels: []*base.Label{
- {Name: issue.Type.Name}},
+ {Name: issue.Type.Name},
+ },
Context: codebaseIssueContext{
foreignID: issue.TicketID.Value,
localID: issue.TicketID.Value,
diff --git a/services/migrations/dump.go b/services/migrations/dump.go
index f4e797b357..01a946673e 100644
--- a/services/migrations/dump.go
+++ b/services/migrations/dump.go
@@ -27,9 +27,7 @@ import (
"gopkg.in/yaml.v2"
)
-var (
- _ base.Uploader = &RepositoryDumper{}
-)
+var _ base.Uploader = &RepositoryDumper{}
// RepositoryDumper implements an Uploader to the local directory
type RepositoryDumper struct {
@@ -403,7 +401,7 @@ func (g *RepositoryDumper) createItems(dir string, itemFiles map[int64]*os.File,
// CreateComments creates comments of issues
func (g *RepositoryDumper) CreateComments(comments ...*base.Comment) error {
- var commentsMap = make(map[int64][]interface{}, len(comments))
+ commentsMap := make(map[int64][]interface{}, len(comments))
for _, comment := range comments {
commentsMap[comment.IssueIndex] = append(commentsMap[comment.IssueIndex], comment)
}
@@ -532,7 +530,7 @@ func (g *RepositoryDumper) CreatePullRequests(prs ...*base.PullRequest) error {
// CreateReviews create pull request reviews
func (g *RepositoryDumper) CreateReviews(reviews ...*base.Review) error {
- var reviewsMap = make(map[int64][]interface{}, len(reviews))
+ reviewsMap := make(map[int64][]interface{}, len(reviews))
for _, review := range reviews {
reviewsMap[review.IssueIndex] = append(reviewsMap[review.IssueIndex], review)
}
@@ -611,7 +609,7 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
if err != nil {
return err
}
- var uploader = NewGiteaLocalUploader(ctx, doer, ownerName, repoName)
+ uploader := NewGiteaLocalUploader(ctx, doer, ownerName, repoName)
downloader, err := NewRepositoryRestorer(ctx, baseDir, ownerName, repoName)
if err != nil {
return err
@@ -622,7 +620,7 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
}
tp, _ := strconv.Atoi(opts["service_type"])
- var migrateOpts = base.MigrateOptions{
+ migrateOpts := base.MigrateOptions{
GitServiceType: structs.GitServiceType(tp),
}
updateOptionsUnits(&migrateOpts, units)
diff --git a/services/migrations/error.go b/services/migrations/error.go
index b90d1b6577..3b3f975012 100644
--- a/services/migrations/error.go
+++ b/services/migrations/error.go
@@ -11,10 +11,8 @@ import (
"github.com/google/go-github/v39/github"
)
-var (
- // ErrRepoNotCreated returns the error that repository not created
- ErrRepoNotCreated = errors.New("repository is not created yet")
-)
+// ErrRepoNotCreated returns the error that repository not created
+var ErrRepoNotCreated = errors.New("repository is not created yet")
// IsRateLimitError returns true if the err is github.RateLimitError
func IsRateLimitError(err error) bool {
diff --git a/services/migrations/git.go b/services/migrations/git.go
index 37ffb674c5..3198f934ca 100644
--- a/services/migrations/git.go
+++ b/services/migrations/git.go
@@ -10,9 +10,7 @@ import (
base "code.gitea.io/gitea/modules/migration"
)
-var (
- _ base.Downloader = &PlainGitDownloader{}
-)
+var _ base.Downloader = &PlainGitDownloader{}
// PlainGitDownloader implements a Downloader interface to clone git from a http/https URL
type PlainGitDownloader struct {
diff --git a/services/migrations/gitbucket.go b/services/migrations/gitbucket.go
index 27ed584aa2..c4fb0df93a 100644
--- a/services/migrations/gitbucket.go
+++ b/services/migrations/gitbucket.go
@@ -23,8 +23,7 @@ func init() {
}
// GitBucketDownloaderFactory defines a GitBucket downloader factory
-type GitBucketDownloaderFactory struct {
-}
+type GitBucketDownloaderFactory struct{}
// New returns a Downloader related to this factory according MigrateOptions
func (f *GitBucketDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
diff --git a/services/migrations/gitea_downloader.go b/services/migrations/gitea_downloader.go
index 258f030726..a712b65a22 100644
--- a/services/migrations/gitea_downloader.go
+++ b/services/migrations/gitea_downloader.go
@@ -32,8 +32,7 @@ func init() {
}
// GiteaDownloaderFactory defines a gitea downloader factory
-type GiteaDownloaderFactory struct {
-}
+type GiteaDownloaderFactory struct{}
// New returns a Downloader related to this factory according MigrateOptions
func (f *GiteaDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
@@ -159,7 +158,7 @@ func (g *GiteaDownloader) GetTopics() ([]string, error) {
// GetMilestones returns milestones
func (g *GiteaDownloader) GetMilestones() ([]*base.Milestone, error) {
- var milestones = make([]*base.Milestone, 0, g.maxPerPage)
+ milestones := make([]*base.Milestone, 0, g.maxPerPage)
for i := 1; ; i++ {
// make sure gitea can shutdown gracefully
@@ -224,7 +223,7 @@ func (g *GiteaDownloader) convertGiteaLabel(label *gitea_sdk.Label) *base.Label
// GetLabels returns labels
func (g *GiteaDownloader) GetLabels() ([]*base.Label, error) {
- var labels = make([]*base.Label, 0, g.maxPerPage)
+ labels := make([]*base.Label, 0, g.maxPerPage)
for i := 1; ; i++ {
// make sure gitea can shutdown gracefully
@@ -304,7 +303,7 @@ func (g *GiteaDownloader) convertGiteaRelease(rel *gitea_sdk.Release) *base.Rele
// GetReleases returns releases
func (g *GiteaDownloader) GetReleases() ([]*base.Release, error) {
- var releases = make([]*base.Release, 0, g.maxPerPage)
+ releases := make([]*base.Release, 0, g.maxPerPage)
for i := 1; ; i++ {
// make sure gitea can shutdown gracefully
@@ -379,7 +378,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
if perPage > g.maxPerPage {
perPage = g.maxPerPage
}
- var allIssues = make([]*base.Issue, 0, perPage)
+ allIssues := make([]*base.Issue, 0, perPage)
issues, _, err := g.client.ListRepoIssues(g.repoOwner, g.repoName, gitea_sdk.ListIssueOption{
ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: perPage},
@@ -391,7 +390,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
}
for _, issue := range issues {
- var labels = make([]*base.Label, 0, len(issue.Labels))
+ labels := make([]*base.Label, 0, len(issue.Labels))
for i := range issue.Labels {
labels = append(labels, g.convertGiteaLabel(issue.Labels[i]))
}
@@ -444,7 +443,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
// GetComments returns comments according issueNumber
func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
- var allComments = make([]*base.Comment, 0, g.maxPerPage)
+ allComments := make([]*base.Comment, 0, g.maxPerPage)
for i := 1; ; i++ {
// make sure gitea can shutdown gracefully
@@ -496,7 +495,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
if perPage > g.maxPerPage {
perPage = g.maxPerPage
}
- var allPRs = make([]*base.PullRequest, 0, perPage)
+ allPRs := make([]*base.PullRequest, 0, perPage)
prs, _, err := g.client.ListRepoPullRequests(g.repoOwner, g.repoName, gitea_sdk.ListPullRequestsOptions{
ListOptions: gitea_sdk.ListOptions{
@@ -514,7 +513,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
milestone = pr.Milestone.Title
}
- var labels = make([]*base.Label, 0, len(pr.Labels))
+ labels := make([]*base.Label, 0, len(pr.Labels))
for i := range pr.Labels {
labels = append(labels, g.convertGiteaLabel(pr.Labels[i]))
}
@@ -620,7 +619,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review,
return nil, nil
}
- var allReviews = make([]*base.Review, 0, g.maxPerPage)
+ allReviews := make([]*base.Review, 0, g.maxPerPage)
for i := 1; ; i++ {
// make sure gitea can shutdown gracefully
diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go
index e939046e90..6e823031ed 100644
--- a/services/migrations/gitea_uploader.go
+++ b/services/migrations/gitea_uploader.go
@@ -33,9 +33,7 @@ import (
gouuid "github.com/google/uuid"
)
-var (
- _ base.Uploader = &GiteaLocalUploader{}
-)
+var _ base.Uploader = &GiteaLocalUploader{}
// GiteaLocalUploader implements an Uploader to gitea sites
type GiteaLocalUploader struct {
@@ -159,7 +157,7 @@ func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
// CreateMilestones creates milestones
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error {
- var mss = make([]*models.Milestone, 0, len(milestones))
+ mss := make([]*models.Milestone, 0, len(milestones))
for _, milestone := range milestones {
var deadline timeutil.TimeStamp
if milestone.Deadline != nil {
@@ -182,7 +180,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err
milestone.Updated = &milestone.Created
}
- var ms = models.Milestone{
+ ms := models.Milestone{
RepoID: g.repo.ID,
Name: milestone.Title,
Content: milestone.Description,
@@ -210,7 +208,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err
// CreateLabels creates labels
func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
- var lbs = make([]*models.Label, 0, len(labels))
+ lbs := make([]*models.Label, 0, len(labels))
for _, label := range labels {
lbs = append(lbs, &models.Label{
RepoID: g.repo.ID,
@@ -232,7 +230,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
// CreateReleases creates releases
func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
- var rels = make([]*models.Release, 0, len(releases))
+ rels := make([]*models.Release, 0, len(releases))
for _, release := range releases {
if release.Created.IsZero() {
if !release.Published.IsZero() {
@@ -242,7 +240,7 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
}
}
- var rel = models.Release{
+ rel := models.Release{
RepoID: g.repo.ID,
TagName: release.TagName,
LowerTagName: strings.ToLower(release.TagName),
@@ -297,7 +295,7 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
asset.Created = release.Created
}
}
- var attach = repo_model.Attachment{
+ attach := repo_model.Attachment{
UUID: gouuid.New().String(),
Name: asset.Name,
DownloadCount: int64(*asset.DownloadCount),
@@ -348,7 +346,7 @@ func (g *GiteaLocalUploader) SyncTags() error {
// CreateIssues creates issues
func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
- var iss = make([]*models.Issue, 0, len(issues))
+ iss := make([]*models.Issue, 0, len(issues))
for _, issue := range issues {
var labels []*models.Label
for _, label := range issue.Labels {
@@ -381,7 +379,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
}
}
- var is = models.Issue{
+ is := models.Issue{
RepoID: g.repo.ID,
Repo: g.repo,
Index: issue.Number,
@@ -433,7 +431,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
g.userMap[reaction.UserID] = userid
}
}
- var res = models.Reaction{
+ res := models.Reaction{
Type: reaction.Content,
CreatedUnix: timeutil.TimeStampNow(),
}
@@ -464,7 +462,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
// CreateComments creates comments of issues
func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
- var cms = make([]*models.Comment, 0, len(comments))
+ cms := make([]*models.Comment, 0, len(comments))
for _, comment := range comments {
var issue *models.Issue
issueInter, ok := g.issues.Load(comment.IssueIndex)
@@ -528,7 +526,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
g.userMap[reaction.UserID] = userid
}
}
- var res = models.Reaction{
+ res := models.Reaction{
Type: reaction.Content,
CreatedUnix: timeutil.TimeStampNow(),
}
@@ -553,7 +551,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
// CreatePullRequests creates pull requests
func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error {
- var gprs = make([]*models.PullRequest, 0, len(prs))
+ gprs := make([]*models.PullRequest, 0, len(prs))
for _, pr := range prs {
gpr, err := g.newPullRequest(pr)
if err != nil {
@@ -652,7 +650,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
return nil, err
}
- var head = "unknown repository"
+ head := "unknown repository"
if pr.IsForkPullRequest() && pr.State != "closed" {
if pr.Head.OwnerName != "" {
remote := pr.Head.OwnerName
@@ -723,7 +721,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
pr.Updated = pr.Created
}
- var issue = models.Issue{
+ issue := models.Issue{
RepoID: g.repo.ID,
Repo: g.repo,
Title: pr.Title,
@@ -773,7 +771,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
g.userMap[reaction.UserID] = userid
}
}
- var res = models.Reaction{
+ res := models.Reaction{
Type: reaction.Content,
CreatedUnix: timeutil.TimeStampNow(),
}
@@ -787,7 +785,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
issue.Reactions = append(issue.Reactions, &res)
}
- var pullRequest = models.PullRequest{
+ pullRequest := models.PullRequest{
HeadRepoID: g.repo.ID,
HeadBranch: head,
BaseRepoID: g.repo.ID,
@@ -830,7 +828,7 @@ func convertReviewState(state string) models.ReviewType {
// CreateReviews create pull request reviews
func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
- var cms = make([]*models.Review, 0, len(reviews))
+ cms := make([]*models.Review, 0, len(reviews))
for _, review := range reviews {
var issue *models.Issue
issueInter, ok := g.issues.Load(review.IssueIndex)
@@ -862,7 +860,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
review.CreatedAt = time.Unix(int64(issue.CreatedUnix), 0)
}
- var cm = models.Review{
+ cm := models.Review{
Type: convertReviewState(review.State),
IssueID: issue.ID,
Content: review.Content,
@@ -926,7 +924,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
comment.UpdatedAt = comment.CreatedAt
}
- var c = models.Comment{
+ c := models.Comment{
Type: models.CommentTypeCode,
PosterID: comment.PosterID,
IssueID: issue.ID,
diff --git a/services/migrations/github.go b/services/migrations/github.go
index b360b05061..a946177c90 100644
--- a/services/migrations/github.go
+++ b/services/migrations/github.go
@@ -37,8 +37,7 @@ func init() {
}
// GithubDownloaderV3Factory defines a github downloader v3 factory
-type GithubDownloaderV3Factory struct {
-}
+type GithubDownloaderV3Factory struct{}
// New returns a Downloader related to this factory according MigrateOptions
func (f *GithubDownloaderV3Factory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
@@ -80,7 +79,7 @@ type GithubDownloaderV3 struct {
// NewGithubDownloaderV3 creates a github Downloader via github v3 API
func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GithubDownloaderV3 {
- var downloader = GithubDownloaderV3{
+ downloader := GithubDownloaderV3{
userName: userName,
password: password,
ctx: ctx,
@@ -96,7 +95,7 @@ func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, tok
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
- var client = &http.Client{
+ client := &http.Client{
Transport: &oauth2.Transport{
Base: NewMigrationHTTPTransport(),
Source: oauth2.ReuseTokenSource(nil, ts),
@@ -106,12 +105,12 @@ func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, tok
downloader.addClient(client, baseURL)
}
} else {
- var transport = NewMigrationHTTPTransport()
+ transport := NewMigrationHTTPTransport()
transport.Proxy = func(req *http.Request) (*url.URL, error) {
req.SetBasicAuth(userName, password)
return proxy.Proxy()(req)
}
- var client = &http.Client{
+ client := &http.Client{
Transport: transport,
}
downloader.addClient(client, baseURL)
@@ -218,8 +217,8 @@ func (g *GithubDownloaderV3) GetTopics() ([]string, error) {
// GetMilestones returns milestones
func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
- var perPage = g.maxPerPage
- var milestones = make([]*base.Milestone, 0, perPage)
+ perPage := g.maxPerPage
+ milestones := make([]*base.Milestone, 0, perPage)
for i := 1; ; i++ {
g.waitAndPickClient()
ms, resp, err := g.getClient().Issues.ListMilestones(g.ctx, g.repoOwner, g.repoName,
@@ -228,14 +227,15 @@ func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
ListOptions: github.ListOptions{
Page: i,
PerPage: perPage,
- }})
+ },
+ })
if err != nil {
return nil, err
}
g.setRate(&resp.Rate)
for _, m := range ms {
- var state = "open"
+ state := "open"
if m.State != nil {
state = *m.State
}
@@ -266,8 +266,8 @@ func convertGithubLabel(label *github.Label) *base.Label {
// GetLabels returns labels
func (g *GithubDownloaderV3) GetLabels() ([]*base.Label, error) {
- var perPage = g.maxPerPage
- var labels = make([]*base.Label, 0, perPage)
+ perPage := g.maxPerPage
+ labels := make([]*base.Label, 0, perPage)
for i := 1; ; i++ {
g.waitAndPickClient()
ls, resp, err := g.getClient().Issues.ListLabels(g.ctx, g.repoOwner, g.repoName,
@@ -311,7 +311,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
httpClient := NewMigrationHTTPClient()
for _, asset := range rel.Assets {
- var assetID = *asset.ID // Don't optimize this, for closure we need a local variable
+ assetID := *asset.ID // Don't optimize this, for closure we need a local variable
r.Assets = append(r.Assets, &base.ReleaseAsset{
ID: asset.GetID(),
Name: asset.GetName(),
@@ -357,8 +357,8 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
// GetReleases returns releases
func (g *GithubDownloaderV3) GetReleases() ([]*base.Release, error) {
- var perPage = g.maxPerPage
- var releases = make([]*base.Release, 0, perPage)
+ perPage := g.maxPerPage
+ releases := make([]*base.Release, 0, perPage)
for i := 1; ; i++ {
g.waitAndPickClient()
ls, resp, err := g.getClient().Repositories.ListReleases(g.ctx, g.repoOwner, g.repoName,
@@ -396,7 +396,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
},
}
- var allIssues = make([]*base.Issue, 0, perPage)
+ allIssues := make([]*base.Issue, 0, perPage)
g.waitAndPickClient()
issues, resp, err := g.getClient().Issues.ListByRepo(g.ctx, g.repoOwner, g.repoName, opt)
if err != nil {
@@ -409,7 +409,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
continue
}
- var labels = make([]*base.Label, 0, len(issue.Labels))
+ labels := make([]*base.Label, 0, len(issue.Labels))
for _, l := range issue.Labels {
labels = append(labels, convertGithubLabel(l))
}
@@ -573,7 +573,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
if err != nil {
return nil, false, fmt.Errorf("error while listing repos: %v", err)
}
- var isEnd = resp.NextPage == 0
+ isEnd := resp.NextPage == 0
log.Trace("Request get comments %d/%d, but in fact get %d, next page is %d", perPage, page, len(comments), resp.NextPage)
g.setRate(&resp.Rate)
@@ -634,7 +634,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
Page: page,
},
}
- var allPRs = make([]*base.PullRequest, 0, perPage)
+ allPRs := make([]*base.PullRequest, 0, perPage)
g.waitAndPickClient()
prs, resp, err := g.getClient().PullRequests.List(g.ctx, g.repoOwner, g.repoName, opt)
if err != nil {
@@ -643,7 +643,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
log.Trace("Request get pull requests %d/%d, but in fact get %d", perPage, page, len(prs))
g.setRate(&resp.Rate)
for _, pr := range prs {
- var labels = make([]*base.Label, 0, len(pr.Labels))
+ labels := make([]*base.Label, 0, len(pr.Labels))
for _, l := range pr.Labels {
labels = append(labels, convertGithubLabel(l))
}
@@ -729,7 +729,7 @@ func convertGithubReview(r *github.PullRequestReview) *base.Review {
}
func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullRequestComment) ([]*base.ReviewComment, error) {
- var rcs = make([]*base.ReviewComment, 0, len(cs))
+ rcs := make([]*base.ReviewComment, 0, len(cs))
for _, c := range cs {
// get reactions
var reactions []*base.Reaction
@@ -776,7 +776,7 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
// GetReviews returns pull requests review
func (g *GithubDownloaderV3) GetReviews(context base.IssueContext) ([]*base.Review, error) {
- var allReviews = make([]*base.Review, 0, g.maxPerPage)
+ allReviews := make([]*base.Review, 0, g.maxPerPage)
opt := &github.ListOptions{
PerPage: g.maxPerPage,
}
diff --git a/services/migrations/gitlab.go b/services/migrations/gitlab.go
index 4eb7e3e47c..a9856739c2 100644
--- a/services/migrations/gitlab.go
+++ b/services/migrations/gitlab.go
@@ -32,8 +32,7 @@ func init() {
}
// GitlabDownloaderFactory defines a gitlab downloader factory
-type GitlabDownloaderFactory struct {
-}
+type GitlabDownloaderFactory struct{}
// New returns a Downloader related to this factory according MigrateOptions
func (f *GitlabDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
@@ -184,16 +183,17 @@ func (g *GitlabDownloader) GetTopics() ([]string, error) {
// GetMilestones returns milestones
func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
- var perPage = g.maxPerPage
- var state = "all"
- var milestones = make([]*base.Milestone, 0, perPage)
+ perPage := g.maxPerPage
+ state := "all"
+ milestones := make([]*base.Milestone, 0, perPage)
for i := 1; ; i++ {
ms, _, err := g.client.Milestones.ListMilestones(g.repoID, &gitlab.ListMilestonesOptions{
State: &state,
ListOptions: gitlab.ListOptions{
Page: i,
PerPage: perPage,
- }}, nil, gitlab.WithContext(g.ctx))
+ },
+ }, nil, gitlab.WithContext(g.ctx))
if err != nil {
return nil, err
}
@@ -203,7 +203,7 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
if m.Description != "" {
desc = m.Description
}
- var state = "open"
+ state := "open"
var closedAt *time.Time
if m.State != "" {
state = m.State
@@ -255,8 +255,8 @@ func (g *GitlabDownloader) normalizeColor(val string) string {
// GetLabels returns labels
func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
- var perPage = g.maxPerPage
- var labels = make([]*base.Label, 0, perPage)
+ perPage := g.maxPerPage
+ labels := make([]*base.Label, 0, perPage)
for i := 1; ; i++ {
ls, _, err := g.client.Labels.ListLabels(g.repoID, &gitlab.ListLabelsOptions{ListOptions: gitlab.ListOptions{
Page: i,
@@ -327,8 +327,8 @@ func (g *GitlabDownloader) convertGitlabRelease(rel *gitlab.Release) *base.Relea
// GetReleases returns releases
func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
- var perPage = g.maxPerPage
- var releases = make([]*base.Release, 0, perPage)
+ perPage := g.maxPerPage
+ releases := make([]*base.Release, 0, perPage)
for i := 1; ; i++ {
ls, _, err := g.client.Releases.ListReleases(g.repoID, &gitlab.ListReleasesOptions{
Page: i,
@@ -381,7 +381,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
},
}
- var allIssues = make([]*base.Issue, 0, perPage)
+ allIssues := make([]*base.Issue, 0, perPage)
issues, _, err := g.client.Issues.ListProjectIssues(g.repoID, opt, nil, gitlab.WithContext(g.ctx))
if err != nil {
@@ -389,7 +389,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
}
for _, issue := range issues {
- var labels = make([]*base.Label, 0, len(issue.Labels))
+ labels := make([]*base.Label, 0, len(issue.Labels))
for _, l := range issue.Labels {
labels = append(labels, &base.Label{
Name: l,
@@ -402,7 +402,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
}
var reactions []*base.Reaction
- var awardPage = 1
+ awardPage := 1
for {
awards, _, err := g.client.AwardEmoji.ListIssueAwardEmoji(g.repoID, issue.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx))
if err != nil {
@@ -456,9 +456,9 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
return nil, false, fmt.Errorf("unexpected context: %+v", opts.Context)
}
- var allComments = make([]*base.Comment, 0, g.maxPerPage)
+ allComments := make([]*base.Comment, 0, g.maxPerPage)
- var page = 1
+ page := 1
for {
var comments []*gitlab.Discussion
@@ -503,7 +503,6 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
Created: *c.CreatedAt,
})
}
-
}
if resp.NextPage == 0 {
break
@@ -526,7 +525,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
},
}
- var allPRs = make([]*base.PullRequest, 0, perPage)
+ allPRs := make([]*base.PullRequest, 0, perPage)
prs, _, err := g.client.MergeRequests.ListProjectMergeRequests(g.repoID, opt, nil, gitlab.WithContext(g.ctx))
if err != nil {
@@ -534,7 +533,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
}
for _, pr := range prs {
- var labels = make([]*base.Label, 0, len(pr.Labels))
+ labels := make([]*base.Label, 0, len(pr.Labels))
for _, l := range pr.Labels {
labels = append(labels, &base.Label{
Name: l,
@@ -547,12 +546,12 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
pr.State = "closed"
}
- var mergeTime = pr.MergedAt
+ mergeTime := pr.MergedAt
if merged && pr.MergedAt == nil {
mergeTime = pr.UpdatedAt
}
- var closeTime = pr.ClosedAt
+ closeTime := pr.ClosedAt
if merged && pr.ClosedAt == nil {
closeTime = pr.UpdatedAt
}
@@ -568,7 +567,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
}
var reactions []*base.Reaction
- var awardPage = 1
+ awardPage := 1
for {
awards, _, err := g.client.AwardEmoji.ListMergeRequestAwardEmoji(g.repoID, pr.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx))
if err != nil {
@@ -641,7 +640,7 @@ func (g *GitlabDownloader) GetReviews(context base.IssueContext) ([]*base.Review
return nil, err
}
- var reviews = make([]*base.Review, 0, len(approvals.ApprovedBy))
+ reviews := make([]*base.Review, 0, len(approvals.ApprovedBy))
for _, user := range approvals.ApprovedBy {
reviews = append(reviews, &base.Review{
IssueIndex: context.LocalID(),
diff --git a/services/migrations/gogs.go b/services/migrations/gogs.go
index e103ef996e..9280427cd7 100644
--- a/services/migrations/gogs.go
+++ b/services/migrations/gogs.go
@@ -30,8 +30,7 @@ func init() {
}
// GogsDownloaderFactory defines a gogs downloader factory
-type GogsDownloaderFactory struct {
-}
+type GogsDownloaderFactory struct{}
// New returns a Downloader related to this factory according MigrateOptions
func (f *GogsDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
@@ -81,7 +80,7 @@ func (g *GogsDownloader) SetContext(ctx context.Context) {
// NewGogsDownloader creates a gogs Downloader via gogs API
func NewGogsDownloader(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GogsDownloader {
- var downloader = GogsDownloader{
+ downloader := GogsDownloader{
ctx: ctx,
baseURL: baseURL,
userName: userName,
@@ -95,7 +94,7 @@ func NewGogsDownloader(ctx context.Context, baseURL, userName, password, token,
client = gogs.NewClient(baseURL, token)
downloader.userName = token
} else {
- var transport = NewMigrationHTTPTransport()
+ transport := NewMigrationHTTPTransport()
transport.Proxy = func(req *http.Request) (*url.URL, error) {
req.SetBasicAuth(userName, password)
return proxy.Proxy()(req)
@@ -139,8 +138,8 @@ func (g *GogsDownloader) GetRepoInfo() (*base.Repository, error) {
// GetMilestones returns milestones
func (g *GogsDownloader) GetMilestones() ([]*base.Milestone, error) {
- var perPage = 100
- var milestones = make([]*base.Milestone, 0, perPage)
+ perPage := 100
+ milestones := make([]*base.Milestone, 0, perPage)
ms, err := g.client.ListRepoMilestones(g.repoOwner, g.repoName)
if err != nil {
@@ -162,8 +161,8 @@ func (g *GogsDownloader) GetMilestones() ([]*base.Milestone, error) {
// GetLabels returns labels
func (g *GogsDownloader) GetLabels() ([]*base.Label, error) {
- var perPage = 100
- var labels = make([]*base.Label, 0, perPage)
+ perPage := 100
+ labels := make([]*base.Label, 0, perPage)
ls, err := g.client.ListRepoLabels(g.repoOwner, g.repoName)
if err != nil {
return nil, err
@@ -203,7 +202,7 @@ func (g *GogsDownloader) GetIssues(page, _ int) ([]*base.Issue, bool, error) {
}
func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool, error) {
- var allIssues = make([]*base.Issue, 0, 10)
+ allIssues := make([]*base.Issue, 0, 10)
issues, err := g.client.ListRepoIssues(g.repoOwner, g.repoName, gogs.ListIssueOption{
Page: page,
@@ -225,7 +224,7 @@ func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool,
// GetComments returns comments according issueNumber
func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
- var allComments = make([]*base.Comment, 0, 100)
+ allComments := make([]*base.Comment, 0, 100)
comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID())
if err != nil {
@@ -276,7 +275,7 @@ func convertGogsIssue(issue *gogs.Issue) *base.Issue {
if issue.Milestone != nil {
milestone = issue.Milestone.Title
}
- var labels = make([]*base.Label, 0, len(issue.Labels))
+ labels := make([]*base.Label, 0, len(issue.Labels))
for _, l := range issue.Labels {
labels = append(labels, convertGogsLabel(l))
}
diff --git a/services/migrations/migrate.go b/services/migrations/migrate.go
index 65ecceddbe..7bca128ac5 100644
--- a/services/migrations/migrate.go
+++ b/services/migrations/migrate.go
@@ -123,7 +123,7 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
return nil, err
}
- var uploader = NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName)
+ uploader := NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName)
uploader.gitServiceType = opts.GitServiceType
if err := migrateRepository(downloader, uploader, opts, messenger); err != nil {
@@ -305,7 +305,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
if opts.Issues {
log.Trace("migrating issues and comments")
messenger("repo.migrate.migrating_issues")
- var issueBatchSize = uploader.MaxBatchInsertSize("issue")
+ issueBatchSize := uploader.MaxBatchInsertSize("issue")
for i := 1; ; i++ {
issues, isEnd, err := downloader.GetIssues(i, issueBatchSize)
@@ -322,7 +322,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
}
if opts.Comments && !supportAllComments {
- var allComments = make([]*base.Comment, 0, commentBatchSize)
+ allComments := make([]*base.Comment, 0, commentBatchSize)
for _, issue := range issues {
log.Trace("migrating issue %d's comments", issue.Number)
comments, _, err := downloader.GetComments(base.GetCommentOptions{
@@ -362,7 +362,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
if opts.PullRequests {
log.Trace("migrating pull requests and comments")
messenger("repo.migrate.migrating_pulls")
- var prBatchSize = uploader.MaxBatchInsertSize("pullrequest")
+ prBatchSize := uploader.MaxBatchInsertSize("pullrequest")
for i := 1; ; i++ {
prs, isEnd, err := downloader.GetPullRequests(i, prBatchSize)
if err != nil {
@@ -380,7 +380,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
if opts.Comments {
if !supportAllComments {
// plain comments
- var allComments = make([]*base.Comment, 0, commentBatchSize)
+ allComments := make([]*base.Comment, 0, commentBatchSize)
for _, pr := range prs {
log.Trace("migrating pull request %d's comments", pr.Number)
comments, _, err := downloader.GetComments(base.GetCommentOptions{
@@ -410,7 +410,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
}
// migrate reviews
- var allReviews = make([]*base.Review, 0, reviewBatchSize)
+ allReviews := make([]*base.Review, 0, reviewBatchSize)
for _, pr := range prs {
reviews, err := downloader.GetReviews(pr.Context)
if err != nil {
diff --git a/services/migrations/onedev.go b/services/migrations/onedev.go
index bb676131f3..c8253e8947 100644
--- a/services/migrations/onedev.go
+++ b/services/migrations/onedev.go
@@ -29,8 +29,7 @@ func init() {
}
// OneDevDownloaderFactory defines a downloader factory
-type OneDevDownloaderFactory struct {
-}
+type OneDevDownloaderFactory struct{}
// New returns a downloader related to this factory according MigrateOptions
func (f *OneDevDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
@@ -90,7 +89,7 @@ func (d *OneDevDownloader) SetContext(ctx context.Context) {
// NewOneDevDownloader creates a new downloader
func NewOneDevDownloader(ctx context.Context, baseURL *url.URL, username, password, repoName string) *OneDevDownloader {
- var downloader = &OneDevDownloader{
+ downloader := &OneDevDownloader{
ctx: ctx,
baseURL: baseURL,
repoName: repoName,
@@ -195,7 +194,7 @@ func (d *OneDevDownloader) GetMilestones() ([]*base.Milestone, error) {
endpoint := fmt.Sprintf("/api/projects/%d/milestones", d.repoID)
- var milestones = make([]*base.Milestone, 0, 100)
+ milestones := make([]*base.Milestone, 0, 100)
offset := 0
for {
err := d.callAPI(
@@ -583,7 +582,7 @@ func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review
return nil, err
}
- var reviews = make([]*base.Review, 0, len(rawReviews))
+ reviews := make([]*base.Review, 0, len(rawReviews))
for _, review := range rawReviews {
state := base.ReviewStatePending
content := ""
diff --git a/services/migrations/restore.go b/services/migrations/restore.go
index 357e995423..4499f78701 100644
--- a/services/migrations/restore.go
+++ b/services/migrations/restore.go
@@ -59,7 +59,7 @@ func (r *RepositoryRestorer) getRepoOptions() (map[string]string, error) {
return nil, err
}
- var opts = make(map[string]string)
+ opts := make(map[string]string)
err = yaml.Unmarshal(bs, &opts)
if err != nil {
return nil, err
@@ -91,7 +91,7 @@ func (r *RepositoryRestorer) GetRepoInfo() (*base.Repository, error) {
func (r *RepositoryRestorer) GetTopics() ([]string, error) {
p := filepath.Join(r.baseDir, "topic.yml")
- var topics = struct {
+ topics := struct {
Topics []string `yaml:"topics"`
}{}
@@ -109,7 +109,7 @@ func (r *RepositoryRestorer) GetTopics() ([]string, error) {
// GetMilestones returns milestones
func (r *RepositoryRestorer) GetMilestones() ([]*base.Milestone, error) {
- var milestones = make([]*base.Milestone, 0, 10)
+ milestones := make([]*base.Milestone, 0, 10)
p := filepath.Join(r.baseDir, "milestone.yml")
_, err := os.Stat(p)
if err != nil {
@@ -133,7 +133,7 @@ func (r *RepositoryRestorer) GetMilestones() ([]*base.Milestone, error) {
// GetReleases returns releases
func (r *RepositoryRestorer) GetReleases() ([]*base.Release, error) {
- var releases = make([]*base.Release, 0, 10)
+ releases := make([]*base.Release, 0, 10)
p := filepath.Join(r.baseDir, "release.yml")
_, err := os.Stat(p)
if err != nil {
@@ -164,7 +164,7 @@ func (r *RepositoryRestorer) GetReleases() ([]*base.Release, error) {
// GetLabels returns labels
func (r *RepositoryRestorer) GetLabels() ([]*base.Label, error) {
- var labels = make([]*base.Label, 0, 10)
+ labels := make([]*base.Label, 0, 10)
p := filepath.Join(r.baseDir, "label.yml")
_, err := os.Stat(p)
if err != nil {
@@ -188,7 +188,7 @@ func (r *RepositoryRestorer) GetLabels() ([]*base.Label, error) {
// GetIssues returns issues according start and limit
func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool, error) {
- var issues = make([]*base.Issue, 0, 10)
+ issues := make([]*base.Issue, 0, 10)
p := filepath.Join(r.baseDir, "issue.yml")
_, err := os.Stat(p)
if err != nil {
@@ -215,7 +215,7 @@ func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool,
// GetComments returns comments according issueNumber
func (r *RepositoryRestorer) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
- var comments = make([]*base.Comment, 0, 10)
+ comments := make([]*base.Comment, 0, 10)
p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", opts.Context.ForeignID()))
_, err := os.Stat(p)
if err != nil {
@@ -239,7 +239,7 @@ func (r *RepositoryRestorer) GetComments(opts base.GetCommentOptions) ([]*base.C
// GetPullRequests returns pull requests according page and perPage
func (r *RepositoryRestorer) GetPullRequests(page, perPage int) ([]*base.PullRequest, bool, error) {
- var pulls = make([]*base.PullRequest, 0, 10)
+ pulls := make([]*base.PullRequest, 0, 10)
p := filepath.Join(r.baseDir, "pull_request.yml")
_, err := os.Stat(p)
if err != nil {
@@ -267,7 +267,7 @@ func (r *RepositoryRestorer) GetPullRequests(page, perPage int) ([]*base.PullReq
// GetReviews returns pull requests review
func (r *RepositoryRestorer) GetReviews(context base.IssueContext) ([]*base.Review, error) {
- var reviews = make([]*base.Review, 0, 10)
+ reviews := make([]*base.Review, 0, 10)
p := filepath.Join(r.reviewDir(), fmt.Sprintf("%d.yml", context.ForeignID()))
_, err := os.Stat(p)
if err != nil {
diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go
index b9333c77f3..36cd71aa6e 100644
--- a/services/mirror/mirror_pull.go
+++ b/services/mirror/mirror_pull.go
@@ -150,8 +150,8 @@ func pruneBrokenReferences(ctx context.Context,
timeout time.Duration,
stdoutBuilder, stderrBuilder *strings.Builder,
sanitizer *strings.Replacer,
- isWiki bool) error {
-
+ isWiki bool,
+) error {
wiki := ""
if isWiki {
wiki = "Wiki "
diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go
index d605f8e301..be8df0c9b1 100644
--- a/services/pull/commit_status.go
+++ b/services/pull/commit_status.go
@@ -26,7 +26,7 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*models.CommitStatus, re
return structs.CommitStatusSuccess
}
- var returnedStatus = structs.CommitStatusSuccess
+ returnedStatus := structs.CommitStatusSuccess
for _, ctx := range requiredContexts {
var targetStatus structs.CommitStatusState
for _, commitStatus := range commitStatuses {
diff --git a/services/pull/merge.go b/services/pull/merge.go
index 2a67507a87..d2196b22d5 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -165,13 +165,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
}
infoPath := filepath.Join(tmpBasePath, ".git", "info")
- if err := os.MkdirAll(infoPath, 0700); err != nil {
+ if err := os.MkdirAll(infoPath, 0o700); err != nil {
log.Error("Unable to create .git/info in %s: %v", tmpBasePath, err)
return "", fmt.Errorf("Unable to create .git/info in tmpBasePath: %v", err)
}
sparseCheckoutListPath := filepath.Join(infoPath, "sparse-checkout")
- if err := os.WriteFile(sparseCheckoutListPath, []byte(sparseCheckoutList), 0600); err != nil {
+ if err := os.WriteFile(sparseCheckoutListPath, []byte(sparseCheckoutList), 0o600); err != nil {
log.Error("Unable to write .git/info/sparse-checkout file in %s: %v", tmpBasePath, err)
return "", fmt.Errorf("Unable to write .git/info/sparse-checkout file in tmpBasePath: %v", err)
}
diff --git a/services/pull/review.go b/services/pull/review.go
index 0db3168895..25eef78d97 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -24,7 +24,6 @@ import (
// CreateCodeComment creates a comment on the code line
func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *models.Issue, line int64, content, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*models.Comment, error) {
-
var (
existsReview bool
err error
diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go
index 140403172c..fa3bb2f4bb 100644
--- a/services/pull/temp_repo.go
+++ b/services/pull/temp_repo.go
@@ -70,7 +70,7 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
// Add head repo remote.
addCacheRepo := func(staging, cache string) error {
p := filepath.Join(staging, ".git", "objects", "info", "alternates")
- f, err := os.OpenFile(p, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
+ f, err := os.OpenFile(p, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)
if err != nil {
log.Error("Could not create .git/objects/info/alternates file in %s: %v", staging, err)
return err
diff --git a/services/pull/update.go b/services/pull/update.go
index 09cf1ce52e..f32dfad2ca 100644
--- a/services/pull/update.go
+++ b/services/pull/update.go
@@ -26,7 +26,7 @@ func Update(ctx context.Context, pull *models.PullRequest, doer *user_model.User
pr = pull
style = repo_model.MergeStyleRebaseUpdate
} else {
- //use merge functions but switch repo's and branch's
+ // use merge functions but switch repo's and branch's
pr = &models.PullRequest{
HeadRepoID: pull.BaseRepoID,
BaseRepoID: pull.HeadRepoID,
diff --git a/services/release/release.go b/services/release/release.go
index aebf79edc3..8e6f9e1734 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -210,7 +210,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.R
return fmt.Errorf("AddReleaseAttachments: %v", err)
}
- var deletedUUIDsMap = make(map[string]bool)
+ deletedUUIDsMap := make(map[string]bool)
if len(delAttachmentUUIDs) > 0 {
// Check attachments
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, delAttachmentUUIDs)
@@ -230,7 +230,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.R
}
if len(editAttachments) > 0 {
- var updateAttachmentsList = make([]string, 0, len(editAttachments))
+ updateAttachmentsList := make([]string, 0, len(editAttachments))
for k := range editAttachments {
updateAttachmentsList = append(updateAttachmentsList, k)
}
diff --git a/services/release/release_test.go b/services/release/release_test.go
index 4dc45c06e9..413a56116b 100644
--- a/services/release/release_test.go
+++ b/services/release/release_test.go
@@ -112,7 +112,7 @@ func TestRelease_Create(t *testing.T) {
}, strings.NewReader("testtest"))
assert.NoError(t, err)
- var release = models.Release{
+ release := models.Release{
RepoID: repo.ID,
Repo: repo,
PublisherID: user.ID,
diff --git a/services/repository/adopt.go b/services/repository/adopt.go
index adc5942a3c..46337254b2 100644
--- a/services/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -252,7 +252,8 @@ func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unad
ListOptions: db.ListOptions{
Page: 1,
PageSize: len(repoNamesToCheck),
- }, LowerNames: repoNamesToCheck})
+ }, LowerNames: repoNamesToCheck,
+ })
if err != nil {
return err
}
diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go
index 2053151106..685bfe9bc4 100644
--- a/services/repository/adopt_test.go
+++ b/services/repository/adopt_test.go
@@ -69,7 +69,7 @@ func TestListUnadoptedRepositories_ListOptions(t *testing.T) {
username := "user2"
unadoptedList := []string{path.Join(username, "unadopted1"), path.Join(username, "unadopted2")}
for _, unadopted := range unadoptedList {
- _ = os.Mkdir(path.Join(setting.RepoRootPath, unadopted+".git"), 0755)
+ _ = os.Mkdir(path.Join(setting.RepoRootPath, unadopted+".git"), 0o755)
}
opts := db.ListOptions{Page: 1, PageSize: 1}
diff --git a/services/repository/archiver/archiver.go b/services/repository/archiver/archiver.go
index 93ec8bcca2..f982e2ef7b 100644
--- a/services/repository/archiver/archiver.go
+++ b/services/repository/archiver/archiver.go
@@ -172,7 +172,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
w.Close()
rd.Close()
}()
- var done = make(chan error)
+ done := make(chan error)
repo, err := repo_model.GetRepositoryByID(archiver.RepoID)
if err != nil {
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)
diff --git a/services/repository/archiver/archiver_test.go b/services/repository/archiver/archiver_test.go
index 2c0b46d3d4..b7fb6cb0ca 100644
--- a/services/repository/archiver/archiver_test.go
+++ b/services/repository/archiver/archiver_test.go
@@ -128,6 +128,6 @@ func TestArchive_Basic(t *testing.T) {
}
func TestErrUnknownArchiveFormat(t *testing.T) {
- var err = ErrUnknownArchiveFormat{RequestFormat: "master"}
+ err := ErrUnknownArchiveFormat{RequestFormat: "master"}
assert.True(t, errors.Is(err, ErrUnknownArchiveFormat{}))
}
diff --git a/services/repository/push.go b/services/repository/push.go
index 62e2104432..518ad04157 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -312,7 +312,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
sig = commit.Committer
}
var author *user_model.User
- var createdAt = time.Unix(1, 0)
+ createdAt := time.Unix(1, 0)
if sig != nil {
var ok bool
diff --git a/services/task/task.go b/services/task/task.go
index 4994be87dd..376fe1dce1 100644
--- a/services/task/task.go
+++ b/services/task/task.go
@@ -92,7 +92,7 @@ func CreateMigrateTask(doer, u *user_model.User, opts base.MigrateOptions) (*mod
return nil, err
}
- var task = &models.Task{
+ task := &models.Task{
DoerID: doer.ID,
OwnerID: u.ID,
Type: structs.TaskTypeMigrateRepo,
diff --git a/services/webhook/deliver.go b/services/webhook/deliver.go
index 36169baad4..88b709cb41 100644
--- a/services/webhook/deliver.go
+++ b/services/webhook/deliver.go
@@ -64,7 +64,7 @@ func Deliver(t *webhook_model.HookTask) error {
req.Header.Set("Content-Type", "application/json")
case webhook_model.ContentTypeForm:
- var forms = url.Values{
+ forms := url.Values{
"payload": []string{t.PayloadContent},
}
@@ -255,7 +255,6 @@ func DeliverHooks(ctx context.Context) {
}
}
}
-
}
var (
diff --git a/services/webhook/deliver_test.go b/services/webhook/deliver_test.go
index 551c957c8d..8d1d587c38 100644
--- a/services/webhook/deliver_test.go
+++ b/services/webhook/deliver_test.go
@@ -19,7 +19,7 @@ func TestWebhookProxy(t *testing.T) {
setting.Webhook.ProxyURLFixed, _ = url.Parse(setting.Webhook.ProxyURL)
setting.Webhook.ProxyHosts = []string{"*.discordapp.com", "discordapp.com"}
- var kases = map[string]string{
+ kases := map[string]string{
"https://discordapp.com/api/webhooks/xxxxxxxxx/xxxxxxxxxxxxxxxxxxx": "http://localhost:8080",
"http://s.discordapp.com/assets/xxxxxx": "http://localhost:8080",
"http://github.com/a/b": "",
diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go
index a949b073a5..642cf6f2fd 100644
--- a/services/webhook/dingtalk.go
+++ b/services/webhook/dingtalk.go
@@ -23,9 +23,7 @@ type (
DingtalkPayload dingtalk.Payload
)
-var (
- _ PayloadConvertor = &DingtalkPayload{}
-)
+var _ PayloadConvertor = &DingtalkPayload{}
// JSONPayload Marshals the DingtalkPayload to json
func (d *DingtalkPayload) JSONPayload() ([]byte, error) {
@@ -135,7 +133,6 @@ func (d *DingtalkPayload) Review(p *api.PullRequestPayload, event webhook_model.
title = fmt.Sprintf("[%s] Pull request review %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
text = p.Review.Content
-
}
return createDingtalkPayload(title, title+"\r\n\r\n"+text, "view pull request", p.PullRequest.HTMLURL), nil
diff --git a/services/webhook/discord.go b/services/webhook/discord.go
index 587d2098eb..ae5460b9a7 100644
--- a/services/webhook/discord.go
+++ b/services/webhook/discord.go
@@ -106,9 +106,7 @@ func (d *DiscordPayload) JSONPayload() ([]byte, error) {
return data, nil
}
-var (
- _ PayloadConvertor = &DiscordPayload{}
-)
+var _ PayloadConvertor = &DiscordPayload{}
// Create implements PayloadConvertor Create method
func (d *DiscordPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go
index 18858c0994..5b20c7dda7 100644
--- a/services/webhook/feishu.go
+++ b/services/webhook/feishu.go
@@ -44,9 +44,7 @@ func (f *FeishuPayload) JSONPayload() ([]byte, error) {
return data, nil
}
-var (
- _ PayloadConvertor = &FeishuPayload{}
-)
+var _ PayloadConvertor = &FeishuPayload{}
// Create implements PayloadConvertor Create method
func (f *FeishuPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
@@ -80,7 +78,7 @@ func (f *FeishuPayload) Push(p *api.PushPayload) (api.Payloader, error) {
commitDesc string
)
- var text = fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)
+ text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc)
// for each commit, generate attachment text
for i, commit := range p.Commits {
var authorName string
diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go
index 72392debe9..a42ab2a93e 100644
--- a/services/webhook/matrix.go
+++ b/services/webhook/matrix.go
@@ -53,9 +53,7 @@ type MatrixPayloadUnsafe struct {
AccessToken string `json:"access_token"`
}
-var (
- _ PayloadConvertor = &MatrixPayloadUnsafe{}
-)
+var _ PayloadConvertor = &MatrixPayloadUnsafe{}
// safePayload "converts" a unsafe payload to a safe payload
func (m *MatrixPayloadUnsafe) safePayload() *MatrixPayloadSafe {
diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go
index ae5af8d9b6..59e2e93493 100644
--- a/services/webhook/msteams.go
+++ b/services/webhook/msteams.go
@@ -65,9 +65,7 @@ func (m *MSTeamsPayload) JSONPayload() ([]byte, error) {
return data, nil
}
-var (
- _ PayloadConvertor = &MSTeamsPayload{}
-)
+var _ PayloadConvertor = &MSTeamsPayload{}
// Create implements PayloadConvertor Create method
func (m *MSTeamsPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
diff --git a/services/webhook/slack.go b/services/webhook/slack.go
index a67fe6a762..11e1d3c081 100644
--- a/services/webhook/slack.go
+++ b/services/webhook/slack.go
@@ -96,9 +96,7 @@ func SlackLinkToRef(repoURL, ref string) string {
return SlackLinkFormatter(url, refName)
}
-var (
- _ PayloadConvertor = &SlackPayload{}
-)
+var _ PayloadConvertor = &SlackPayload{}
// Create implements PayloadConvertor Create method
func (s *SlackPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go
index 93c464fe73..64211493ec 100644
--- a/services/webhook/telegram.go
+++ b/services/webhook/telegram.go
@@ -40,9 +40,7 @@ func GetTelegramHook(w *webhook_model.Webhook) *TelegramMeta {
return s
}
-var (
- _ PayloadConvertor = &TelegramPayload{}
-)
+var _ PayloadConvertor = &TelegramPayload{}
// JSONPayload Marshals the TelegramPayload to json
func (t *TelegramPayload) JSONPayload() ([]byte, error) {
diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go
index f284a20c30..bb7a9692d1 100644
--- a/services/webhook/webhook.go
+++ b/services/webhook/webhook.go
@@ -25,42 +25,40 @@ type webhook struct {
payloadCreator func(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error)
}
-var (
- webhooks = map[webhook_model.HookType]*webhook{
- webhook_model.SLACK: {
- name: webhook_model.SLACK,
- payloadCreator: GetSlackPayload,
- },
- webhook_model.DISCORD: {
- name: webhook_model.DISCORD,
- payloadCreator: GetDiscordPayload,
- },
- webhook_model.DINGTALK: {
- name: webhook_model.DINGTALK,
- payloadCreator: GetDingtalkPayload,
- },
- webhook_model.TELEGRAM: {
- name: webhook_model.TELEGRAM,
- payloadCreator: GetTelegramPayload,
- },
- webhook_model.MSTEAMS: {
- name: webhook_model.MSTEAMS,
- payloadCreator: GetMSTeamsPayload,
- },
- webhook_model.FEISHU: {
- name: webhook_model.FEISHU,
- payloadCreator: GetFeishuPayload,
- },
- webhook_model.MATRIX: {
- name: webhook_model.MATRIX,
- payloadCreator: GetMatrixPayload,
- },
- webhook_model.WECHATWORK: {
- name: webhook_model.WECHATWORK,
- payloadCreator: GetWechatworkPayload,
- },
- }
-)
+var webhooks = map[webhook_model.HookType]*webhook{
+ webhook_model.SLACK: {
+ name: webhook_model.SLACK,
+ payloadCreator: GetSlackPayload,
+ },
+ webhook_model.DISCORD: {
+ name: webhook_model.DISCORD,
+ payloadCreator: GetDiscordPayload,
+ },
+ webhook_model.DINGTALK: {
+ name: webhook_model.DINGTALK,
+ payloadCreator: GetDingtalkPayload,
+ },
+ webhook_model.TELEGRAM: {
+ name: webhook_model.TELEGRAM,
+ payloadCreator: GetTelegramPayload,
+ },
+ webhook_model.MSTEAMS: {
+ name: webhook_model.MSTEAMS,
+ payloadCreator: GetMSTeamsPayload,
+ },
+ webhook_model.FEISHU: {
+ name: webhook_model.FEISHU,
+ payloadCreator: GetFeishuPayload,
+ },
+ webhook_model.MATRIX: {
+ name: webhook_model.MATRIX,
+ payloadCreator: GetMatrixPayload,
+ },
+ webhook_model.WECHATWORK: {
+ name: webhook_model.WECHATWORK,
+ payloadCreator: GetWechatworkPayload,
+ },
+}
// RegisterWebhook registers a webhook
func RegisterWebhook(name string, webhook *webhook) {
diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go
index e8ab07aaa0..de8b777066 100644
--- a/services/webhook/wechatwork.go
+++ b/services/webhook/wechatwork.go
@@ -52,9 +52,7 @@ func newWechatworkMarkdownPayload(title string) *WechatworkPayload {
}
}
-var (
- _ PayloadConvertor = &WechatworkPayload{}
-)
+var _ PayloadConvertor = &WechatworkPayload{}
// Create implements PayloadConvertor Create method
func (f *WechatworkPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
@@ -72,12 +70,10 @@ func (f *WechatworkPayload) Delete(p *api.DeletePayload) (api.Payloader, error)
title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName)
return newWechatworkMarkdownPayload(title), nil
-
}
// Fork implements PayloadConvertor Fork method
func (f *WechatworkPayload) Fork(p *api.ForkPayload) (api.Payloader, error) {
-
title := fmt.Sprintf("%s is forked to %s", p.Forkee.FullName, p.Repo.FullName)
return newWechatworkMarkdownPayload(title), nil
@@ -110,7 +106,6 @@ func (f *WechatworkPayload) Push(p *api.PushPayload) (api.Payloader, error) {
}
}
return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil
-
}
// Issue implements PayloadConvertor Issue method
@@ -120,7 +115,6 @@ func (f *WechatworkPayload) Issue(p *api.IssuePayload) (api.Payloader, error) {
content += fmt.Sprintf(" ><font color=\"info\">%s</font>\n >%s \n ><font color=\"warning\"> %s</font> \n [%s](%s)", text, attachmentText, issueTitle, p.Issue.HTMLURL, p.Issue.HTMLURL)
return newWechatworkMarkdownPayload(content), nil
-
}
// IssueComment implements PayloadConvertor IssueComment method
@@ -130,7 +124,6 @@ func (f *WechatworkPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloa
content += fmt.Sprintf(" ><font color=\"info\">%s</font>\n >%s \n ><font color=\"warning\">%s</font> \n [%s](%s)", text, p.Comment.Body, issueTitle, p.Comment.HTMLURL, p.Comment.HTMLURL)
return newWechatworkMarkdownPayload(content), nil
-
}
// PullRequest implements PayloadConvertor PullRequest method
@@ -140,7 +133,6 @@ func (f *WechatworkPayload) PullRequest(p *api.PullRequestPayload) (api.Payloade
text, issueTitle, attachmentText)
return newWechatworkMarkdownPayload(pr), nil
-
}
// Review implements PayloadConvertor Review method
@@ -157,7 +149,6 @@ func (f *WechatworkPayload) Review(p *api.PullRequestPayload, event webhook_mode
}
return newWechatworkMarkdownPayload("# " + title + "\r\n\r\n >" + text), nil
-
}
// Repository implements PayloadConvertor Repository method