Skip to content

Commit f93c66c

Browse files
committed
replace "com.ToStr" with "fmt.Sprint" where its easy to do
1 parent a843466 commit f93c66c

File tree

9 files changed

+60
-71
lines changed

9 files changed

+60
-71
lines changed

modules/base/tool.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"code.gitea.io/gitea/modules/setting"
2727

2828
"github.com/dustin/go-humanize"
29-
"github.com/unknwon/com"
3029
)
3130

3231
// EncodeMD5 encodes string to md5 hex value.
@@ -131,7 +130,7 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
131130

132131
// create sha1 encode string
133132
sh := sha1.New()
134-
_, _ = sh.Write([]byte(data + setting.SecretKey + startStr + endStr + com.ToStr(minutes)))
133+
_, _ = sh.Write([]byte(data + setting.SecretKey + startStr + endStr + fmt.Sprint(minutes)))
135134
encoded := hex.EncodeToString(sh.Sum(nil))
136135

137136
code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)

routers/admin/auths.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"code.gitea.io/gitea/modules/setting"
2121
"code.gitea.io/gitea/modules/util"
2222

23-
"github.com/unknwon/com"
2423
"xorm.io/xorm/convert"
2524
)
2625

@@ -373,7 +372,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
373372
log.Trace("Authentication changed by admin(%s): %d", ctx.User.Name, source.ID)
374373

375374
ctx.Flash.Success(ctx.Tr("admin.auths.update_success"))
376-
ctx.Redirect(setting.AppSubURL + "/admin/auths/" + com.ToStr(form.ID))
375+
ctx.Redirect(setting.AppSubURL + "/admin/auths/" + fmt.Sprint(form.ID))
377376
}
378377

379378
// DeleteAuthSource response for deleting an auth source

routers/admin/users.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package admin
77

88
import (
9+
"fmt"
910
"strconv"
1011
"strings"
1112

@@ -18,8 +19,6 @@ import (
1819
"code.gitea.io/gitea/modules/setting"
1920
"code.gitea.io/gitea/routers"
2021
"code.gitea.io/gitea/services/mailer"
21-
22-
"github.com/unknwon/com"
2322
)
2423

2524
const (
@@ -156,7 +155,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
156155
}
157156

158157
ctx.Flash.Success(ctx.Tr("admin.users.new_success", u.Name))
159-
ctx.Redirect(setting.AppSubURL + "/admin/users/" + com.ToStr(u.ID))
158+
ctx.Redirect(setting.AppSubURL + "/admin/users/" + fmt.Sprint(u.ID))
160159
}
161160

