Skip to content

Commit 283c6df

Browse files
committed
remove github.com/unknwon/com from models
1 parent acd5e5a commit 283c6df

15 files changed

+179
-47
lines changed

models/action.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"code.gitea.io/gitea/modules/setting"
1919
"code.gitea.io/gitea/modules/timeutil"
2020

21-
"github.com/unknwon/com"
2221
"xorm.io/builder"
2322
)
2423

@@ -266,7 +265,7 @@ func (a *Action) GetIssueInfos() []string {
266265
// GetIssueTitle returns the title of first issue associated
267266
// with the action.
268267
func (a *Action) GetIssueTitle() string {
269-
index := com.StrTo(a.GetIssueInfos()[0]).MustInt64()
268+
index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
270269
issue, err := GetIssueByIndex(a.RepoID, index)
271270
if err != nil {
272271
log.Error("GetIssueByIndex: %v", err)
@@ -278,7 +277,7 @@ func (a *Action) GetIssueTitle() string {
278277
// GetIssueContent returns the content of first issue associated with
279278
// this action.
280279
func (a *Action) GetIssueContent() string {
281-
index := com.StrTo(a.GetIssueInfos()[0]).MustInt64()
280+
index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
282281
issue, err := GetIssueByIndex(a.RepoID, index)
283282
if err != nil {
284283
log.Error("GetIssueByIndex: %v", err)

models/admin.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"code.gitea.io/gitea/modules/storage"
1313
"code.gitea.io/gitea/modules/timeutil"
1414
"code.gitea.io/gitea/modules/util"
15-
16-
"github.com/unknwon/com"
1715
)
1816

1917
//NoticeType describes the notice type
@@ -36,7 +34,7 @@ type Notice struct {
3634

3735
// TrStr returns a translation format string.
3836
func (n *Notice) TrStr() string {
39-
return "admin.notices.type_" + com.ToStr(n.Type)
37+
return fmt.Sprintf("admin.notices.type_%d", n.Type)
4038
}
4139

4240
// CreateNotice creates new system notice.

models/branches.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"code.gitea.io/gitea/modules/util"
1717

1818
"github.com/gobwas/glob"
19-
"github.com/unknwon/com"
2019
)
2120

2221
// ProtectedBranch struct
@@ -483,7 +482,7 @@ func updateTeamWhitelist(repo *Repository, currentWhitelist, newWhitelist []int6
483482

484483
whitelist = make([]int64, 0, len(teams))
485484
for i := range teams {
486-
if com.IsSliceContainsInt64(newWhitelist, teams[i].ID) {
485+
if util.IsInt64InSlice(teams[i].ID, newWhitelist) {
487486
whitelist = append(whitelist, teams[i].ID)
488487
}
489488
}

models/issue.go

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

23-
"github.com/unknwon/com"
2423
"xorm.io/builder"
2524
"xorm.io/xorm"
2625
)
@@ -386,7 +385,7 @@ func (issue *Issue) State() api.StateType {
386385

387386
// HashTag returns unique hash tag for issue.
388387
func (issue *Issue) HashTag() string {
389-
return "issue-" + com.ToStr(issue.ID)
388+
return fmt.Sprintf("issue-%d", issue.ID)
390389
}
391390

392391
// IsPoster returns true if given user by ID is the poster.
@@ -1374,7 +1373,8 @@ func parseCountResult(results []map[string][]byte) int64 {
13741373
return 0
13751374
}
13761375
for _, result := range results[0] {
1377-
return com.StrTo(string(result)).MustInt64()
1376+
c, _ := strconv.ParseInt(string(result), 10, 64)
1377+
return c
13781378
}
13791379
return 0
13801380
}

models/issue_comment.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"code.gitea.io/gitea/modules/structs"
2323
"code.gitea.io/gitea/modules/timeutil"
2424

25-
"github.com/unknwon/com"
2625
"xorm.io/builder"
2726
"xorm.io/xorm"
2827
)
@@ -367,7 +366,7 @@ func (c *Comment) HashTag() string {
367366

368367
// EventTag returns unique event hash tag for comment.
369368
func (c *Comment) EventTag() string {
370-
return "event-" + com.ToStr(c.ID)
369+
return fmt.Sprintf("event-%d", c.ID)
371370
}
372371

373372
// LoadLabel if comment.Type is CommentTypeLabel, then load Label

models/issue_xref.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"code.gitea.io/gitea/modules/log"
1111
"code.gitea.io/gitea/modules/references"
1212

13-
"github.com/unknwon/com"
1413
"xorm.io/xorm"
1514
)
1615

@@ -324,7 +323,7 @@ func (comment *Comment) RefIssueIdent() string {
324323
return ""
325324
}
326325
// FIXME: check this name for cross-repository references (#7901 if it gets merged)
327-
return "#" + com.ToStr(comment.RefIssue.Index)
326+
return fmt.Sprintf("#%d", comment.RefIssue.Index)
328327
}
329328

330329
// __________ .__ .__ __________ __

models/login_source.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"net/smtp"
1414
"net/textproto"
15+
"strconv"
1516
"strings"
1617

1718
"code.gitea.io/gitea/modules/auth/ldap"
@@ -20,8 +21,8 @@ import (
2021
"code.gitea.io/gitea/modules/log"
2122
"code.gitea.io/gitea/modules/setting"
2223
"code.gitea.io/gitea/modules/timeutil"
24+
"code.gitea.io/gitea/modules/util"
2325

24-
"github.com/unknwon/com"
2526
"xorm.io/xorm"
2627
"xorm.io/xorm/convert"
2728
)
@@ -180,7 +181,9 @@ func Cell2Int64(val xorm.Cell) int64 {
180181
switch (*val).(type) {
181182
case []uint8:
182183
log.Trace("Cell2Int64 ([]uint8): %v", *val)
183-
return com.StrTo(string((*val).([]uint8))).MustInt64()
184+
185+
v, _ := strconv.ParseInt(string((*val).([]uint8)), 10, 64)
186+
return v
184187
}
185188
return (*val).(int64)
186189
}
@@ -200,7 +203,7 @@ func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) {
200203
case LoginSSPI:
201204
source.Cfg = new(SSPIConfig)
202205
default:
203-
panic("unrecognized login source type: " + com.ToStr(*val))
206+
panic(fmt.Sprintf("unrecognized login source type: %v", *val))
204207
}
205208
}
206209
}
@@ -610,7 +613,7 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
610613
idx := strings.Index(login, "@")
611614
if idx == -1 {
612615
return nil, ErrUserNotExist{0, login, 0}
613-
} else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), login[idx+1:]) {
616+
} else if !util.IsStringInSlice(login[idx+1:], strings.Split(cfg.AllowedDomains, ","), true) {
614617
return nil, ErrUserNotExist{0, login, 0}
615618
}
616619
}

