Просмотр исходного кода

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>
tags/v1.21.0-rc0
Laurent Cahour 10 месяцев назад
Родитель
Сommit
b21b63c61a
Аккаунт пользователя с таким Email не найден
22 измененных файлов: 38 добавлений и 1 удалений
  1. 1
    1
      modules/git/commit.go
  2. 23
    0
      modules/git/commit_test.go
  3. 1
    0
      modules/git/tests/repos/repo6_merge/HEAD
  4. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/02/2f4ce6214973e018f02bf363bf8a2e3691f699
  5. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/05/45879290cc368a8becebc4aa34002c52d5fecc
  6. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/1e/5d0a65fe099ef12d24b28f783896e4b8172576
  7. 2
    0
      modules/git/tests/repos/repo6_merge/objects/37/d35c7ed39e4e16d0b579a5b995b7e30b0e9411
  8. 2
    0
      modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f41439
  9. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/66/7e0fbc6bc02c2285d17f542e89b23c0fa5482b
  10. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/9f/d90b1d524c0fea776ed5e6476da02ea1740597
  11. 5
    0
      modules/git/tests/repos/repo6_merge/objects/ae/4b035e7c4afbc000576cee3f713ea0c2f1e1e2
  12. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a
  13. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/c1/a95c2eff8151c6d1437a0d5d3322a73ff38fb8
  14. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/cc/d1d4d594029e68c388ecef5aa3063fa1055831
  15. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/cd/fc1aaf7a149151cb7bff639fafe05668d4bbd2
  16. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/d1/792641396ff7630d35fbb0b74b86b0c71bca77
  17. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/ec/d11d8da0f25eaa99f64a37a82da98685f381e2
  18. Двоичные данные
      modules/git/tests/repos/repo6_merge/objects/fa/49b077972391ad58037050f2a75f74e3671e92
  19. 1
    0
      modules/git/tests/repos/repo6_merge/refs/heads/main
  20. 1
    0
      modules/git/tests/repos/repo6_merge/refs/heads/merge/add_file
  21. 1
    0
      modules/git/tests/repos/repo6_merge/refs/heads/merge/modify_file
  22. 1
    0
      modules/git/tests/repos/repo6_merge/refs/heads/merge/remove_file

+ 1
- 1
modules/git/commit.go Просмотреть файл

@@ -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,

+ 23
- 0
modules/git/commit_test.go Просмотреть файл

@@ -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)
}

+ 1
- 0
modules/git/tests/repos/repo6_merge/HEAD Просмотреть файл

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

Двоичные данные
modules/git/tests/repos/repo6_merge/objects/02/2f4ce6214973e018f02bf363bf8a2e3691f699 Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/05/45879290cc368a8becebc4aa34002c52d5fecc Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/1e/5d0a65fe099ef12d24b28f783896e4b8172576 Просмотреть файл


+ 2
- 0
modules/git/tests/repos/repo6_merge/objects/37/d35c7ed39e4e16d0b579a5b995b7e30b0e9411 Просмотреть файл

@@ -0,0 +1,2 @@
x�ÍM
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Ã

+ 2
- 0
modules/git/tests/repos/repo6_merge/objects/38/ec3e0cdc88bde01014bda4a5dd9fc835f41439 Просмотреть файл

@@ -0,0 +1,2 @@
x█нM
б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┤ЫЪа>╝

Двоичные данные
modules/git/tests/repos/repo6_merge/objects/66/7e0fbc6bc02c2285d17f542e89b23c0fa5482b Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/9f/d90b1d524c0fea776ed5e6476da02ea1740597 Просмотреть файл


+ 5
- 0
modules/git/tests/repos/repo6_merge/objects/ae/4b035e7c4afbc000576cee3f713ea0c2f1e1e2 Просмотреть файл

@@ -0,0 +1,5 @@
xŤÎM
1 @a×=Eö‚¤?iń*mšÁÇ‘™xOŕćŰ=x˛.Ëlŕ™O¶©R˘Z80ŠÄ\[í*Ú%µb
�&qď¶éË –IŠŽČšÔç�ť
7ęĚÔ‹F쨜ĽwícŹuÓÝŕzx?¸ÜŔçš0ç
ś1 :ům™ţ¸6LóSÝŔí>&

Двоичные данные
modules/git/tests/repos/repo6_merge/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/c1/a95c2eff8151c6d1437a0d5d3322a73ff38fb8 Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/cc/d1d4d594029e68c388ecef5aa3063fa1055831 Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/cd/fc1aaf7a149151cb7bff639fafe05668d4bbd2 Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/d1/792641396ff7630d35fbb0b74b86b0c71bca77 Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/ec/d11d8da0f25eaa99f64a37a82da98685f381e2 Просмотреть файл


Двоичные данные
modules/git/tests/repos/repo6_merge/objects/fa/49b077972391ad58037050f2a75f74e3671e92 Просмотреть файл


+ 1
- 0
modules/git/tests/repos/repo6_merge/refs/heads/main Просмотреть файл

@@ -0,0 +1 @@
022f4ce6214973e018f02bf363bf8a2e3691f699

+ 1
- 0
modules/git/tests/repos/repo6_merge/refs/heads/merge/add_file Просмотреть файл

@@ -0,0 +1 @@
ae4b035e7c4afbc000576cee3f713ea0c2f1e1e2

+ 1
- 0
modules/git/tests/repos/repo6_merge/refs/heads/merge/modify_file Просмотреть файл

@@ -0,0 +1 @@
d1792641396ff7630d35fbb0b74b86b0c71bca77

+ 1
- 0
modules/git/tests/repos/repo6_merge/refs/heads/merge/remove_file Просмотреть файл

@@ -0,0 +1 @@
38ec3e0cdc88bde01014bda4a5dd9fc835f41439

Загрузка…
Отмена
Сохранить