mirror of
https://github.com/gogs/gogs.git
synced 2026-05-07 00:56:32 +02:00
Replace github.com/unknwon/com with stdlib and internal helpers (#8148)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Joe Chen <jc@unknwon.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,9 +9,9 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"github.com/urfave/cli"
|
||||
log "unknwon.dev/clog/v2"
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"gogs.io/gogs/internal/database"
|
||||
"gogs.io/gogs/internal/email"
|
||||
"gogs.io/gogs/internal/httplib"
|
||||
"gogs.io/gogs/internal/osutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -85,7 +86,7 @@ func runHookPreReceive(c *cli.Context) error {
|
||||
branchName := git.RefShortName(string(fields[2]))
|
||||
|
||||
// Branch protection
|
||||
repoID := com.StrTo(os.Getenv(database.EnvRepoID)).MustInt64()
|
||||
repoID, _ := strconv.ParseInt(os.Getenv(database.EnvRepoID), 10, 64)
|
||||
protectBranch, err := database.GetProtectBranchOfRepoByName(repoID, branchName)
|
||||
if err != nil {
|
||||
if database.IsErrBranchNotExist(err) {
|
||||
@@ -101,7 +102,7 @@ func runHookPreReceive(c *cli.Context) error {
|
||||
bypassRequirePullRequest := false
|
||||
|
||||
// Check if user is in whitelist when enabled
|
||||
userID := com.StrTo(os.Getenv(database.EnvAuthUserID)).MustInt64()
|
||||
userID, _ := strconv.ParseInt(os.Getenv(database.EnvAuthUserID), 10, 64)
|
||||
if protectBranch.EnableWhitelist {
|
||||
if !database.IsUserInProtectBranchWhitelist(repoID, userID, branchName) {
|
||||
fail(fmt.Sprintf("Branch '%s' is protected and you are not in the push whitelist", branchName), "")
|
||||
@@ -131,7 +132,7 @@ func runHookPreReceive(c *cli.Context) error {
|
||||
}
|
||||
|
||||
customHooksPath := filepath.Join(os.Getenv(database.EnvRepoCustomHooksPath), "pre-receive")
|
||||
if !com.IsFile(customHooksPath) {
|
||||
if !osutil.IsFile(customHooksPath) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ func runHookUpdate(c *cli.Context) error {
|
||||
}
|
||||
|
||||
customHooksPath := filepath.Join(os.Getenv(database.EnvRepoCustomHooksPath), "update")
|
||||
if !com.IsFile(customHooksPath) {
|
||||
if !osutil.IsFile(customHooksPath) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -213,11 +214,12 @@ func runHookPostReceive(c *cli.Context) error {
|
||||
continue
|
||||
}
|
||||
|
||||
pusherID, _ := strconv.ParseInt(os.Getenv(database.EnvAuthUserID), 10, 64)
|
||||
options := database.PushUpdateOptions{
|
||||
OldCommitID: string(fields[0]),
|
||||
NewCommitID: string(fields[1]),
|
||||
FullRefspec: string(fields[2]),
|
||||
PusherID: com.StrTo(os.Getenv(database.EnvAuthUserID)).MustInt64(),
|
||||
PusherID: pusherID,
|
||||
PusherName: os.Getenv(database.EnvAuthUserName),
|
||||
RepoUserName: os.Getenv(database.EnvRepoOwnerName),
|
||||
RepoName: os.Getenv(database.EnvRepoName),
|
||||
@@ -249,7 +251,7 @@ func runHookPostReceive(c *cli.Context) error {
|
||||
}
|
||||
|
||||
customHooksPath := filepath.Join(os.Getenv(database.EnvRepoCustomHooksPath), "post-receive")
|
||||
if !com.IsFile(customHooksPath) {
|
||||
if !osutil.IsFile(customHooksPath) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/unknwon/com"
|
||||
"github.com/urfave/cli"
|
||||
|
||||
"gogs.io/gogs/internal/conf"
|
||||
"gogs.io/gogs/internal/osutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -44,9 +44,9 @@ func runImportLocale(c *cli.Context) error {
|
||||
} else if !c.IsSet("target") {
|
||||
return errors.New("target directory is not specified")
|
||||
}
|
||||
if !com.IsDir(c.String("source")) {
|
||||
if !osutil.IsDir(c.String("source")) {
|
||||
return errors.Newf("source directory %q does not exist or is not a directory", c.String("source"))
|
||||
} else if !com.IsDir(c.String("target")) {
|
||||
} else if !osutil.IsDir(c.String("target")) {
|
||||
return errors.Newf("target directory %q does not exist or is not a directory", c.String("target"))
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func runImportLocale(c *cli.Context) error {
|
||||
name := fmt.Sprintf("locale_%s.ini", lang)
|
||||
source := filepath.Join(c.String("source"), name)
|
||||
target := filepath.Join(c.String("target"), name)
|
||||
if !com.IsFile(source) {
|
||||
if !osutil.IsFile(source) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"github.com/urfave/cli"
|
||||
log "unknwon.dev/clog/v2"
|
||||
|
||||
@@ -188,7 +188,8 @@ func runServ(c *cli.Context) error {
|
||||
// Allow anonymous (user is nil) clone for public repositories.
|
||||
var user *database.User
|
||||
|
||||
key, err := database.GetPublicKeyByID(com.StrTo(strings.TrimPrefix(c.Args()[0], "key-")).MustInt64())
|
||||
keyID, _ := strconv.ParseInt(strings.TrimPrefix(c.Args()[0], "key-"), 10, 64)
|
||||
key, err := database.GetPublicKeyByID(keyID)
|
||||
if err != nil {
|
||||
fail("Invalid key ID", "Invalid key ID '%s': %v", c.Args()[0], err)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"github.com/go-macaron/session"
|
||||
"github.com/go-macaron/toolbox"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/unknwon/com"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/macaron.v1"
|
||||
log "unknwon.dev/clog/v2"
|
||||
@@ -308,7 +307,7 @@ func runWeb(c *cli.Context) error {
|
||||
if err != nil {
|
||||
c.NotFoundOrError(err, "get attachment by UUID")
|
||||
return
|
||||
} else if !com.IsFile(attach.LocalPath()) {
|
||||
} else if !osutil.IsFile(attach.LocalPath()) {
|
||||
c.NotFound()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user