diff options
author | charles-plutohealth <143208583+charles-plutohealth@users.noreply.github.com> | 2024-09-11 13:29:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-12 01:29:27 +0800 |
commit | 7c6edf1ba06d4c3269eaa78f4039c9123b006c51 (patch) | |
tree | 75e7b20228aefe6f7fc1d65fcb5f4d4de555a544 | |
parent | 125679f2e14cdc8a26a147f7e8fd0e5f174fb5cb (diff) | |
download | gitea-7c6edf1ba06d4c3269eaa78f4039c9123b006c51.tar.gz gitea-7c6edf1ba06d4c3269eaa78f4039c9123b006c51.zip |
Fix `/repos/{owner}/{repo}/pulls/{index}/files` endpoint not populating `previous_filename` (#32017)
---
`status == "rename"` should have read `status == "renamed"`. The typo
means that file.PreviousFilename would never be populated, which e.g.
breaks usage of the Github Action at
https://github.com/dorny/paths-filter.
-rw-r--r-- | services/convert/convert.go | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/services/convert/convert.go b/services/convert/convert.go index d70c1b940a..041d553e98 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -485,6 +485,7 @@ func ToLFSLock(ctx context.Context, l *git_model.LFSLock) *api.LFSLock { // ToChangedFile convert a gitdiff.DiffFile to api.ChangedFile func ToChangedFile(f *gitdiff.DiffFile, repo *repo_model.Repository, commit string) *api.ChangedFile { status := "changed" + previousFilename := "" if f.IsDeleted { status = "deleted" } else if f.IsCreated { @@ -493,23 +494,21 @@ func ToChangedFile(f *gitdiff.DiffFile, repo *repo_model.Repository, commit stri status = "copied" } else if f.IsRenamed && f.Type == gitdiff.DiffFileRename { status = "renamed" + previousFilename = f.OldName } else if f.Addition == 0 && f.Deletion == 0 { status = "unchanged" } file := &api.ChangedFile{ - Filename: f.GetDiffFileName(), - Status: status, - Additions: f.Addition, - Deletions: f.Deletion, - Changes: f.Addition + f.Deletion, - HTMLURL: fmt.Sprint(repo.HTMLURL(), "/src/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())), - ContentsURL: fmt.Sprint(repo.APIURL(), "/contents/", util.PathEscapeSegments(f.GetDiffFileName()), "?ref=", commit), - RawURL: fmt.Sprint(repo.HTMLURL(), "/raw/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())), - } - - if status == "rename" { - file.PreviousFilename = f.OldName + Filename: f.GetDiffFileName(), + Status: status, + Additions: f.Addition, + Deletions: f.Deletion, + Changes: f.Addition + f.Deletion, + PreviousFilename: previousFilename, + HTMLURL: fmt.Sprint(repo.HTMLURL(), "/src/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())), + ContentsURL: fmt.Sprint(repo.APIURL(), "/contents/", util.PathEscapeSegments(f.GetDiffFileName()), "?ref=", commit), + RawURL: fmt.Sprint(repo.HTMLURL(), "/raw/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())), } return file |