models/oauth2_application.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"code.gitea.io/gitea/modules/secret"
1515
"code.gitea.io/gitea/modules/setting"
1616
"code.gitea.io/gitea/modules/timeutil"
17+
"code.gitea.io/gitea/modules/util"
1718

1819
"github.com/dgrijalva/jwt-go"
1920
uuid "github.com/google/uuid"
20-
"github.com/unknwon/com"
2121
"golang.org/x/crypto/bcrypt"
2222
"xorm.io/xorm"
2323
)
@@ -62,7 +62,7 @@ func (app *OAuth2Application) LoadUser() (err error) {
6262

6363
// ContainsRedirectURI checks if redirectURI is allowed for app
6464
func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
65-
return com.IsSliceContainsStr(app.RedirectURIs, redirectURI)
65+
return util.IsStringInSlice(redirectURI, app.RedirectURIs, true)
6666
}
6767

6868
// GenerateClientSecret will generate the client secret and returns the plaintext and saves the hash at the database

models/repo.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"code.gitea.io/gitea/modules/timeutil"
3535
"code.gitea.io/gitea/modules/util"
3636

37-
"github.com/unknwon/com"
3837
"xorm.io/builder"
3938
)
4039

@@ -85,7 +84,7 @@ func loadRepoConfig() {
8584
}
8685

