Skip to content

Commit b3af359

Browse files
GiteaBotcharles-plutohealth
and
charles-plutohealth
authored
Fix /repos/{owner}/{repo}/pulls/{index}/files endpoint not populating previous_filename (#32017) (#32028)
Backport #32017 by @charles-plutohealth --- `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. Co-authored-by: charles-plutohealth <[email protected]>
1 parent 0629c08 commit b3af359

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

services/convert/convert.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ func ToLFSLock(ctx context.Context, l *git_model.LFSLock) *api.LFSLock {
424424
// ToChangedFile convert a gitdiff.DiffFile to api.ChangedFile
425425
func ToChangedFile(f *gitdiff.DiffFile, repo *repo_model.Repository, commit string) *api.ChangedFile {
426426
status := "changed"
427+
previousFilename := ""
427428
if f.IsDeleted {
428429
status = "deleted"
429430
} else if f.IsCreated {
@@ -432,23 +433,21 @@ func ToChangedFile(f *gitdiff.DiffFile, repo *repo_model.Repository, commit stri
432433
status = "copied"
433434
} else if f.IsRenamed && f.Type == gitdiff.DiffFileRename {
434435
status = "renamed"
436+
previousFilename = f.OldName
435437
} else if f.Addition == 0 && f.Deletion == 0 {
436438
status = "unchanged"
437439
}
438440

439441
file := &api.ChangedFile{
440-
Filename: f.GetDiffFileName(),
441-
Status: status,
442-
Additions: f.Addition,
443-
Deletions: f.Deletion,
444-
Changes: f.Addition + f.Deletion,
445-
HTMLURL: fmt.Sprint(repo.HTMLURL(), "/src/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
446-
ContentsURL: fmt.Sprint(repo.APIURL(), "/contents/", util.PathEscapeSegments(f.GetDiffFileName()), "?ref=", commit),
447-
RawURL: fmt.Sprint(repo.HTMLURL(), "/raw/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
448-
}
449-
450-
if status == "rename" {
451-
file.PreviousFilename = f.OldName
442+
Filename: f.GetDiffFileName(),
443+
Status: status,
444+
Additions: f.Addition,
445+
Deletions: f.Deletion,
446+
Changes: f.Addition + f.Deletion,
447+
PreviousFilename: previousFilename,
448+
HTMLURL: fmt.Sprint(repo.HTMLURL(), "/src/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
449+
ContentsURL: fmt.Sprint(repo.APIURL(), "/contents/", util.PathEscapeSegments(f.GetDiffFileName()), "?ref=", commit),
450+
RawURL: fmt.Sprint(repo.HTMLURL(), "/raw/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
452451
}
453452

454453
return file

0 commit comments

Comments
 (0)