#1896 fatal when no needed update task
This commit is contained in:
		
							parent
							
								
									9372eedf2e
								
							
						
					
					
						commit
						f255b1e86d
					
				
					 10 changed files with 66 additions and 46 deletions
				
			
		|  | @ -5,7 +5,7 @@ Gogs - Go Git Service [ |  | ||||||
| 
 | 
 | ||||||
| ##### Current version: 0.6.25 Beta | ##### Current version: 0.6.26 Beta | ||||||
| 
 | 
 | ||||||
| <table> | <table> | ||||||
|     <tr> |     <tr> | ||||||
|  | @ -42,7 +42,7 @@ The goal of this project is to make the easiest, fastest, and most painless way | ||||||
| 
 | 
 | ||||||
| ## Overview | ## Overview | ||||||
| 
 | 
 | ||||||
| - Please see the [Documentation](http://gogs.io/docs/intro) for project design, known issues, and change log. | - Please see the [Documentation](http://gogs.io/docs/intro) for common usages and change log. | ||||||
| - See the [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) to follow the develop team. | - See the [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) to follow the develop team. | ||||||
| - Want to try it before doing anything else? Do it [online](https://try.gogs.io/gogs/gogs) or go down to the **Installation -> Install from binary** section! | - Want to try it before doing anything else? Do it [online](https://try.gogs.io/gogs/gogs) or go down to the **Installation -> Install from binary** section! | ||||||
| - Having trouble? Get help with [Troubleshooting](http://gogs.io/docs/intro/troubleshooting.html). | - Having trouble? Get help with [Troubleshooting](http://gogs.io/docs/intro/troubleshooting.html). | ||||||
|  | @ -63,7 +63,7 @@ The goal of this project is to make the easiest, fastest, and most painless way | ||||||
| - Mail service | - Mail service | ||||||
| - Administration panel | - Administration panel | ||||||
| - CI integration: [Drone](https://github.com/drone/drone) | - CI integration: [Drone](https://github.com/drone/drone) | ||||||
| - Supports MySQL, PostgreSQL, SQLite3 and [TiDB](https://github.com/pingcap/tidb) | - Supports MySQL, PostgreSQL, SQLite3 and [TiDB](https://github.com/pingcap/tidb) (experimental) | ||||||
| - Multi-language support ([14 languages](https://crowdin.com/project/gogs)) | - Multi-language support ([14 languages](https://crowdin.com/project/gogs)) | ||||||
| 
 | 
 | ||||||
| ## System Requirements | ## System Requirements | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| Gogs - Go Git Service [](https://travis-ci.org/gogits/gogs) | Gogs - Go Git Service [](https://travis-ci.org/gogits/gogs) | ||||||
| ===================== | ===================== | ||||||
| 
 | 
 | ||||||
| Gogs (Go Git Service) 是一款可轻易搭建的自助 Git 服务。 | Gogs (Go Git Service) 是一款极易搭建的自助 Git 服务。 | ||||||
| 
 | 
 | ||||||
| ## 开发目的 | ## 开发目的 | ||||||
| 
 | 
 | ||||||
|  | @ -9,7 +9,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 | ||||||
| 
 | 
 | ||||||
| ## 项目概览 | ## 项目概览 | ||||||
| 
 | 
 | ||||||
| - 有关项目设计、已知问题和变更日志,请通过 [使用手册](http://gogs.io/docs/intro/) 查看。 | - 有关基本用法和变更日志,请通过 [使用手册](http://gogs.io/docs/intro/) 查看。 | ||||||
| - 您可以到 [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) 跟随开发团队的脚步。 | - 您可以到 [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) 跟随开发团队的脚步。 | ||||||
| - 想要先睹为快?通过 [在线体验](https://try.gogs.io/gogs/gogs) 或查看 **安装部署 -> 二进制安装** 小节。 | - 想要先睹为快?通过 [在线体验](https://try.gogs.io/gogs/gogs) 或查看 **安装部署 -> 二进制安装** 小节。 | ||||||
| - 使用过程中遇到问题?尝试从 [故障排查](http://gogs.io/docs/intro/troubleshooting.html) 页面获取帮助。 | - 使用过程中遇到问题?尝试从 [故障排查](http://gogs.io/docs/intro/troubleshooting.html) 页面获取帮助。 | ||||||
|  | @ -30,7 +30,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 | ||||||
| - 支持邮件服务 | - 支持邮件服务 | ||||||
| - 支持后台管理面板 | - 支持后台管理面板 | ||||||
| - 支持 CI 集成:[Drone](https://github.com/drone/drone) | - 支持 CI 集成:[Drone](https://github.com/drone/drone) | ||||||
| - 支持 MySQL、PostgreSQL、SQLite3 和 [TiDB](https://github.com/pingcap/tidb) 数据库 | - 支持 MySQL、PostgreSQL、SQLite3 和 [TiDB](https://github.com/pingcap/tidb)(实验性支持) 数据库 | ||||||
| - 支持多语言本地化([14 种语言]([more](https://crowdin.com/project/gogs))) | - 支持多语言本地化([14 种语言]([more](https://crowdin.com/project/gogs))) | ||||||
| 
 | 
 | ||||||
| ## 系统要求 | ## 系统要求 | ||||||
|  |  | ||||||
							
								
								
									
										70
									
								
								cmd/serve.go
									
									
									
									
									
								
							
							
						
						
									
										70
									
								
								cmd/serve.go
									
									
									
									
									
								
							|  | @ -77,6 +77,43 @@ func fail(userMessage, logMessage string, args ...interface{}) { | ||||||
| 	log.GitLogger.Fatal(3, logMessage, args...) | 	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) { | func runServ(c *cli.Context) { | ||||||
| 	if c.IsSet("config") { | 	if c.IsSet("config") { | ||||||
| 		setting.CustomConf = c.String("config") | 		setting.CustomConf = c.String("config") | ||||||
|  | @ -162,7 +199,7 @@ func runServ(c *cli.Context) { | ||||||
| 				fail("Internal error", "UpdateDeployKey: %v", err) | 				fail("Internal error", "UpdateDeployKey: %v", err) | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			user, err = models.GetUserByKeyId(key.ID) | 			user, err = models.GetUserByKeyID(key.ID) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				fail("internal error", "Failed to get user by key ID(%d): %v", keyID, err) | 				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 { | 	if requestedMode == models.ACCESS_MODE_WRITE { | ||||||
| 		task, err := models.GetUpdateTaskByUUID(uuid) | 		handleUpdateTask(uuid, user, repoUserName, repoName) | ||||||
| 		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) |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Update user key activity.
 | 	// Update user key activity.
 | ||||||
|  |  | ||||||
|  | @ -42,10 +42,8 @@ func runUpdate(c *cli.Context) { | ||||||
| 		log.GitLogger.Fatal(2, "refName is empty, shouldn't use") | 		log.GitLogger.Fatal(2, "refName is empty, shouldn't use") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	uuid := os.Getenv("uuid") |  | ||||||
| 
 |  | ||||||
| 	task := models.UpdateTask{ | 	task := models.UpdateTask{ | ||||||
| 		UUID:        uuid, | 		UUID:        os.Getenv("uuid"), | ||||||
| 		RefName:     args[0], | 		RefName:     args[0], | ||||||
| 		OldCommitID: args[1], | 		OldCommitID: args[1], | ||||||
| 		NewCommitID: args[2], | 		NewCommitID: args[2], | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							|  | @ -17,7 +17,7 @@ import ( | ||||||
| 	"github.com/gogits/gogs/modules/setting" | 	"github.com/gogits/gogs/modules/setting" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const APP_VER = "0.6.25.1104 Beta" | const APP_VER = "0.6.26.1104 Beta" | ||||||
| 
 | 
 | ||||||
| func init() { | func init() { | ||||||
| 	runtime.GOMAXPROCS(runtime.NumCPU()) | 	runtime.GOMAXPROCS(runtime.NumCPU()) | ||||||
|  |  | ||||||
|  | @ -275,6 +275,19 @@ func (err ErrInvalidCloneAddr) Error() string { | ||||||
| 		err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied) | 		err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type ErrUpdateTaskNotExist struct { | ||||||
|  | 	UUID string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func IsErrUpdateTaskNotExist(err error) bool { | ||||||
|  | 	_, ok := err.(ErrUpdateTaskNotExist) | ||||||
|  | 	return ok | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (err ErrUpdateTaskNotExist) Error() string { | ||||||
|  | 	return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| //  __      __      ___.   .__                   __
 | //  __      __      ___.   .__                   __
 | ||||||
| // /  \    /  \ ____\_ |__ |  |__   ____   ____ |  | __
 | // /  \    /  \ ____\_ |__ |  |__   ____   ____ |  | __
 | ||||||
| // \   \/\/   // __ \| __ \|  |  \ /  _ \ /  _ \|  |/ /
 | // \   \/\/   // __ \| __ \|  |  \ /  _ \ /  _ \|  |/ /
 | ||||||
|  |  | ||||||
|  | @ -28,6 +28,7 @@ func AddUpdateTask(task *UpdateTask) error { | ||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // GetUpdateTaskByUUID returns update task by given UUID.
 | ||||||
| func GetUpdateTaskByUUID(uuid string) (*UpdateTask, error) { | func GetUpdateTaskByUUID(uuid string) (*UpdateTask, error) { | ||||||
| 	task := &UpdateTask{ | 	task := &UpdateTask{ | ||||||
| 		UUID: uuid, | 		UUID: uuid, | ||||||
|  | @ -36,7 +37,7 @@ func GetUpdateTaskByUUID(uuid string) (*UpdateTask, error) { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} else if !has { | 	} else if !has { | ||||||
| 		return nil, fmt.Errorf("task does not exist: %s", uuid) | 		return nil, ErrUpdateTaskNotExist{uuid} | ||||||
| 	} | 	} | ||||||
| 	return task, nil | 	return task, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -728,9 +728,9 @@ func UserPath(userName string) string { | ||||||
| 	return filepath.Join(setting.RepoRootPath, strings.ToLower(userName)) | 	return filepath.Join(setting.RepoRootPath, strings.ToLower(userName)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func GetUserByKeyId(keyId int64) (*User, error) { | func GetUserByKeyID(keyID int64) (*User, error) { | ||||||
| 	user := new(User) | 	user := new(User) | ||||||
| 	has, err := x.Sql("SELECT a.* FROM `user` AS a, public_key AS b WHERE a.id = b.owner_id AND b.id=?", keyId).Get(user) | 	has, err := x.Sql("SELECT a.* FROM `user` AS a, public_key AS b WHERE a.id = b.owner_id AND b.id=?", keyID).Get(user) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} else if !has { | 	} else if !has { | ||||||
|  |  | ||||||
|  | @ -130,7 +130,7 @@ func (ls *Source) SearchEntry(name, passwd string, directBind bool) (string, str | ||||||
| 
 | 
 | ||||||
| 	l, err := ldapDial(ls) | 	l, err := ldapDial(ls) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Error(4, "LDAP Connect error, %s:%v", ls.Host, err) | 		log.Error(4, "LDAP Connect error (%s): %v", ls.Host, err) | ||||||
| 		ls.Enabled = false | 		ls.Enabled = false | ||||||
| 		return "", "", "", false, false | 		return "", "", "", false, false | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -1 +1 @@ | ||||||
| 0.6.25.1104 Beta | 0.6.26.1104 Beta | ||||||
		Loading…
	
		Reference in a new issue