Skip to content

Commit b21b63c

Browse files
jasuguntdesveaux
andauthored
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>
1 parent 86ee5b4 commit b21b63c

22 files changed

+38
-1
lines changed

modules/git/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
495495
}()
496496

497497
stderr := new(bytes.Buffer)
498-
err := NewCommand(ctx, "log", "--name-status", "-c", "--pretty=format:", "--parents", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
498+
err := NewCommand(ctx, "log", "--name-status", "-m", "--pretty=format:", "--first-parent", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(&RunOpts{
499499
Dir: repoPath,
500500
Stdout: w,
501501
Stderr: stderr,

modules/git/commit_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,26 @@ func TestParseCommitFileStatus(t *testing.T) {
255255
assert.Equal(t, kase.modified, fileStatus.Modified)
256256
}
257257
}
258+
259+
func TestGetCommitFileStatusMerges(t *testing.T) {
260+
bareRepo1Path := filepath.Join(testReposDir, "repo6_merge")
261+
262+
commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "022f4ce6214973e018f02bf363bf8a2e3691f699")
263+
assert.NoError(t, err)
264+
265+
expected := CommitFileStatus{
266+
[]string{
267+
"add_file.txt",
268+
},
269+
[]string{
270+
"to_remove.txt",
271+
},
272+
[]string{
273+
"to_modify.txt",
274+
},
275+
}
276+
277+
assert.Equal(t, commitFileStatus.Added, expected.Added)
278+
assert.Equal(t, commitFileStatus.Removed, expected.Removed)
279+
assert.Equal(t, commitFileStatus.Modified, expected.Modified)
280+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��M
2+
1 �a�=E��$��LAī�'���i��R���g�~_��u1��N��@mZ)g�2�D�j��*_�f��s �4��a�m�np>�����>!��#���1�;p]�x��uyIw�N4�

modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f41439

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��M
2+
�0�a�9����M2 �U�� ��=���yv/��� ��0:@��$��UѬ�.�[�>� �l��I�s�x ��8'T��R�ĤS,��$x. ֚�=n[��נ��u�s!+9���BGv�f�m���u���r����>�
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
x��M
2+
1 @a�=E���?i�*m��Ǒ�xO���=x�.�l��O��R�Z80��\[�*�%�b
3+
�&q��� �I��Ț�灝
4+
7��ԋF쨜�w�c�u���zx?����0�
5+
�1 :�m���6L�S���>&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
022f4ce6214973e018f02bf363bf8a2e3691f699
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ae4b035e7c4afbc000576cee3f713ea0c2f1e1e2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d1792641396ff7630d35fbb0b74b86b0c71bca77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
38ec3e0cdc88bde01014bda4a5dd9fc835f41439

0 commit comments

Comments
 (0)