162161
func prepareUserInfo(ctx *context.Context) *models.User {

routers/install.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package routers
66

77
import (
8+
"fmt"
89
"net/http"
910
"os"
1011
"os/exec"
@@ -22,7 +23,6 @@ import (
2223
"code.gitea.io/gitea/modules/user"
2324
"code.gitea.io/gitea/modules/util"
2425

25-
"github.com/unknwon/com"
2626
"gopkg.in/ini.v1"
2727
)
2828

@@ -294,7 +294,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
294294
cfg.Section("server").Key("DISABLE_SSH").SetValue("true")
295295
} else {
296296
cfg.Section("server").Key("DISABLE_SSH").SetValue("false")
297-
cfg.Section("server").Key("SSH_PORT").SetValue(com.ToStr(form.SSHPort))
297+
cfg.Section("server").Key("SSH_PORT").SetValue(fmt.Sprint(form.SSHPort))
298298
}
299299

300300
if form.LFSRootPath != "" {
@@ -319,22 +319,22 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
319319
} else {
320320
cfg.Section("mailer").Key("ENABLED").SetValue("false")
321321
}
322-
cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").SetValue(com.ToStr(form.RegisterConfirm))
323-
cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").SetValue(com.ToStr(form.MailNotify))
324-
325-
cfg.Section("server").Key("OFFLINE_MODE").SetValue(com.ToStr(form.OfflineMode))
326-
cfg.Section("picture").Key("DISABLE_GRAVATAR").SetValue(com.ToStr(form.DisableGravatar))
327-
cfg.Section("picture").Key("ENABLE_FEDERATED_AVATAR").SetValue(com.ToStr(form.EnableFederatedAvatar))
328-
cfg.Section("openid").Key("ENABLE_OPENID_SIGNIN").SetValue(com.ToStr(form.EnableOpenIDSignIn))
329-
cfg.Section("openid").Key("ENABLE_OPENID_SIGNUP").SetValue(com.ToStr(form.EnableOpenIDSignUp))
330-
cfg.Section("service").Key("DISABLE_REGISTRATION").SetValue(com.ToStr(form.DisableRegistration))
331-
cfg.Section("service").Key("ALLOW_ONLY_EXTERNAL_REGISTRATION").SetValue(com.ToStr(form.AllowOnlyExternalRegistration))
332-
cfg.Section("service").Key("ENABLE_CAPTCHA").SetValue(com.ToStr(form.EnableCaptcha))
333-
cfg.Section("service").Key("REQUIRE_SIGNIN_VIEW").SetValue(com.ToStr(form.RequireSignInView))
334-
cfg.Section("service").Key("DEFAULT_KEEP_EMAIL_PRIVATE").SetValue(com.ToStr(form.DefaultKeepEmailPrivate))
335-
cfg.Section("service").Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").SetValue(com.ToStr(form.DefaultAllowCreateOrganization))
336-
cfg.Section("service").Key("DEFAULT_ENABLE_TIMETRACKING").SetValue(com.ToStr(form.DefaultEnableTimetracking))
337-
cfg.Section("service").Key("NO_REPLY_ADDRESS").SetValue(com.ToStr(form.NoReplyAddress))
322+
cfg.Section("service").Key("REGISTER_EMAIL_CONFIRM").SetValue(fmt.Sprint(form.RegisterConfirm))
323+
cfg.Section("service").Key("ENABLE_NOTIFY_MAIL").SetValue(fmt.Sprint(form.MailNotify))
324+
325+
cfg.Section("server").Key("OFFLINE_MODE").SetValue(fmt.Sprint(form.OfflineMode))
326+
cfg.Section("picture").Key("DISABLE_GRAVATAR").SetValue(fmt.Sprint(form.DisableGravatar))
327+
cfg.Section("picture").Key("ENABLE_FEDERATED_AVATAR").SetValue(fmt.Sprint(form.EnableFederatedAvatar))
328+
cfg.Section("openid").Key("ENABLE_OPENID_SIGNIN").SetValue(fmt.Sprint(form.EnableOpenIDSignIn))
329+
cfg.Section("openid").Key("ENABLE_OPENID_SIGNUP").SetValue(fmt.Sprint(form.EnableOpenIDSignUp))
330+
cfg.Section("service").Key("DISABLE_REGISTRATION").SetValue(fmt.Sprint(form.DisableRegistration))
331+
cfg.Section("service").Key("ALLOW_ONLY_EXTERNAL_REGISTRATION").SetValue(fmt.Sprint(form.AllowOnlyExternalRegistration))
332+
cfg.Section("service").Key("ENABLE_CAPTCHA").SetValue(fmt.Sprint(form.EnableCaptcha))
333+
cfg.Section("service").Key("REQUIRE_SIGNIN_VIEW").SetValue(fmt.Sprint(form.RequireSignInView))
334+
cfg.Section("service").Key("DEFAULT_KEEP_EMAIL_PRIVATE").SetValue(fmt.Sprint(form.DefaultKeepEmailPrivate))
335+
cfg.Section("service").Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").SetValue(fmt.Sprint(form.DefaultAllowCreateOrganization))
336+
cfg.Section("service").Key("DEFAULT_ENABLE_TIMETRACKING").SetValue(fmt.Sprint(form.DefaultEnableTimetracking))
337+
cfg.Section("service").Key("NO_REPLY_ADDRESS").SetValue(fmt.Sprint(form.NoReplyAddress))
338338

339339
cfg.Section("").Key("RUN_MODE").SetValue("prod")
340340

routers/repo/issue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
981981
}
982982

