aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cert.go14
-rw-r--r--cmd/cmd.go42
-rw-r--r--cmd/dump.go4
-rw-r--r--cmd/serve.go93
-rw-r--r--cmd/update.go12
-rw-r--r--cmd/web.go77
6 files changed, 159 insertions, 83 deletions
diff --git a/cmd/cert.go b/cmd/cert.go
index 0a09b003..7b68f330 100644
--- a/cmd/cert.go
+++ b/cmd/cert.go
@@ -32,12 +32,12 @@ var CmdCert = cli.Command{
Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
Action: runCert,
Flags: []cli.Flag{
- cli.StringFlag{"host", "", "Comma-separated hostnames and IPs to generate a certificate for", ""},
- cli.StringFlag{"ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521", ""},
- cli.IntFlag{"rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set", ""},
- cli.StringFlag{"start-date", "", "Creation date formatted as Jan 1 15:04:05 2011", ""},
- cli.DurationFlag{"duration", 365 * 24 * time.Hour, "Duration that certificate is valid for", ""},
- cli.BoolFlag{"ca", "whether this cert should be its own Certificate Authority", ""},
+ stringFlag("host", "", "Comma-separated hostnames and IPs to generate a certificate for"),
+ stringFlag("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521"),
+ intFlag("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set"),
+ stringFlag("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011"),
+ durationFlag("duration", 365*24*time.Hour, "Duration that certificate is valid for"),
+ boolFlag("ca", "whether this cert should be its own Certificate Authority"),
},
}
@@ -114,7 +114,7 @@ func runCert(ctx *cli.Context) {
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"Acme Co"},
- CommonName: "Gogs",
+ CommonName: "Gogs",
},
NotBefore: notBefore,
NotAfter: notAfter,
diff --git a/cmd/cmd.go b/cmd/cmd.go
new file mode 100644
index 00000000..8df02d5c
--- /dev/null
+++ b/cmd/cmd.go
@@ -0,0 +1,42 @@
+// Copyright 2015 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package cmd
+
+import (
+ "time"
+
+ "github.com/codegangsta/cli"
+)
+
+func stringFlag(name, value, usage string) cli.StringFlag {
+ return cli.StringFlag{
+ Name: name,
+ Value: value,
+ Usage: usage,
+ }
+}
+
+func boolFlag(name, usage string) cli.BoolFlag {
+ return cli.BoolFlag{
+ Name: name,
+ Usage: usage,
+ }
+}
+
+func intFlag(name string, value int, usage string) cli.IntFlag {
+ return cli.IntFlag{
+ Name: name,
+ Value: value,
+ Usage: usage,
+ }
+}
+
+func durationFlag(name string, value time.Duration, usage string) cli.DurationFlag {
+ return cli.DurationFlag{
+ Name: name,
+ Value: value,
+ Usage: usage,
+ }
+}
diff --git a/cmd/dump.go b/cmd/dump.go
index 44b180c3..0bf385d0 100644
--- a/cmd/dump.go
+++ b/cmd/dump.go
@@ -25,8 +25,8 @@ var CmdDump = cli.Command{
It can be used for backup and capture Gogs server image to send to maintainer`,
Action: runDump,
Flags: []cli.Flag{
- cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""},
- cli.BoolFlag{"verbose, v", "show process details", ""},
+ stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
+ boolFlag("verbose, v", "show process details"),
},
}
diff --git a/cmd/serve.go b/cmd/serve.go
index 34ebe9fb..b6ab9bb8 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -5,6 +5,7 @@
package cmd
import (
+ "crypto/tls"
"fmt"
"os"
"os/exec"
@@ -32,7 +33,7 @@ var CmdServ = cli.Command{
Description: `Serv provide access auth for repositories`,
Action: runServ,
Flags: []cli.Flag{
- cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""},
+ stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
},
}
@@ -73,7 +74,51 @@ var (
func fail(userMessage, logMessage string, args ...interface{}) {
fmt.Fprintln(os.Stderr, "Gogs:", userMessage)
- log.GitLogger.Fatal(3, logMessage, args...)
+
+ if len(logMessage) > 0 {
+ log.GitLogger.Fatal(3, logMessage, args...)
+ return
+ }
+
+ log.GitLogger.Close()
+ os.Exit(1)
+}
+
+func handleUpdateTask(uuid string, user *models.User, repoUserName, repoName string) {
+ task, err := models.GetUpdateTaskByUUID(uuid)
+ if err != nil {
+ if models.IsErrUpdateTaskNotExist(err) {
+ log.GitLogger.Trace("No update task is presented: %s", uuid)
+ return
+ }
+ log.GitLogger.Fatal(2, "GetUpdateTaskByUUID: %v", err)
+ }
+
+ if err = models.Update(task.RefName, task.OldCommitID, task.NewCommitID,
+ user.Name, repoUserName, repoName, user.Id); err != nil {
+ log.GitLogger.Error(2, "Update: %v", err)
+ }
+
+ if err = models.DeleteUpdateTaskByUUID(uuid); err != nil {
+ log.GitLogger.Fatal(2, "DeleteUpdateTaskByUUID: %v", err)
+ }
+
+ // Ask for running deliver hook and test pull request tasks.
+ reqURL := setting.AppUrl + repoUserName + "/" + repoName + "/tasks/trigger?branch=" +
+ strings.TrimPrefix(task.RefName, "refs/heads/")
+ log.GitLogger.Trace("Trigger task: %s", reqURL)
+
+ resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{
+ InsecureSkipVerify: true,
+ }).Response()
+ if err == nil {
+ resp.Body.Close()
+ if resp.StatusCode/100 != 2 {
+ log.GitLogger.Error(2, "Fail to trigger task: not 2xx response code")
+ }
+ } else {
+ log.GitLogger.Error(2, "Fail to trigger task: %v", err)
+ }
}
func runServ(c *cli.Context) {
@@ -94,13 +139,13 @@ func runServ(c *cli.Context) {
}
verb, args := parseCmd(cmd)
- repoPath := strings.Trim(args, "'")
+ repoPath := strings.ToLower(strings.Trim(args, "'"))
rr := strings.SplitN(repoPath, "/", 2)
if len(rr) != 2 {
fail("Invalid repository path", "Invalid repository path: %v", args)
}
- repoUserName := rr[0]
- repoName := strings.TrimSuffix(rr[1], ".git")
+ repoUserName := strings.ToLower(rr[0])
+ repoName := strings.ToLower(strings.TrimSuffix(rr[1], ".git"))
repoUser, err := models.GetUserByName(repoUserName)
if err != nil {
@@ -123,6 +168,11 @@ func runServ(c *cli.Context) {
fail("Unknown git command", "Unknown git command %s", verb)
}
+ // Prohibit push to mirror repositories.
+ if requestedMode > models.ACCESS_MODE_READ && repo.IsMirror {
+ fail("mirror repository is read-only", "")
+ }
+
// Allow anonymous clone for public repositories.
var (
keyID int64
@@ -131,12 +181,12 @@ func runServ(c *cli.Context) {
if requestedMode == models.ACCESS_MODE_WRITE || repo.IsPrivate {
keys := strings.Split(c.Args()[0], "-")
if len(keys) != 2 {
- fail("Key ID format error", "Invalid key ID: %s", c.Args()[0])
+ fail("Key ID format error", "Invalid key argument: %s", c.Args()[0])
}
key, err := models.GetPublicKeyByID(com.StrTo(keys[1]).MustInt64())
if err != nil {
- fail("Key ID format error", "Invalid key ID[%s]: %v", c.Args()[0], err)
+ fail("Invalid key ID", "Invalid key ID[%s]: %v", c.Args()[0], err)
}
keyID = key.ID
@@ -161,7 +211,7 @@ func runServ(c *cli.Context) {
fail("Internal error", "UpdateDeployKey: %v", err)
}
} else {
- user, err = models.GetUserByKeyId(key.ID)
+ user, err = models.GetUserByKeyID(key.ID)
if err != nil {
fail("internal error", "Failed to get user by key ID(%d): %v", keyID, err)
}
@@ -200,32 +250,7 @@ func runServ(c *cli.Context) {
}
if requestedMode == models.ACCESS_MODE_WRITE {
- tasks, err := models.GetUpdateTasksByUuid(uuid)
- if err != nil {
- log.GitLogger.Fatal(2, "GetUpdateTasksByUuid: %v", err)
- }
-
- for _, task := range tasks {
- err = models.Update(task.RefName, task.OldCommitId, task.NewCommitId,
- user.Name, repoUserName, repoName, user.Id)
- if err != nil {
- log.GitLogger.Error(2, "Failed to update: %v", err)
- }
- }
-
- if err = models.DelUpdateTasksByUuid(uuid); err != nil {
- log.GitLogger.Fatal(2, "DelUpdateTasksByUuid: %v", err)
- }
- }
-
- // Send deliver hook request.
- reqURL := setting.AppUrl + repoUserName + "/" + repoName + "/hooks/trigger"
- resp, err := httplib.Head(reqURL).Response()
- if err == nil {
- resp.Body.Close()
- log.GitLogger.Trace("Trigger hook: %s", reqURL)
- } else {
- log.GitLogger.Error(2, "Fail to trigger hook: %v", err)
+ handleUpdateTask(uuid, user, repoUserName, repoName)
}
// Update user key activity.
diff --git a/cmd/update.go b/cmd/update.go
index c9eaeccf..4cd62a7f 100644
--- a/cmd/update.go
+++ b/cmd/update.go
@@ -20,7 +20,7 @@ var CmdUpdate = cli.Command{
Description: `Update get pushed info and insert into database`,
Action: runUpdate,
Flags: []cli.Flag{
- cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""},
+ stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
},
}
@@ -42,16 +42,14 @@ func runUpdate(c *cli.Context) {
log.GitLogger.Fatal(2, "refName is empty, shouldn't use")
}
- uuid := os.Getenv("uuid")
-
task := models.UpdateTask{
- Uuid: uuid,
+ UUID: os.Getenv("uuid"),
RefName: args[0],
- OldCommitId: args[1],
- NewCommitId: args[2],
+ OldCommitID: args[1],
+ NewCommitID: args[2],
}
if err := models.AddUpdateTask(&task); err != nil {
- log.GitLogger.Fatal(2, err.Error())
+ log.GitLogger.Fatal(2, "AddUpdateTask: %v", err)
}
}
diff --git a/cmd/web.go b/cmd/web.go
index 30fd4b79..cb14b7c9 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -7,7 +7,7 @@ package cmd
import (
"crypto/tls"
"fmt"
- "html/template"
+ gotmpl "html/template"
"io/ioutil"
"net/http"
"net/http/fcgi"
@@ -15,18 +15,19 @@ import (
"path"
"strings"
- "github.com/Unknwon/macaron"
"github.com/codegangsta/cli"
+ "github.com/go-macaron/binding"
+ "github.com/go-macaron/cache"
+ "github.com/go-macaron/captcha"
+ "github.com/go-macaron/csrf"
+ "github.com/go-macaron/gzip"
+ "github.com/go-macaron/i18n"
+ "github.com/go-macaron/session"
+ "github.com/go-macaron/toolbox"
"github.com/go-xorm/xorm"
- "github.com/macaron-contrib/binding"
- "github.com/macaron-contrib/cache"
- "github.com/macaron-contrib/captcha"
- "github.com/macaron-contrib/csrf"
- "github.com/macaron-contrib/i18n"
- "github.com/macaron-contrib/session"
- "github.com/macaron-contrib/toolbox"
"github.com/mcuadros/go-version"
"gopkg.in/ini.v1"
+ "gopkg.in/macaron.v1"
api "github.com/gogits/go-gogs-client"
@@ -34,11 +35,11 @@ import (
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/auth/apiv1"
"github.com/gogits/gogs/modules/avatar"
- "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/bindata"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
+ "github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/routers"
"github.com/gogits/gogs/routers/admin"
"github.com/gogits/gogs/routers/api/v1"
@@ -55,8 +56,8 @@ var CmdWeb = cli.Command{
and it takes care of all the other things for you`,
Action: runWeb,
Flags: []cli.Flag{
- cli.StringFlag{"port, p", "3000", "Temporary port number to prevent conflict", ""},
- cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""},
+ stringFlag("port, p", "3000", "Temporary port number to prevent conflict"),
+ stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
},
}
@@ -79,13 +80,14 @@ func checkVersion() {
// Check dependency version.
checkers := []VerChecker{
- {"github.com/go-xorm/xorm", func() string { return xorm.Version }, "0.4.3.0806"},
+ {"github.com/go-xorm/xorm", func() string { return xorm.Version }, "0.4.4.1029"},
{"github.com/Unknwon/macaron", macaron.Version, "0.5.4"},
- {"github.com/macaron-contrib/binding", binding.Version, "0.1.0"},
- {"github.com/macaron-contrib/cache", cache.Version, "0.1.2"},
- {"github.com/macaron-contrib/csrf", csrf.Version, "0.0.3"},
- {"github.com/macaron-contrib/i18n", i18n.Version, "0.0.7"},
- {"github.com/macaron-contrib/session", session.Version, "0.1.6"},
+ {"github.com/go-macaron/binding", binding.Version, "0.1.0"},
+ {"github.com/go-macaron/cache", cache.Version, "0.1.2"},
+ {"github.com/go-macaron/csrf", csrf.Version, "0.0.3"},
+ {"github.com/go-macaron/i18n", i18n.Version, "0.0.7"},
+ {"github.com/go-macaron/session", session.Version, "0.1.6"},
+ {"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
{"gopkg.in/ini.v1", ini.Version, "1.3.4"},
}
for _, c := range checkers {
@@ -103,7 +105,7 @@ func newMacaron() *macaron.Macaron {
}
m.Use(macaron.Recovery())
if setting.EnableGzip {
- m.Use(macaron.Gziper())
+ m.Use(gzip.Gziper())
}
if setting.Protocol == setting.FCGI {
m.SetURLPrefix(setting.AppSubUrl)
@@ -123,7 +125,7 @@ func newMacaron() *macaron.Macaron {
))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "templates"),
- Funcs: []template.FuncMap{base.TemplateFuncs},
+ Funcs: []gotmpl.FuncMap{template.Funcs},
IndentJSON: macaron.Env != macaron.PROD,
}))
@@ -223,11 +225,12 @@ func runWeb(ctx *cli.Context) {
m.Group("/repos", func() {
m.Get("/search", v1.SearchRepos)
+ })
- m.Group("", func() {
- m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo)
- m.Delete("/:username/:reponame", v1.DeleteRepo)
- }, middleware.ApiReqToken())
+ m.Group("/repos", func() {
+ m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo)
+ m.Combo("/:username/:reponame").Get(v1.GetRepo).
+ Delete(v1.DeleteRepo)
m.Group("/:username/:reponame", func() {
m.Combo("/hooks").Get(v1.ListRepoHooks).
@@ -235,8 +238,8 @@ func runWeb(ctx *cli.Context) {
m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook)
m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile)
m.Get("/archive/*", v1.GetRepoArchive)
- }, middleware.ApiRepoAssignment(), middleware.ApiReqToken())
- })
+ }, middleware.ApiRepoAssignment())
+ }, middleware.ApiReqToken())
m.Any("/*", func(ctx *middleware.Context) {
ctx.Error(404)
@@ -460,8 +463,10 @@ func runWeb(ctx *cli.Context) {
m.Post("/delete", repo.DeleteDeployKey)
})
+ }, func(ctx *middleware.Context) {
+ ctx.Data["PageIsSettings"] = true
})
- }, reqSignIn, middleware.RepoAssignment(true), reqRepoAdmin)
+ }, reqSignIn, middleware.RepoAssignment(true), reqRepoAdmin, middleware.RepoRef())
m.Group("/:username/:reponame", func() {
m.Get("/action/:action", repo.Action)
@@ -509,11 +514,17 @@ func runWeb(ctx *cli.Context) {
}, reqSignIn, middleware.RepoAssignment(true))
m.Group("/:username/:reponame", func() {
- m.Get("/releases", middleware.RepoRef(), repo.Releases)
- m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
+ m.Group("", func() {
+ m.Get("/releases", repo.Releases)
+ m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
+ m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
+ m.Get("/milestones", repo.Milestones)
+ }, middleware.RepoRef(),
+ func(ctx *middleware.Context) {
+ ctx.Data["PageIsList"] = true
+ })
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)
- m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
- m.Get("/milestones", repo.Milestones)
+
m.Get("/branches", repo.Branches)
m.Get("/archive/*", repo.Download)
@@ -543,8 +554,8 @@ func runWeb(ctx *cli.Context) {
}, ignSignIn, middleware.RepoAssignment(true, true), middleware.RepoRef())
m.Group("/:reponame", func() {
- m.Any("/*", ignSignInAndCsrf, repo.Http)
- m.Head("/hooks/trigger", repo.TriggerHook)
+ m.Any("/*", ignSignInAndCsrf, repo.HTTP)
+ m.Head("/tasks/trigger", repo.TriggerTask)
})
})
// ***** END: Repository *****