]> source.dussan.org Git - gitea.git/commitdiff
More commit info from API (#19252)
authorJohn Olheiser <john.olheiser@gmail.com>
Tue, 29 Mar 2022 15:47:44 +0000 (10:47 -0500)
committerGitHub <noreply@github.com>
Tue, 29 Mar 2022 15:47:44 +0000 (10:47 -0500)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
modules/convert/git_commit.go
modules/structs/repo_commit.go
templates/swagger/v1_json.tmpl

index a5c3112f13358fd58d6047e49ded98a32c131740..dfd6cb080ca35991c932071b0c5d7719cc25c6be 100644 (file)
@@ -14,6 +14,7 @@ import (
        "code.gitea.io/gitea/modules/log"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/util"
+       "code.gitea.io/gitea/services/gitdiff"
 )
 
 // ToCommitUser convert a git.Signature to an api.CommitUser
@@ -146,6 +147,13 @@ func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.
                }
        }
 
+       diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{
+               AfterCommitID: commit.ID.String(),
+       })
+       if err != nil {
+               return nil, err
+       }
+
        return &api.Commit{
                CommitMeta: &api.CommitMeta{
                        URL:     repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
@@ -175,10 +183,16 @@ func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.
                                SHA:     commit.ID.String(),
                                Created: commit.Committer.When,
                        },
+                       Verification: ToVerification(commit),
                },
                Author:    apiAuthor,
                Committer: apiCommitter,
                Parents:   apiParents,
                Files:     affectedFileList,
+               Stats: &api.CommitStats{
+                       Total:     diff.TotalAddition + diff.TotalDeletion,
+                       Additions: diff.TotalAddition,
+                       Deletions: diff.TotalDeletion,
+               },
        }, nil
 }
index f5c5f1b9401818b369c56f99a753dbcb17727792..55a516a975adb1cfc116766f821b6f202728aa9a 100644 (file)
@@ -32,11 +32,19 @@ type CommitUser struct {
 
 // RepoCommit contains information of a commit in the context of a repository.
 type RepoCommit struct {
-       URL       string      `json:"url"`
-       Author    *CommitUser `json:"author"`
-       Committer *CommitUser `json:"committer"`
-       Message   string      `json:"message"`
-       Tree      *CommitMeta `json:"tree"`
+       URL          string                     `json:"url"`
+       Author       *CommitUser                `json:"author"`
+       Committer    *CommitUser                `json:"committer"`
+       Message      string                     `json:"message"`
+       Tree         *CommitMeta                `json:"tree"`
+       Verification *PayloadCommitVerification `json:"verification"`
+}
+
+// CommitStats is statistics for a RepoCommit
+type CommitStats struct {
+       Total     int `json:"total"`
+       Additions int `json:"additions"`
+       Deletions int `json:"deletions"`
 }
 
 // Commit contains information generated from a Git commit.
@@ -48,6 +56,7 @@ type Commit struct {
        Committer  *User                  `json:"committer"`
        Parents    []*CommitMeta          `json:"parents"`
        Files      []*CommitAffectedFiles `json:"files"`
+       Stats      *CommitStats           `json:"stats"`
 }
 
 // CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
index 284e1c71a0cf4561990515fb011b08c00bfb287c..16e3a348567751e4928c750837020fadb97bd10b 100644 (file)
           "type": "string",
           "x-go-name": "SHA"
         },
+        "stats": {
+          "$ref": "#/definitions/CommitStats"
+        },
         "url": {
           "type": "string",
           "x-go-name": "URL"
       },
       "x-go-package": "code.gitea.io/gitea/modules/structs"
     },
+    "CommitStats": {
+      "description": "CommitStats is statistics for a RepoCommit",
+      "type": "object",
+      "properties": {
+        "additions": {
+          "type": "integer",
+          "format": "int64",
+          "x-go-name": "Additions"
+        },
+        "deletions": {
+          "type": "integer",
+          "format": "int64",
+          "x-go-name": "Deletions"
+        },
+        "total": {
+          "type": "integer",
+          "format": "int64",
+          "x-go-name": "Total"
+        }
+      },
+      "x-go-package": "code.gitea.io/gitea/modules/structs"
+    },
     "CommitStatus": {
       "description": "CommitStatus holds a single status of a single Commit",
       "type": "object",
         "url": {
           "type": "string",
           "x-go-name": "URL"
+        },
+        "verification": {
+          "$ref": "#/definitions/PayloadCommitVerification"
         }
       },
       "x-go-package": "code.gitea.io/gitea/modules/structs"