983983
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
984-
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
984+
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + fmt.Sprint(issue.Index))
985985
}
986986

987987
// commentTag returns the CommentTag for a comment in/with the given repo, poster and issue
@@ -1061,10 +1061,10 @@ func ViewIssue(ctx *context.Context) {
10611061

10621062
// Make sure type and URL matches.
10631063
if ctx.Params(":type") == "issues" && issue.IsPull {
1064-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
1064+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
10651065
return
10661066
} else if ctx.Params(":type") == "pulls" && !issue.IsPull {
1067-
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
1067+
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + fmt.Sprint(issue.Index))
10681068
return
10691069
}
10701070

@@ -1411,7 +1411,7 @@ func ViewIssue(ctx *context.Context) {
14111411
log.Error("IsProtectedBranch: %v", err)
14121412
} else if !protected {
14131413
canDelete = true
1414-
ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index) + "/cleanup"
1414+
ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index) + "/cleanup"
14151415
}
14161416
}
14171417
}

routers/repo/pull.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import (
3131
"code.gitea.io/gitea/services/gitdiff"
3232
pull_service "code.gitea.io/gitea/services/pull"
3333
repo_service "code.gitea.io/gitea/services/repository"
34-
35-
"github.com/unknwon/com"
3634
)
3735

3836
const (
@@ -732,7 +730,7 @@ func UpdatePullRequest(ctx *context.Context) {
732730
// ToDo: add check if maintainers are allowed to change branch ... (need migration & co)
733731
if !allowedUpdate {
734732
ctx.Flash.Error(ctx.Tr("repo.pulls.update_not_allowed"))
735-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
733+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
736734
return
737735
}
738736

@@ -752,18 +750,18 @@ func UpdatePullRequest(ctx *context.Context) {
752750
return
753751
}
754752
ctx.Flash.Error(flashError)
755-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
753+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
756754
return
757755
}
758756
ctx.Flash.Error(err.Error())
759-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
757+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
760758
return
761759
}
762760

763761
time.Sleep(1 * time.Second)
764762

765763
ctx.Flash.Success(ctx.Tr("repo.pulls.update_branch_success"))
766-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
764+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
767765
}
768766

769767
// MergePullRequest response for merging pull request
@@ -775,11 +773,11 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
775773
if issue.IsClosed {
776774
if issue.IsPull {
777775
ctx.Flash.Error(ctx.Tr("repo.pulls.is_closed"))
778-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
776+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
779777
return
780778
}
781779
ctx.Flash.Error(ctx.Tr("repo.issues.closed_title"))
782-
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
780+
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + fmt.Sprint(issue.Index))
783781
return
784782
}
785783

@@ -792,25 +790,25 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
792790
}
793791
if !allowedMerge {
794792
ctx.Flash.Error(ctx.Tr("repo.pulls.update_not_allowed"))
795-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
793+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
796794
return
797795
}
798796

799797
if !pr.CanAutoMerge() {
800798
ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_not_ready"))
801-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
799+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
802800
return
803801
}
804802

805803
if pr.HasMerged {
806804
ctx.Flash.Error(ctx.Tr("repo.pulls.has_merged"))
807-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
805+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
808806
return
809807
}
810808

811809
if pr.IsWorkInProgress() {
812810
ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_wip"))
813-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
811+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
814812
return
815813
}
816814

@@ -824,14 +822,14 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
824822
return
825823
} else if !isRepoAdmin {
826824
ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_not_ready"))
827-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
825+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
828826
return
829827
}
830828
}
831829

832830
if ctx.HasError() {
833831
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
834-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
832+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
835833
return
836834
}
837835

@@ -863,14 +861,14 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
863861

