diff options
author | 6543 <6543@obermui.de> | 2020-09-18 14:09:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-18 20:09:26 +0800 |
commit | 1418288734b430330023e4e17747175e4fea2f41 (patch) | |
tree | 270f7bdbb6aee5f732a6d1295ce3d021d3e98874 /modules/convert/convert.go | |
parent | 5995326d51ab42014c6d77d3313233641c258318 (diff) | |
download | gitea-1418288734b430330023e4e17747175e4fea2f41.tar.gz gitea-1418288734b430330023e4e17747175e4fea2f41.zip |
Refactor: move Commit To APIFormat Code & Lot of StopWatch related things (#12729)
* move GitCommit to APIFormat convertion into convert package
* rename Commit convert functions
* move stopwatch to api convertion into convert package & rm unused code & extend test
* fix compare time
* Gitea not Gogs ;)
Diffstat (limited to 'modules/convert/convert.go')
-rw-r--r-- | modules/convert/convert.go | 59 |
1 files changed, 2 insertions, 57 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 03a84115a5..ec676002b9 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -7,7 +7,6 @@ package convert import ( "fmt" - "time" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" @@ -43,7 +42,7 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models. return &api.Branch{ Name: b.Name, - Commit: ToCommit(repo, c), + Commit: ToPayloadCommit(repo, c), Protected: false, RequiredApprovals: 0, EnableStatusCheck: false, @@ -55,7 +54,7 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models. branch := &api.Branch{ Name: b.Name, - Commit: ToCommit(repo, c), + Commit: ToPayloadCommit(repo, c), Protected: true, RequiredApprovals: bp.RequiredApprovals, EnableStatusCheck: bp.EnableStatusCheck, @@ -142,41 +141,6 @@ func ToTag(repo *models.Repository, t *git.Tag) *api.Tag { } } -// ToCommit convert a git.Commit to api.PayloadCommit -func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit { - authorUsername := "" - if author, err := models.GetUserByEmail(c.Author.Email); err == nil { - authorUsername = author.Name - } else if !models.IsErrUserNotExist(err) { - log.Error("GetUserByEmail: %v", err) - } - - committerUsername := "" - if committer, err := models.GetUserByEmail(c.Committer.Email); err == nil { - committerUsername = committer.Name - } else if !models.IsErrUserNotExist(err) { - log.Error("GetUserByEmail: %v", err) - } - - return &api.PayloadCommit{ - ID: c.ID.String(), - Message: c.Message(), - URL: util.URLJoin(repo.HTMLURL(), "commit", c.ID.String()), - Author: &api.PayloadUser{ - Name: c.Author.Name, - Email: c.Author.Email, - UserName: authorUsername, - }, - Committer: &api.PayloadUser{ - Name: c.Committer.Name, - Email: c.Committer.Email, - UserName: committerUsername, - }, - Timestamp: c.Author.When, - Verification: ToVerification(c), - } -} - // ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification func ToVerification(c *git.Commit) *api.PayloadCommitVerification { verif := models.ParseCommitWithSignature(c) @@ -353,25 +317,6 @@ func ToAnnotatedTagObject(repo *models.Repository, commit *git.Commit) *api.Anno } } -// ToCommitUser convert a git.Signature to an api.CommitUser -func ToCommitUser(sig *git.Signature) *api.CommitUser { - return &api.CommitUser{ - Identity: api.Identity{ - Name: sig.Name, - Email: sig.Email, - }, - Date: sig.When.UTC().Format(time.RFC3339), - } -} - -// ToCommitMeta convert a git.Tag to an api.CommitMeta -func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta { - return &api.CommitMeta{ - SHA: tag.Object.String(), - URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()), - } -} - // ToTopicResponse convert from models.Topic to api.TopicResponse func ToTopicResponse(topic *models.Topic) *api.TopicResponse { return &api.TopicResponse{ |