8786
for _, f := range customFiles {
88-
if !com.IsSliceContainsStr(files, f) {
87+
if !util.IsStringInSlice(f, files, true) {
8988
files = append(files, f)
9089
}
9190
}
@@ -115,12 +114,12 @@ func loadRepoConfig() {
115114
// Filter out invalid names and promote preferred licenses.
116115
sortedLicenses := make([]string, 0, len(Licenses))
117116
for _, name := range setting.Repository.PreferredLicenses {
118-
if com.IsSliceContainsStr(Licenses, name) {
117+
if util.IsStringInSlice(name, Licenses, true) {
119118
sortedLicenses = append(sortedLicenses, name)
120119
}
121120
}
122121
for _, name := range Licenses {
123-
if !com.IsSliceContainsStr(setting.Repository.PreferredLicenses, name) {
122+
if !util.IsStringInSlice(name, setting.Repository.PreferredLicenses, true) {
124123
sortedLicenses = append(sortedLicenses, name)
125124
}
126125
}
@@ -1933,7 +1932,7 @@ func repoStatsCheck(ctx context.Context, checker *repoChecker) {
19331932
return
19341933
}
19351934
for _, result := range results {
1936-
id := com.StrTo(result["id"]).MustInt64()
1935+
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
19371936
select {
19381937
case <-ctx.Done():
19391938
log.Warn("CheckRepoStats: Cancelled before checking %s for Repo[%d]", checker.desc, id)
@@ -2001,7 +2000,7 @@ func CheckRepoStats(ctx context.Context) error {
20012000
log.Error("Select %s: %v", desc, err)
20022001
} else {
20032002
for _, result := range results {
2004-
id := com.StrTo(result["id"]).MustInt64()
2003+
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
20052004
select {
20062005
case <-ctx.Done():
20072006
log.Warn("CheckRepoStats: Cancelled during %s for repo ID %d", desc, id)
@@ -2024,7 +2023,7 @@ func CheckRepoStats(ctx context.Context) error {
20242023
log.Error("Select %s: %v", desc, err)
20252024
} else {
20262025
for _, result := range results {
2027-
id := com.StrTo(result["id"]).MustInt64()
2026+
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
20282027
select {
20292028
case <-ctx.Done():
20302029
log.Warn("CheckRepoStats: Cancelled")
@@ -2047,7 +2046,7 @@ func CheckRepoStats(ctx context.Context) error {
20472046
log.Error("Select repository count 'num_forks': %v", err)
20482047
} else {
20492048
for _, result := range results {
2050-
id := com.StrTo(result["id"]).MustInt64()
2049+
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
20512050
select {
20522051
case <-ctx.Done():
20532052
log.Warn("CheckRepoStats: Cancelled")

models/repo_unit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ package models
66

77
import (
88
"encoding/json"
9+
"fmt"
910

1011
"code.gitea.io/gitea/modules/timeutil"
1112

12-
"github.com/unknwon/com"
1313
"xorm.io/xorm"
1414
"xorm.io/xorm/convert"
1515
)
@@ -147,7 +147,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
147147
case UnitTypeIssues:
148148
r.Config = new(IssuesConfig)
149149
default:
150-
panic("unrecognized repo unit type: " + com.ToStr(*val))
150+
panic(fmt.Sprintf("unrecognized repo unit type: %v", *val))
151151
}
152152
}
153153
}

models/ssh_key.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"math/big"
2121
"os"
2222
"path/filepath"
23+
"strconv"
2324
"strings"
2425
"sync"
2526
"time"
@@ -30,7 +31,6 @@ import (
3031
"code.gitea.io/gitea/modules/timeutil"
3132
"code.gitea.io/gitea/modules/util"
3233

33-
"github.com/unknwon/com"
3434
"golang.org/x/crypto/ssh"
3535
"xorm.io/builder"
3636
"xorm.io/xorm"
@@ -252,7 +252,11 @@ func SSHKeyGenParsePublicKey(key string) (string, int, error) {
252252
}
253253

254254
keyType := strings.Trim(fields[len(fields)-1], "()\r\n")
255-
return strings.ToLower(keyType), com.StrTo(fields[0]).MustInt(), nil
255+
length, err := strconv.ParseInt(fields[0], 10, 32)
256+
if err != nil {
257+
return "", 0, err
258+
}
259+
return strings.ToLower(keyType), int(length), nil
256260
}
257261

258262
// SSHNativeParsePublicKey extracts the key type and length using the golang SSH library.
@@ -744,7 +748,7 @@ func rewriteAllPublicKeys(e Engine) error {
744748
}
745749
if isExist {
746750
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
747-
if err = com.Copy(fPath, bakPath); err != nil {
751+
if err = util.CopyFile(fPath, bakPath); err != nil {
748752
return err
749753
}
750754
}
@@ -1226,7 +1230,7 @@ func rewriteAllPrincipalKeys(e Engine) error {
12261230
}
12271231
if isExist {
12281232
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
1229-
if err = com.Copy(fPath, bakPath); err != nil {
1233+
if err = util.CopyFile(fPath, bakPath); err != nil {
12301234
return err
12311235
}
12321236
}

models/unit_tests.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"code.gitea.io/gitea/modules/util"
2020

2121
"github.com/stretchr/testify/assert"
22-
"github.com/unknwon/com"
2322
"xorm.io/xorm"
2423
"xorm.io/xorm/names"
2524
)
@@ -82,8 +81,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
8281
if err = util.RemoveAll(setting.RepoRootPath); err != nil {
8382
fatalTestError("util.RemoveAll: %v\n", err)
8483
}
85-
if err = com.CopyDir(filepath.Join(pathToGiteaRoot, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
86-
fatalTestError("com.CopyDir: %v\n", err)
84+
if err = util.CopyDir(filepath.Join(pathToGiteaRoot, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
85+
fatalTestError("util.CopyDir: %v\n", err)
8786
}
8887

8988
exitStatus := m.Run()
@@ -126,7 +125,7 @@ func PrepareTestEnv(t testing.TB) {
126125
assert.NoError(t, PrepareTestDatabase())
127126
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
128127
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
129-
assert.NoError(t, com.CopyDir(metaPath, setting.RepoRootPath))
128+
assert.NoError(t, util.CopyDir(metaPath, setting.RepoRootPath))
130129
base.SetupGiteaRoot() // Makes sure GITEA_ROOT is set
131130
}
132131

models/user.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"code.gitea.io/gitea/modules/timeutil"
3333
"code.gitea.io/gitea/modules/util"
3434

35-
"github.com/unknwon/com"
3635
"golang.org/x/crypto/argon2"
3736
"golang.org/x/crypto/bcrypt"
3837
"golang.org/x/crypto/pbkdf2"
@@ -315,7 +314,7 @@ func (u *User) HTMLURL() string {
315314
// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
316315
func (u *User) GenerateEmailActivateCode(email string) string {
317316
code := base.CreateTimeLimitCode(
318-
com.ToStr(u.ID)+email+u.LowerName+u.Passwd+u.Rands,
317+
fmt.Sprintf("%d%s%s%s%s", u.ID, email, u.LowerName, u.Passwd, u.Rands),
319318
setting.Service.ActiveCodeLives, nil)
320319

321320
// Add tail hex username
@@ -880,7 +879,7 @@ func VerifyUserActiveCode(code string) (user *User) {
880879
if user = getVerifyUser(code); user != nil {
881880
// time limit code
882881
prefix := code[:base.TimeLimitCodeLength]
883-
data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Passwd + user.Rands
882+
data := fmt.Sprintf("%d%s%s%s%s", user.ID, user.Email, user.LowerName, user.Passwd, user.Rands)
884883

885884
if base.VerifyTimeLimitCode(data, minutes, prefix) {
886885
return user
@@ -896,7 +895,7 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress {
896895
if user := getVerifyUser(code); user != nil {
897896
// time limit code
898897
prefix := code[:base.TimeLimitCodeLength]
899-
data := com.ToStr(user.ID) + email + user.LowerName + user.Passwd + user.Rands
898+
data := fmt.Sprintf("%d%s%s%s%s", user.ID, email, user.LowerName, user.Passwd, user.Rands)
900899

901900
if base.VerifyTimeLimitCode(data, minutes, prefix) {
902901
emailAddress := &EmailAddress{UID: user.ID, Email: email}

0 commit comments

Comments
 (0)