Skip to content

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

Closed
@msantos

Description

@msantos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions