routers/api/v1/repo /pull.go: GetPullRequestCommits: empty Files list #11801

Closed
opened 2025-11-02 09:48:14 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @msantos on GitHub (Oct 6, 2023).

Description

The gitea API now returns an empty file list for commits:

https://try.gitea.io/api/v1/repos/msantos/test/pulls/1/commits

[
  {
    "url": "https://try.gitea.io/api/v1/repos/msantos/test/git/commits/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f",
    "sha": "3a17cc9a6227c8c859851398ccc5a189f2bfdd6f",
    "created": "2023-08-02T17:43:35-04:00",
    "html_url": "https://try.gitea.io/msantos/test/commit/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f",
    "commit": ...,
    "author": ...,
    "committer": ...,
    "parents": [
      {
        "url": "https://try.gitea.io/api/v1/repos/msantos/test/git/commits/02f1e87c51f94fcaa3d3af904abd9ddc848b030e",
        "sha": "02f1e87c51f94fcaa3d3af904abd9ddc848b030e",
        "created": "0001-01-01T00:00:00Z"
      }
    ],
    "files": null,
    "stats": {
      "total": 2,
      "additions": 2,
      "deletions": 0
    }
  },
...
]

The file list is available using the files endpoint:

https://try.gitea.io/api/v1/repos/msantos/test/pulls/1/files

[
  {
    "filename": "README.md",
    "status": "changed",
    "additions": 3,
    "deletions": 0,
    "changes": 3,
    "html_url": "https://try.gitea.io/msantos/test/src/commit/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f/README.md",
    "contents_url": "https://try.gitea.io/api/v1/repos/msantos/test/contents/README.md?ref=3a17cc9a6227c8c859851398ccc5a189f2bfdd6f",
    "raw_url": "https://try.gitea.io/msantos/test/raw/commit/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f/README.md"
  }
]

Untested patch:

diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 586f3385b..3bd2703e2 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -1330,7 +1330,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {

        apiCommits := make([]*api.Commit, 0, end-start)
        for i := start; i < end; i++ {
-               apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true})
+               apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true, Files: true})
                if err != nil {
                        ctx.ServerError("toCommit", err)
                        return

Gitea Version

1.20.5

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

  • Github download
  • systemd

Database

SQLite

Originally created by @msantos on GitHub (Oct 6, 2023). ### Description The gitea API now returns an empty file list for commits: https://try.gitea.io/api/v1/repos/msantos/test/pulls/1/commits ```json [ { "url": "https://try.gitea.io/api/v1/repos/msantos/test/git/commits/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f", "sha": "3a17cc9a6227c8c859851398ccc5a189f2bfdd6f", "created": "2023-08-02T17:43:35-04:00", "html_url": "https://try.gitea.io/msantos/test/commit/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f", "commit": ..., "author": ..., "committer": ..., "parents": [ { "url": "https://try.gitea.io/api/v1/repos/msantos/test/git/commits/02f1e87c51f94fcaa3d3af904abd9ddc848b030e", "sha": "02f1e87c51f94fcaa3d3af904abd9ddc848b030e", "created": "0001-01-01T00:00:00Z" } ], "files": null, "stats": { "total": 2, "additions": 2, "deletions": 0 } }, ... ] ``` The file list is available using the files endpoint: https://try.gitea.io/api/v1/repos/msantos/test/pulls/1/files ```json [ { "filename": "README.md", "status": "changed", "additions": 3, "deletions": 0, "changes": 3, "html_url": "https://try.gitea.io/msantos/test/src/commit/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f/README.md", "contents_url": "https://try.gitea.io/api/v1/repos/msantos/test/contents/README.md?ref=3a17cc9a6227c8c859851398ccc5a189f2bfdd6f", "raw_url": "https://try.gitea.io/msantos/test/raw/commit/3a17cc9a6227c8c859851398ccc5a189f2bfdd6f/README.md" } ] ``` Untested patch: ```diff diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 586f3385b..3bd2703e2 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1330,7 +1330,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { apiCommits := make([]*api.Commit, 0, end-start) for i := start; i < end; i++ { - apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true}) + apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true, Files: true}) if err != nil { ctx.ServerError("toCommit", err) return ``` ### Gitea Version 1.20.5 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? * Github download * systemd ### Database SQLite
GiteaMirror added the type/bug label 2025-11-02 09:48:14 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#11801