mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	add update
This commit is contained in:
		
							
								
								
									
										1
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								gogs.go
									
									
									
									
									
								
							| @@ -49,6 +49,7 @@ func main() { | |||||||
| 	app.Commands = []cli.Command{ | 	app.Commands = []cli.Command{ | ||||||
| 		CmdWeb, | 		CmdWeb, | ||||||
| 		CmdServ, | 		CmdServ, | ||||||
|  | 		CmdUpdate, | ||||||
| 	} | 	} | ||||||
| 	app.Flags = append(app.Flags, []cli.Flag{ | 	app.Flags = append(app.Flags, []cli.Flag{ | ||||||
| 		cli.BoolFlag{"noterm", "disable color output"}, | 		cli.BoolFlag{"noterm", "disable color output"}, | ||||||
|   | |||||||
| @@ -43,7 +43,22 @@ func (a Action) GetRepoName() string { | |||||||
| 	return a.RepoName | 	return a.RepoName | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func CommitRepoAction(userId int64, userName string, | ||||||
|  | 	repoId int64, repoName string, msg string) error { | ||||||
|  | 	_, err := orm.InsertOne(&Action{ | ||||||
|  | 		UserId:      userId, | ||||||
|  | 		ActUserId:   userId, | ||||||
|  | 		ActUserName: userName, | ||||||
|  | 		OpType:      OP_COMMIT_REPO, | ||||||
|  | 		Content:     msg, | ||||||
|  | 		RepoId:      repoId, | ||||||
|  | 		RepoName:    repoName, | ||||||
|  | 	}) | ||||||
|  | 	return err | ||||||
|  | } | ||||||
|  |  | ||||||
| // NewRepoAction inserts action for create repository. | // NewRepoAction inserts action for create repository. | ||||||
|  |  | ||||||
| func NewRepoAction(user *User, repo *Repository) error { | func NewRepoAction(user *User, repo *Repository) error { | ||||||
| 	_, err := orm.InsertOne(&Action{ | 	_, err := orm.InsertOne(&Action{ | ||||||
| 		UserId:      user.Id, | 		UserId:      user.Id, | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								serve.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								serve.go
									
									
									
									
									
								
							| @@ -73,6 +73,17 @@ func runServ(*cli.Context) { | |||||||
| 	if strings.HasSuffix(repoName, ".git") { | 	if strings.HasSuffix(repoName, ".git") { | ||||||
| 		repoName = repoName[:len(repoName)-4] | 		repoName = repoName[:len(repoName)-4] | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	os.Setenv("userName", user.Name) | ||||||
|  | 	os.Setenv("userId", strconv.Itoa(int(user.Id))) | ||||||
|  | 	repo, err := models.GetRepositoryByName(user, repoName) | ||||||
|  | 	if err != nil { | ||||||
|  | 		println("Unavilable repository", err) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	os.Setenv("repoId", strconv.Itoa(int(repo.Id))) | ||||||
|  | 	os.Setenv("repoName", repoName) | ||||||
|  |  | ||||||
| 	isWrite := In(verb, COMMANDS_WRITE) | 	isWrite := In(verb, COMMANDS_WRITE) | ||||||
| 	isRead := In(verb, COMMANDS_READONLY) | 	isRead := In(verb, COMMANDS_READONLY) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										51
									
								
								update.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								update.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | |||||||
|  | package main | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"os" | ||||||
|  | 	"strconv" | ||||||
|  |  | ||||||
|  | 	"github.com/gogits/gogs/models" | ||||||
|  |  | ||||||
|  | 	"github.com/codegangsta/cli" | ||||||
|  | 	git "github.com/gogits/git" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | var CmdUpdate = cli.Command{ | ||||||
|  | 	Name:  "update", | ||||||
|  | 	Usage: "This command just should be called by ssh shell", | ||||||
|  | 	Description: ` | ||||||
|  | gogs serv provide access auth for repositories`, | ||||||
|  | 	Action: runUpdate, | ||||||
|  | 	Flags:  []cli.Flag{}, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func runUpdate(*cli.Context) { | ||||||
|  | 	userName := os.Getenv("userName") | ||||||
|  | 	userId := os.Getenv("userId") | ||||||
|  | 	repoId := os.Getenv("repoId") | ||||||
|  | 	repoName := os.Getenv("repoName") | ||||||
|  |  | ||||||
|  | 	f := models.RepoPath(userName, repoName) | ||||||
|  |  | ||||||
|  | 	repo, err := git.OpenRepository(f) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	ref, err := repo.LookupReference("HEAD") | ||||||
|  | 	if err != nil { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	lastCommit, err := repo.LookupCommit(ref.Oid) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	sUserId, _ := strconv.Atoi(userId) | ||||||
|  | 	sRepoId, _ := strconv.Atoi(repoId) | ||||||
|  | 	err = models.CommitRepoAction(int64(sUserId), userName, | ||||||
|  | 		int64(sRepoId), repoName, lastCommit.Message()) | ||||||
|  | 	if err != nil { | ||||||
|  | 		//TODO: log | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 Lunny Xiao
					Lunny Xiao