864862
if !noDeps {
865863
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
866-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
864+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
867865
return
868866
}
869867

870868
if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
871869
if models.IsErrInvalidMergeStyle(err) {
872870
ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
873-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
871+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
874872
return
875873
} else if models.IsErrMergeConflicts(err) {
876874
conflictError := err.(models.ErrMergeConflicts)
@@ -884,7 +882,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
884882
return
885883
}
886884
ctx.Flash.Error(flashError)
887-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
885+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
888886
return
889887
} else if models.IsErrRebaseConflicts(err) {
890888
conflictError := err.(models.ErrRebaseConflicts)
@@ -898,17 +896,17 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
898896
return
899897
}
900898
ctx.Flash.Error(flashError)
901-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
899+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
902900
return
903901
} else if models.IsErrMergeUnrelatedHistories(err) {
904902
log.Debug("MergeUnrelatedHistories error: %v", err)
905903
ctx.Flash.Error(ctx.Tr("repo.pulls.unrelated_histories"))
906-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
904+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
907905
return
908906
} else if git.IsErrPushOutOfDate(err) {
909907
log.Debug("MergePushOutOfDate error: %v", err)
910908
ctx.Flash.Error(ctx.Tr("repo.pulls.merge_out_of_date"))
911-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
909+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
912910
return
913911
} else if git.IsErrPushRejected(err) {
914912
log.Debug("MergePushRejected error: %v", err)
@@ -928,7 +926,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
928926
}
929927
ctx.Flash.Error(flashError)
930928
}
931-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
929+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
932930
return
933931
}
934932
ctx.ServerError("Merge", err)
@@ -941,7 +939,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
941939
}
942940

943941
log.Trace("Pull request merged: %d", pr.ID)
944-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
942+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pr.Index))
945943
}
946944

947945
func stopTimerIfAvailable(user *models.User, issue *models.Issue) error {
@@ -1052,15 +1050,15 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
10521050
}
10531051
ctx.Flash.Error(flashError)
10541052
}
1055-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
1053+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pullIssue.Index))
10561054
return
10571055
}
10581056
ctx.ServerError("NewPullRequest", err)
10591057
return
10601058
}
10611059

10621060
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
1063-
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
1061+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(pullIssue.Index))
10641062
}
10651063

10661064
// TriggerTask response for a trigger task request
@@ -1159,7 +1157,7 @@ func CleanUpPullRequest(ctx *context.Context) {
11591157

11601158
defer func() {
11611159
ctx.JSON(200, map[string]interface{}{
1162-
"redirect": pr.BaseRepo.Link() + "/pulls/" + com.ToStr(issue.Index),
1160+
"redirect": pr.BaseRepo.Link() + "/pulls/" + fmt.Sprint(issue.Index),
11631161
})
11641162
}()
11651163

services/pull/pull.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"code.gitea.io/gitea/modules/notification"
2222
"code.gitea.io/gitea/modules/setting"
2323
issue_service "code.gitea.io/gitea/services/issue"
24-
25-
"github.com/unknwon/com"
2624
)
2725

2826
// NewPullRequest creates new pull request with labels for repository.
@@ -326,7 +324,7 @@ func checkIfPRContentChanged(pr *models.PullRequest, oldCommitID, newCommitID st
326324
defer headGitRepo.Close()
327325

328326
// Add a temporary remote.
329-
tmpRemote := "checkIfPRContentChanged-" + com.ToStr(time.Now().UnixNano())
327+
tmpRemote := "checkIfPRContentChanged-" + fmt.Sprint(time.Now().UnixNano())
330328
if err = headGitRepo.AddRemote(tmpRemote, pr.BaseRepo.RepoPath(), true); err != nil {
331329
return false, fmt.Errorf("AddRemote: %s/%s-%s: %v", pr.HeadRepo.OwnerName, pr.HeadRepo.Name, tmpRemote, err)
332330
}

0 commit comments

Comments
 (0)