Skip to content

Commit 7c6edf1

Browse files
author
charles-plutohealth
authored
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.
1 parent 125679f commit 7c6edf1

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
@@ -485,6 +485,7 @@ func ToLFSLock(ctx context.Context, l *git_model.LFSLock) *api.LFSLock {
485485
// ToChangedFile convert a gitdiff.DiffFile to api.ChangedFile
486486
func ToChangedFile(f *gitdiff.DiffFile, repo *repo_model.Repository, commit string) *api.ChangedFile {
487487
status := "changed"
488+
previousFilename := ""
488489
if f.IsDeleted {
489490
status = "deleted"
490491
} else if f.IsCreated {
@@ -493,23 +494,21 @@ func ToChangedFile(f *gitdiff.DiffFile, repo *repo_model.Repository, commit stri
493494
status = "copied"
494495
} else if f.IsRenamed && f.Type == gitdiff.DiffFileRename {
495496
status = "renamed"
497+
previousFilename = f.OldName
496498
} else if f.Addition == 0 && f.Deletion == 0 {
497499
status = "unchanged"
498500
}
499501

500502
file := &api.ChangedFile{
501-
Filename: f.GetDiffFileName(),
502-
Status: status,
503-
Additions: f.Addition,
504-
Deletions: f.Deletion,
505-
Changes: f.Addition + f.Deletion,
506-
HTMLURL: fmt.Sprint(repo.HTMLURL(), "/src/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
507-
ContentsURL: fmt.Sprint(repo.APIURL(), "/contents/", util.PathEscapeSegments(f.GetDiffFileName()), "?ref=", commit),
508-
RawURL: fmt.Sprint(repo.HTMLURL(), "/raw/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
509-
}
510-
511-
if status == "rename" {
512-
file.PreviousFilename = f.OldName
503+
Filename: f.GetDiffFileName(),
504+
Status: status,
505+
Additions: f.Addition,
506+
Deletions: f.Deletion,
507+
Changes: f.Addition + f.Deletion,
508+
PreviousFilename: previousFilename,
509+
HTMLURL: fmt.Sprint(repo.HTMLURL(), "/src/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
510+
ContentsURL: fmt.Sprint(repo.APIURL(), "/contents/", util.PathEscapeSegments(f.GetDiffFileName()), "?ref=", commit),
511+
RawURL: fmt.Sprint(repo.HTMLURL(), "/raw/commit/", commit, "/", util.PathEscapeSegments(f.GetDiffFileName())),
513512
}
514513

515514
return file

0 commit comments

Comments
 (0)