summaryrefslogtreecommitdiffstats
path: root/cmd/serve.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-04 21:57:10 -0500
committerUnknwon <u@gogs.io>2015-11-04 21:57:10 -0500
commitf255b1e86dae17dc0221b537d85f25bfa72a7912 (patch)
tree7b27cb470f8f2a3772bf02e756c0c2ba6f50cd96 /cmd/serve.go
parent9372eedf2ea7e8ccf8b127843e592765cbc1b034 (diff)
downloadgitea-f255b1e86dae17dc0221b537d85f25bfa72a7912.tar.gz
gitea-f255b1e86dae17dc0221b537d85f25bfa72a7912.zip
#1896 fatal when no needed update task
Diffstat (limited to 'cmd/serve.go')
-rw-r--r--cmd/serve.go70
1 files changed, 39 insertions, 31 deletions
diff --git a/cmd/serve.go b/cmd/serve.go
index b99ab8fcd6..c3c66318da 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -77,6 +77,43 @@ func fail(userMessage, logMessage string, args ...interface{}) {
log.GitLogger.Fatal(3, logMessage, args...)
}
+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) {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
@@ -162,7 +199,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)
}
@@ -201,36 +238,7 @@ func runServ(c *cli.Context) {
}
if requestedMode == models.ACCESS_MODE_WRITE {
- task, err := models.GetUpdateTaskByUUID(uuid)
- if err != nil {
- 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)
- }
+ handleUpdateTask(uuid, user, repoUserName, repoName)
}
// Update user key activity.