mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Move commits signature and verify functions to service layers (#33605)
No logic change, just move functions.
This commit is contained in:
		| @@ -12,7 +12,10 @@ import ( | ||||
| 	access_model "code.gitea.io/gitea/models/perm/access" | ||||
| 	repo_model "code.gitea.io/gitea/models/repo" | ||||
| 	user_model "code.gitea.io/gitea/models/user" | ||||
| 	"code.gitea.io/gitea/modules/gitrepo" | ||||
| 	"code.gitea.io/gitea/modules/json" | ||||
| 	"code.gitea.io/gitea/modules/timeutil" | ||||
| 	git_service "code.gitea.io/gitea/services/git" | ||||
| 	notify_service "code.gitea.io/gitea/services/notify" | ||||
| ) | ||||
|  | ||||
| @@ -139,3 +142,40 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // LoadCommentPushCommits Load push commits | ||||
| func LoadCommentPushCommits(ctx context.Context, c *issues_model.Comment) (err error) { | ||||
| 	if c.Content == "" || c.Commits != nil || c.Type != issues_model.CommentTypePullRequestPush { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	var data issues_model.PushActionContent | ||||
| 	err = json.Unmarshal([]byte(c.Content), &data) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	c.IsForcePush = data.IsForcePush | ||||
|  | ||||
| 	if c.IsForcePush { | ||||
| 		if len(data.CommitIDs) != 2 { | ||||
| 			return nil | ||||
| 		} | ||||
| 		c.OldCommit = data.CommitIDs[0] | ||||
| 		c.NewCommit = data.CommitIDs[1] | ||||
| 	} else { | ||||
| 		gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, c.Issue.Repo) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		defer closer.Close() | ||||
|  | ||||
| 		c.Commits, err = git_service.ConvertFromGitCommit(ctx, gitRepo.GetCommitsFromIDs(data.CommitIDs), c.Issue.Repo) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		c.CommitsNum = int64(len(c.Commits)) | ||||
| 	} | ||||
|  | ||||
| 	return err | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user