Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
msantos opened this issue Oct 6, 2023 · 0 comments · Fixed by #27483
Closed

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

msantos opened this issue Oct 6, 2023 · 0 comments · Fixed by #27483
Labels

Comments

@msantos
Copy link
Contributor

msantos commented 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

msantos added a commit to msantos/gitea that referenced this issue Oct 6, 2023
wxiaoguang added a commit that referenced this issue Oct 9, 2023
Fixes #27481

----

Co-authored-by: silverwind <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Oct 9, 2023
silverwind added a commit that referenced this issue Oct 9, 2023
Backport #27483 by @msantos

Fixes #27481

---
Patch tested:

```json
[
  {
    "url": "http://100.115.92.198:9292/api/v1/repos/msantos/test/git/commits/7664dcb44167e0f9efd994e4ca6a9164694adc27",
    "sha": "7664dcb44167e0f9efd994e4ca6a9164694adc27",
    "created": "2023-10-06T09:57:08-04:00",
    "html_url": "http://100.115.92.198:9292/msantos/test/commit/7664dcb44167e0f9efd994e4ca6a9164694adc27",
...
    "files": [
      {
        "filename": "README.md",
        "status": "modified"
      }
    ],
    "stats": {
      "total": 2,
      "additions": 2,
      "deletions": 0
    }
  }
]
```

Co-authored-by: Michael Santos <[email protected]>
Co-authored-by: silverwind <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant