mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +00:00
migrate from com.* to alternatives (#14103)
* remove github.com/unknwon/com from models * dont use "com.ToStr()" * replace "com.ToStr" with "fmt.Sprint" where its easy to do * more refactor * fix test * just "proxy" Copy func for now * as per @lunny
This commit is contained in:
parent
04ae0f2f3f
commit
a19447aed1
46 changed files with 230 additions and 220 deletions
|
@ -18,7 +18,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
|
@ -266,7 +265,7 @@ func (a *Action) GetIssueInfos() []string {
|
|||
// GetIssueTitle returns the title of first issue associated
|
||||
// with the action.
|
||||
func (a *Action) GetIssueTitle() string {
|
||||
index := com.StrTo(a.GetIssueInfos()[0]).MustInt64()
|
||||
index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
|
||||
issue, err := GetIssueByIndex(a.RepoID, index)
|
||||
if err != nil {
|
||||
log.Error("GetIssueByIndex: %v", err)
|
||||
|
@ -278,7 +277,7 @@ func (a *Action) GetIssueTitle() string {
|
|||
// GetIssueContent returns the content of first issue associated with
|
||||
// this action.
|
||||
func (a *Action) GetIssueContent() string {
|
||||
index := com.StrTo(a.GetIssueInfos()[0]).MustInt64()
|
||||
index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
|
||||
issue, err := GetIssueByIndex(a.RepoID, index)
|
||||
if err != nil {
|
||||
log.Error("GetIssueByIndex: %v", err)
|
||||
|
|
|
@ -12,8 +12,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
)
|
||||
|
||||
//NoticeType describes the notice type
|
||||
|
@ -36,7 +34,7 @@ type Notice struct {
|
|||
|
||||
// TrStr returns a translation format string.
|
||||
func (n *Notice) TrStr() string {
|
||||
return "admin.notices.type_" + com.ToStr(n.Type)
|
||||
return fmt.Sprintf("admin.notices.type_%d", n.Type)
|
||||
}
|
||||
|
||||
// CreateNotice creates new system notice.
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
"github.com/unknwon/com"
|
||||
)
|
||||
|
||||
// ProtectedBranch struct
|
||||
|
@ -483,7 +482,7 @@ func updateTeamWhitelist(repo *Repository, currentWhitelist, newWhitelist []int6
|
|||
|
||||
whitelist = make([]int64, 0, len(teams))
|
||||
for i := range teams {
|
||||
if com.IsSliceContainsInt64(newWhitelist, teams[i].ID) {
|
||||
if util.IsInt64InSlice(teams[i].ID, newWhitelist) {
|
||||
whitelist = append(whitelist, teams[i].ID)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
@ -386,7 +385,7 @@ func (issue *Issue) State() api.StateType {
|
|||
|
||||
// HashTag returns unique hash tag for issue.
|
||||
func (issue *Issue) HashTag() string {
|
||||
return "issue-" + com.ToStr(issue.ID)
|
||||
return fmt.Sprintf("issue-%d", issue.ID)
|
||||
}
|
||||
|
||||
// IsPoster returns true if given user by ID is the poster.
|
||||
|
@ -1374,7 +1373,8 @@ func parseCountResult(results []map[string][]byte) int64 {
|
|||
return 0
|
||||
}
|
||||
for _, result := range results[0] {
|
||||
return com.StrTo(string(result)).MustInt64()
|
||||
c, _ := strconv.ParseInt(string(result), 10, 64)
|
||||
return c
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
@ -367,7 +366,7 @@ func (c *Comment) HashTag() string {
|
|||
|
||||
// EventTag returns unique event hash tag for comment.
|
||||
func (c *Comment) EventTag() string {
|
||||
return "event-" + com.ToStr(c.ID)
|
||||
return fmt.Sprintf("event-%d", c.ID)
|
||||
}
|
||||
|
||||
// LoadLabel if comment.Type is CommentTypeLabel, then load Label
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/references"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
|
@ -324,7 +323,7 @@ func (comment *Comment) RefIssueIdent() string {
|
|||
return ""
|
||||
}
|
||||
// FIXME: check this name for cross-repository references (#7901 if it gets merged)
|
||||
return "#" + com.ToStr(comment.RefIssue.Index)
|
||||
return fmt.Sprintf("#%d", comment.RefIssue.Index)
|
||||
}
|
||||
|
||||
// __________ .__ .__ __________ __
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"fmt"
|
||||
"net/smtp"
|
||||
"net/textproto"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/auth/ldap"
|
||||
|
@ -20,8 +21,8 @@ import (
|
|||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/convert"
|
||||
)
|
||||
|
@ -180,7 +181,9 @@ func Cell2Int64(val xorm.Cell) int64 {
|
|||
switch (*val).(type) {
|
||||
case []uint8:
|
||||
log.Trace("Cell2Int64 ([]uint8): %v", *val)
|
||||
return com.StrTo(string((*val).([]uint8))).MustInt64()
|
||||
|
||||
v, _ := strconv.ParseInt(string((*val).([]uint8)), 10, 64)
|
||||
return v
|
||||
}
|
||||
return (*val).(int64)
|
||||
}
|
||||
|
@ -200,7 +203,7 @@ func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) {
|
|||
case LoginSSPI:
|
||||
source.Cfg = new(SSPIConfig)
|
||||
default:
|
||||
panic("unrecognized login source type: " + com.ToStr(*val))
|
||||
panic(fmt.Sprintf("unrecognized login source type: %v", *val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -610,7 +613,7 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
|
|||
idx := strings.Index(login, "@")
|
||||
if idx == -1 {
|
||||
return nil, ErrUserNotExist{0, login, 0}
|
||||
} else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), login[idx+1:]) {
|
||||
} else if !util.IsStringInSlice(login[idx+1:], strings.Split(cfg.AllowedDomains, ","), true) {
|
||||
return nil, ErrUserNotExist{0, login, 0}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ import (
|
|||
"code.gitea.io/gitea/modules/secret"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
uuid "github.com/google/uuid"
|
||||
"github.com/unknwon/com"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
@ -62,7 +62,7 @@ func (app *OAuth2Application) LoadUser() (err error) {
|
|||
|
||||
// ContainsRedirectURI checks if redirectURI is allowed for app
|
||||
func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
|
||||
return com.IsSliceContainsStr(app.RedirectURIs, redirectURI)
|
||||
return util.IsStringInSlice(redirectURI, app.RedirectURIs, true)
|
||||
}
|
||||
|
||||
// GenerateClientSecret will generate the client secret and returns the plaintext and saves the hash at the database
|
||||
|
|
|
@ -34,7 +34,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
|
@ -85,7 +84,7 @@ func loadRepoConfig() {
|
|||
}
|
||||
|
||||
for _, f := range customFiles {
|
||||
if !com.IsSliceContainsStr(files, f) {
|
||||
if !util.IsStringInSlice(f, files, true) {
|
||||
files = append(files, f)
|
||||
}
|
||||
}
|
||||
|
@ -115,12 +114,12 @@ func loadRepoConfig() {
|
|||
// Filter out invalid names and promote preferred licenses.
|
||||
sortedLicenses := make([]string, 0, len(Licenses))
|
||||
for _, name := range setting.Repository.PreferredLicenses {
|
||||
if com.IsSliceContainsStr(Licenses, name) {
|
||||
if util.IsStringInSlice(name, Licenses, true) {
|
||||
sortedLicenses = append(sortedLicenses, name)
|
||||
}
|
||||
}
|
||||
for _, name := range Licenses {
|
||||
if !com.IsSliceContainsStr(setting.Repository.PreferredLicenses, name) {
|
||||
if !util.IsStringInSlice(name, setting.Repository.PreferredLicenses, true) {
|
||||
sortedLicenses = append(sortedLicenses, name)
|
||||
}
|
||||
}
|
||||
|
@ -1933,7 +1932,7 @@ func repoStatsCheck(ctx context.Context, checker *repoChecker) {
|
|||
return
|
||||
}
|
||||
for _, result := range results {
|
||||
id := com.StrTo(result["id"]).MustInt64()
|
||||
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Warn("CheckRepoStats: Cancelled before checking %s for Repo[%d]", checker.desc, id)
|
||||
|
@ -2001,7 +2000,7 @@ func CheckRepoStats(ctx context.Context) error {
|
|||
log.Error("Select %s: %v", desc, err)
|
||||
} else {
|
||||
for _, result := range results {
|
||||
id := com.StrTo(result["id"]).MustInt64()
|
||||
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Warn("CheckRepoStats: Cancelled during %s for repo ID %d", desc, id)
|
||||
|
@ -2024,7 +2023,7 @@ func CheckRepoStats(ctx context.Context) error {
|
|||
log.Error("Select %s: %v", desc, err)
|
||||
} else {
|
||||
for _, result := range results {
|
||||
id := com.StrTo(result["id"]).MustInt64()
|
||||
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Warn("CheckRepoStats: Cancelled")
|
||||
|
@ -2047,7 +2046,7 @@ func CheckRepoStats(ctx context.Context) error {
|
|||
log.Error("Select repository count 'num_forks': %v", err)
|
||||
} else {
|
||||
for _, result := range results {
|
||||
id := com.StrTo(result["id"]).MustInt64()
|
||||
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Warn("CheckRepoStats: Cancelled")
|
||||
|
|
|
@ -6,10 +6,10 @@ package models
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/convert"
|
||||
)
|
||||
|
@ -147,7 +147,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
|
|||
case UnitTypeIssues:
|
||||
r.Config = new(IssuesConfig)
|
||||
default:
|
||||
panic("unrecognized repo unit type: " + com.ToStr(*val))
|
||||
panic(fmt.Sprintf("unrecognized repo unit type: %v", *val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -30,7 +31,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
|
@ -252,7 +252,11 @@ func SSHKeyGenParsePublicKey(key string) (string, int, error) {
|
|||
}
|
||||
|
||||
keyType := strings.Trim(fields[len(fields)-1], "()\r\n")
|
||||
return strings.ToLower(keyType), com.StrTo(fields[0]).MustInt(), nil
|
||||
length, err := strconv.ParseInt(fields[0], 10, 32)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
return strings.ToLower(keyType), int(length), nil
|
||||
}
|
||||
|
||||
// SSHNativeParsePublicKey extracts the key type and length using the golang SSH library.
|
||||
|
@ -744,7 +748,7 @@ func rewriteAllPublicKeys(e Engine) error {
|
|||
}
|
||||
if isExist {
|
||||
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
|
||||
if err = com.Copy(fPath, bakPath); err != nil {
|
||||
if err = util.CopyFile(fPath, bakPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -1226,7 +1230,7 @@ func rewriteAllPrincipalKeys(e Engine) error {
|
|||
}
|
||||
if isExist {
|
||||
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
|
||||
if err = com.Copy(fPath, bakPath); err != nil {
|
||||
if err = util.CopyFile(fPath, bakPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/names"
|
||||
)
|
||||
|
@ -82,8 +81,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
|
|||
if err = util.RemoveAll(setting.RepoRootPath); err != nil {
|
||||
fatalTestError("util.RemoveAll: %v\n", err)
|
||||
}
|
||||
if err = com.CopyDir(filepath.Join(pathToGiteaRoot, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
|
||||
fatalTestError("com.CopyDir: %v\n", err)
|
||||
if err = util.CopyDir(filepath.Join(pathToGiteaRoot, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
|
||||
fatalTestError("util.CopyDir: %v\n", err)
|
||||
}
|
||||
|
||||
exitStatus := m.Run()
|
||||
|
@ -126,7 +125,7 @@ func PrepareTestEnv(t testing.TB) {
|
|||
assert.NoError(t, PrepareTestDatabase())
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
|
||||
assert.NoError(t, com.CopyDir(metaPath, setting.RepoRootPath))
|
||||
assert.NoError(t, util.CopyDir(metaPath, setting.RepoRootPath))
|
||||
base.SetupGiteaRoot() // Makes sure GITEA_ROOT is set
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"golang.org/x/crypto/argon2"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
|
@ -315,7 +314,7 @@ func (u *User) HTMLURL() string {
|
|||
// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
|
||||
func (u *User) GenerateEmailActivateCode(email string) string {
|
||||
code := base.CreateTimeLimitCode(
|
||||
com.ToStr(u.ID)+email+u.LowerName+u.Passwd+u.Rands,
|
||||
fmt.Sprintf("%d%s%s%s%s", u.ID, email, u.LowerName, u.Passwd, u.Rands),
|
||||
setting.Service.ActiveCodeLives, nil)
|
||||
|
||||
// Add tail hex username
|
||||
|
@ -880,7 +879,7 @@ func VerifyUserActiveCode(code string) (user *User) {
|
|||
if user = getVerifyUser(code); user != nil {
|
||||
// time limit code
|
||||
prefix := code[:base.TimeLimitCodeLength]
|
||||
data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Passwd + user.Rands
|
||||
data := fmt.Sprintf("%d%s%s%s%s", user.ID, user.Email, user.LowerName, user.Passwd, user.Rands)
|
||||
|
||||
if base.VerifyTimeLimitCode(data, minutes, prefix) {
|
||||
return user
|
||||
|
@ -896,7 +895,7 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress {
|
|||
if user := getVerifyUser(code); user != nil {
|
||||
// time limit code
|
||||
prefix := code[:base.TimeLimitCodeLength]
|
||||
data := com.ToStr(user.ID) + email + user.LowerName + user.Passwd + user.Rands
|
||||
data := fmt.Sprintf("%d%s%s%s%s", user.ID, email, user.LowerName, user.Passwd, user.Rands)
|
||||
|
||||
if base.VerifyTimeLimitCode(data, minutes, prefix) {
|
||||
emailAddress := &EmailAddress{UID: user.ID, Email: email}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue