1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-03 09:07:19 +00:00

Add merge files files to GetCommitFileStatus (#20515)

Hi,

We'd like to add merge files files to GetCommitFileStatus fucntions so
API returns the list of all the files associated to a merged pull
request commit, like GitHub API does.
The list of affectedFiles for an API commit is fetched from toCommit()
function in routers/api/v1/repo/commits.go, and API was returning no
file in case of a pull request with no conflict, or just files
associated to the confict resolution, but NOT the full list of merged
files.

This would lead to situations where a CI polling a repo for changes
could miss some file changes due to API returning an empty / partial
list in case of such merged pull requests. (Hope this makes sense :) )

NOTE: I'd like to add a unittest in
integrations/api_repo_git_commits_test.go but failed to understand how
to add my own test bare repo so I can make a test on a merged pull
request commit to check for affectedFiles.
Is there a merged pull request in there that I could use maybe?
Could someone please direct me to the relevant ressources with
informations on how to do that please?

Thanks for your time,
Laurent.

---------

Co-authored-by: Thomas Desveaux <desveaux.thomas@gmail.com>
This commit is contained in:
Laurent Cahour
2023-08-24 12:03:49 +02:00
committed by GitHub
parent 86ee5b4b1b
commit b21b63c61a
22 changed files with 38 additions and 1 deletions

View File

@ -495,7 +495,7 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
}()
stderr := new(bytes.Buffer)
err := NewCommand(ctx, "log", "--name-status", "-c", "--pretty=format:", "--parents", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
err := NewCommand(ctx, "log", "--name-status", "-m", "--pretty=format:", "--first-parent", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
Dir: repoPath,
Stdout: w,
Stderr: stderr,

View File

@ -255,3 +255,26 @@ func TestParseCommitFileStatus(t *testing.T) {
assert.Equal(t, kase.modified, fileStatus.Modified)
}
}
func TestGetCommitFileStatusMerges(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo6_merge")
commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "022f4ce6214973e018f02bf363bf8a2e3691f699")
assert.NoError(t, err)
expected := CommitFileStatus{
[]string{
"add_file.txt",
},
[]string{
"to_remove.txt",
},
[]string{
"to_modify.txt",
},
}
assert.Equal(t, commitFileStatus.Added, expected.Added)
assert.Equal(t, commitFileStatus.Removed, expected.Removed)
assert.Equal(t, commitFileStatus.Modified, expected.Modified)
}

View File

@ -0,0 +1 @@
ref: refs/heads/main

View File

@ -0,0 +1,2 @@
x<01><>M
1 <0C>a<EFBFBD>=E<><45>$<24><>LAī<41>'<27><01><>i<EFBFBD><69>R<EFBFBD><52><EFBFBD>g<EFBFBD>~_<><5F>u1<75><31>N<EFBFBD><4E>@mZ)g<>2<EFBFBD>D<EFBFBD>j<EFBFBD><6A>*_<>f<15><>s <0B>4<EFBFBD><34>a<EFBFBD>m<07>np><06><><1D><><EFBFBD><EFBFBD>>!<21><>#<23><><EFBFBD>1<EFBFBD>;p]<5D>x<EFBFBD><78>uyIw<1F>N4<4E>

View File

@ -0,0 +1,2 @@
x<01><>M
<EFBFBD>0<10>a<EFBFBD>9<EFBFBD><39><05><>M2 <20>U<EFBFBD><55> <16><>=<3D><><13>yv/<2F><><EFBFBD><EFBFBD><EFBFBD> <20><>0:@<16><>$<24><><55>.<14>[<5B>><3E> <20>l<EFBFBD><6C>I<EFBFBD>s<EFBFBD>x <0C><><EFBFBD>8'T<><08>R<EFBFBD>ĤS,<2C><>$x.

View File

@ -0,0 +1,5 @@
x<01><>M
1 @a<>=E<><45><EFBFBD>?i<10>*m<><6D>Ǒ<>xO<><4F><EFBFBD>=x<>.<2E>l<EFBFBD><6C>O<EFBFBD><4F>R<>Z80<38><30>\[<5B>*<2A>%<25>b
<EFBFBD>&q<><71><EFBFBD><EFBFBD> <20>I<><49>Ț<EFBFBD>
7<EFBFBD><EFBFBD>ԋF쨜<EFBFBD>w<EFBFBD>c<EFBFBD>u<03><><EFBFBD>zx?<3F><1C><><EFBFBD><EFBFBD>0<EFBFBD>
<EFBFBD>1 :<3A>m<EFBFBD><6D><1D>6L<>S<EFBFBD><17><>>&

View File

@ -0,0 +1 @@
022f4ce6214973e018f02bf363bf8a2e3691f699

View File

@ -0,0 +1 @@
ae4b035e7c4afbc000576cee3f713ea0c2f1e1e2

View File

@ -0,0 +1 @@
d1792641396ff7630d35fbb0b74b86b0c71bca77

View File

@ -0,0 +1 @@
38ec3e0cdc88bde01014bda4a5dd9fc835f41439