Skip to content

refactor: update format #15057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 2 additions & 5 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func runCreateUser(c *cli.Context) error {
}

// always default to true
var changePassword = true
changePassword := true

// If this is the first user being created.
// Take it as the admin and don't force a password update.
Expand Down Expand Up @@ -453,7 +453,6 @@ func runListUsers(c *cli.Context) error {
}

users, err := models.GetAllUsers()

if err != nil {
return err
}
Expand All @@ -477,7 +476,6 @@ func runListUsers(c *cli.Context) error {

w.Flush()
return nil

}

func runDeleteUser(c *cli.Context) error {
Expand Down Expand Up @@ -668,7 +666,7 @@ func runUpdateOauth(c *cli.Context) error {
}

// update custom URL mapping
var customURLMapping = &oauth2.CustomURLMapping{}
customURLMapping := &oauth2.CustomURLMapping{}

if oAuth2Config.CustomURLMapping != nil {
customURLMapping.TokenURL = oAuth2Config.CustomURLMapping.TokenURL
Expand Down Expand Up @@ -704,7 +702,6 @@ func runListAuth(c *cli.Context) error {
}

loginSources, err := models.LoginSources()

if err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/admin_auth_ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (

func TestAddLdapBindDn(t *testing.T) {
// Mock cli functions to do not exit on error
var osExiter = cli.OsExiter
osExiter := cli.OsExiter
defer func() { cli.OsExiter = osExiter }()
cli.OsExiter = func(code int) {}

// Test cases
var cases = []struct {
cases := []struct {
args []string
loginSource *models.LoginSource
errMsg string
Expand Down Expand Up @@ -244,12 +244,12 @@ func TestAddLdapBindDn(t *testing.T) {

func TestAddLdapSimpleAuth(t *testing.T) {
// Mock cli functions to do not exit on error
var osExiter = cli.OsExiter
osExiter := cli.OsExiter
defer func() { cli.OsExiter = osExiter }()
cli.OsExiter = func(code int) {}

// Test cases
var cases = []struct {
cases := []struct {
args []string
loginSource *models.LoginSource
errMsg string
Expand Down Expand Up @@ -477,12 +477,12 @@ func TestAddLdapSimpleAuth(t *testing.T) {

func TestUpdateLdapBindDn(t *testing.T) {
// Mock cli functions to do not exit on error
var osExiter = cli.OsExiter
osExiter := cli.OsExiter
defer func() { cli.OsExiter = osExiter }()
cli.OsExiter = func(code int) {}

// Test cases
var cases = []struct {
cases := []struct {
args []string
id int64
existingLoginSource *models.LoginSource
Expand Down Expand Up @@ -958,12 +958,12 @@ func TestUpdateLdapBindDn(t *testing.T) {

func TestUpdateLdapSimpleAuth(t *testing.T) {
// Mock cli functions to do not exit on error
var osExiter = cli.OsExiter
osExiter := cli.OsExiter
defer func() { cli.OsExiter = osExiter }()
cli.OsExiter = func(code int) {}

// Test cases
var cases = []struct {
cases := []struct {
args []string
id int64
existingLoginSource *models.LoginSource
Expand Down
2 changes: 1 addition & 1 deletion cmd/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func runCert(c *cli.Context) error {
}
log.Println("Written cert.pem")

keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
log.Fatalf("Failed to open key.pem for writing: %v", err)
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ func runRecreateTable(ctx *cli.Context) error {
}
return recreateTables(x)
})

}

func runDoctor(ctx *cli.Context) error {

// Silence the default loggers
log.DelNamedLogger("console")
log.DelNamedLogger(log.DEFAULT)
Expand Down
6 changes: 3 additions & 3 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/urfave/cli"
)

func addFile(w archiver.Writer, filePath string, absPath string, verbose bool) error {
func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
if verbose {
log.Info("Adding file %s\n", filePath)
}
Expand All @@ -49,7 +49,7 @@ func addFile(w archiver.Writer, filePath string, absPath string, verbose bool) e
})
}

func isSubdir(upper string, lower string) (bool, error) {
func isSubdir(upper, lower string) (bool, error) {
if relPath, err := filepath.Rel(upper, lower); err != nil {
return false, err
} else if relPath == "." || !strings.HasPrefix(relPath, ".") {
Expand Down Expand Up @@ -353,7 +353,7 @@ func runDump(ctx *cli.Context) error {
fatal("Failed to save %s: %v", fileName, err)
}

if err := os.Chmod(fileName, 0600); err != nil {
if err := os.Chmod(fileName, 0o600); err != nil {
log.Info("Can't change file access permissions mask to 0600: %v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dump_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func runDumpRepository(ctx *cli.Context) error {
}
serviceType = convert.ToGitServiceType(serviceStr)

var opts = base.MigrateOptions{
opts := base.MigrateOptions{
GitServiceType: serviceType,
CloneAddr: cloneAddr,
AuthUsername: ctx.String("auth_username"),
Expand Down
13 changes: 7 additions & 6 deletions cmd/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ type asset struct {
}

func initEmbeddedExtractor(c *cli.Context) error {

// Silence the console logger
log.DelNamedLogger("console")
log.DelNamedLogger(log.DEFAULT)
Expand Down Expand Up @@ -258,7 +257,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
return fmt.Errorf("%s: %v", dir, err)
}

perms := os.ModePerm & 0666
perms := os.ModePerm & 0o666

fi, err := os.Lstat(dest)
if err != nil {
Expand Down Expand Up @@ -294,7 +293,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
}

func buildAssetList(sec *section, globs []glob.Glob, c *cli.Context) []asset {
var results = make([]asset, 0, 64)
results := make([]asset, 0, 64)
for _, name := range sec.Names() {
if isdir, err := sec.IsDir(name); !isdir && err == nil {
if sec.Path == "public" &&
Expand All @@ -305,9 +304,11 @@ func buildAssetList(sec *section, globs []glob.Glob, c *cli.Context) []asset {
matchName := sec.Path + "/" + name
for _, g := range globs {
if g.Match(matchName) {
results = append(results, asset{Section: sec,
Name: name,
Path: sec.Path + "/" + name})
results = append(results, asset{
Section: sec,
Name: name,
Path: sec.Path + "/" + name,
})
break
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var (
Name: "timeout",
Value: 60 * time.Second,
Usage: "Timeout for the flushing process",
}, cli.BoolFlag{
},
cli.BoolFlag{
Name: "non-blocking",
Usage: "Set to true to not wait for flush to complete before returning",
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/restore_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func runRestoreRepository(ctx *cli.Context) error {
return err
}

var opts = base.MigrateOptions{
opts := base.MigrateOptions{
RepoName: ctx.String("repo_name"),
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func runServ(c *cli.Context) error {
os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
os.Setenv(models.EnvAppURL, setting.AppURL)

//LFS token authentication
// LFS token authentication
if verb == lfsAuthenticateVerb {
url := fmt.Sprintf("%s%s/%s.git/info/lfs", setting.AppURL, url.PathEscape(results.OwnerName), url.PathEscape(results.RepoName))

Expand Down
3 changes: 1 addition & 2 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func runHTTPRedirector() {
http.Redirect(w, r, target, http.StatusTemporaryRedirect)
})

var err = runHTTP("tcp", source, "HTTP Redirector", context2.ClearHandler(handler))

err := runHTTP("tcp", source, "HTTP Redirector", context2.ClearHandler(handler))
if err != nil {
log.Fatal("Failed to start port redirection: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/web_letsencrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler) error {

// If HTTP Challenge enabled, needs to be serving on port 80. For TLSALPN needs 443.
// Due to docker port mapping this can't be checked programatically
// TODO: these are placeholders until we add options for each in settings with appropriate warning
Expand Down Expand Up @@ -46,7 +45,7 @@ func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler)
go func() {
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
var err = runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
err := runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
if err != nil {
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/fixtures/fixture_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func generate(name string) error {
return err
}
path := filepath.Join(fixturesDir, name+".yml")
if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil {
if err := ioutil.WriteFile(path, []byte(data), 0o644); err != nil {
return fmt.Errorf("%s: %+v", path, err)
}
fmt.Printf("%s created.\n", path)
Expand Down
35 changes: 18 additions & 17 deletions contrib/pr/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func runPR() {

routers.NewServices()
setting.Database.LogSQL = true
//x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
// x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")

models.NewEngine(context.Background(), func(_ *xorm.Engine) error {
return nil
})
models.HasEngine = true
//x.ShowSQL(true)
// x.ShowSQL(true)
err = models.InitFixtures(
path.Join(curDir, "models/fixtures/"),
)
Expand All @@ -113,7 +113,7 @@ func runPR() {
util.CopyDir(path.Join(curDir, "integrations/gitea-repositories-meta"), setting.RepoRootPath)

log.Printf("[PR] Setting up router\n")
//routers.GlobalInit()
// routers.GlobalInit()
external.RegisterParsers()
markup.Init()
c := routes.NormalRoutes()
Expand All @@ -135,7 +135,7 @@ func runPR() {
}
*/

//Start the server
// Start the server
http.ListenAndServe(":8080", context2.ClearHandler(c))

log.Printf("[PR] Cleaning up ...\n")
Expand All @@ -158,7 +158,7 @@ func runPR() {
}

func main() {
var runPRFlag = flag.Bool("run", false, "Run the PR code")
runPRFlag := flag.Bool("run", false, "Run the PR code")
flag.Parse()
if *runPRFlag {
runPR()
Expand All @@ -171,15 +171,15 @@ func main() {
force = false
}

//Otherwise checkout PR
// Otherwise checkout PR
if len(os.Args) != 2 {
log.Fatal("Need only one arg: the PR number")
}
pr := os.Args[1]

codeFilePath = filepath.FromSlash(codeFilePath) //Convert to running OS
codeFilePath = filepath.FromSlash(codeFilePath) // Convert to running OS

//Copy this file if it will not exist in the PR branch
// Copy this file if it will not exist in the PR branch
dat, err := ioutil.ReadFile(codeFilePath)
if err != nil {
log.Fatalf("Failed to cache this code file : %v", err)
Expand All @@ -190,16 +190,16 @@ func main() {
log.Fatalf("Failed to open the repo : %v", err)
}

//Find remote upstream
// Find remote upstream
remotes, err := repo.Remotes()
if err != nil {
log.Fatalf("Failed to list remotes of repo : %v", err)
}
remoteUpstream := "origin" //Default
remoteUpstream := "origin" // Default
for _, r := range remotes {
if r.Config().URLs[0] == "https://github.com/go-gitea/gitea.git" ||
r.Config().URLs[0] == "https://github.com/go-gitea/gitea" ||
r.Config().URLs[0] == "[email protected]:go-gitea/gitea.git" { //fetch at index 0
r.Config().URLs[0] == "[email protected]:go-gitea/gitea.git" { // fetch at index 0
remoteUpstream = r.Config().Name
break
}
Expand All @@ -210,7 +210,7 @@ func main() {

log.Printf("Fetching PR #%s in %s\n", pr, branch)
if runtime.GOOS == "windows" {
//Use git cli command for windows
// Use git cli command for windows
runCmd("git", "fetch", remoteUpstream, fmt.Sprintf("pull/%s/head:%s", pr, branch))
} else {
ref := fmt.Sprintf("refs/pull/%s/head:%s", pr, branchRef)
Expand Down Expand Up @@ -238,22 +238,23 @@ func main() {
log.Fatalf("Failed to checkout %s : %v", branch, err)
}

//Copy this file if not exist
// Copy this file if not exist
if _, err := os.Stat(codeFilePath); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(codeFilePath), 0755)
err = os.MkdirAll(filepath.Dir(codeFilePath), 0o755)
if err != nil {
log.Fatalf("Failed to duplicate this code file in PR : %v", err)
}
err = ioutil.WriteFile(codeFilePath, dat, 0644)
err = ioutil.WriteFile(codeFilePath, dat, 0o644)
if err != nil {
log.Fatalf("Failed to duplicate this code file in PR : %v", err)
}
}
//Force build of js, css, bin, ...
// Force build of js, css, bin, ...
runCmd("make", "build")
//Start with integration test
// Start with integration test
runCmd("go", "run", "-mod", "vendor", "-tags", "sqlite sqlite_unlock_notify", codeFilePath, "-run")
}

func runCmd(cmd ...string) {
log.Printf("Executing : %s ...\n", cmd)
c := exec.Command(cmd[0], cmd[1:]...)
Expand Down
Loading