Skip to content

Commit 41cf654

Browse files
authored
Merge pull request #349 from adivishy1/master
feat: [PIPE-31833]: Added code to return the list of files for FindCommit api for github
2 parents 5750961 + b5b2c7c commit 41cf654

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

scm/driver/github/git.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,25 @@ func convertCommit(from *commit) *scm.Commit {
164164
Login: from.Committer.Login,
165165
Avatar: from.Committer.AvatarURL,
166166
},
167+
Files: convertFileList(from.Files),
167168
}
168169
}
169170

171+
func convertFileList(from []*file) []scm.Files {
172+
to := []scm.Files{}
173+
for _, v := range from {
174+
if v == nil {
175+
continue
176+
}
177+
to = append(to, scm.Files{
178+
Sha: v.BlobID,
179+
FileName: v.Filename,
180+
Status: v.Status,
181+
})
182+
}
183+
return to
184+
}
185+
170186
func convertBranchList(from []*branch) []*scm.Reference {
171187
to := []*scm.Reference{}
172188
for _, v := range from {

scm/driver/github/testdata/commit.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@
9595
"raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
9696
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e",
9797
"patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
98+
},
99+
{
100+
"sha": "aaqq538c8e72b8c175046e27cc8f907076312345",
101+
"filename": "file2.yaml",
102+
"status": "updated",
103+
"additions": 10,
104+
"deletions": 21,
105+
"changes": 124,
106+
"blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file2.yaml",
107+
"raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file2.yaml",
108+
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file2.yaml?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e",
109+
"patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
98110
}
99111
]
100112
}

scm/driver/github/testdata/commit.json.golden

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,17 @@
1515
"Login": "octocat",
1616
"Avatar": "https://avatars3.githubusercontent.com/u/583231?v=4"
1717
},
18+
"Files": [
19+
{
20+
"Sha": "bbcd538c8e72b8c175046e27cc8f907076331401",
21+
"FileName": "file1.txt",
22+
"Status": "added"
23+
},
24+
{
25+
"Sha": "aaqq538c8e72b8c175046e27cc8f907076312345",
26+
"FileName": "file2.yaml",
27+
"Status": "updated"
28+
}
29+
],
1830
"Link": "https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d"
1931
}

scm/driver/github/testdata/commits.json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"Login": "octocat",
1717
"Avatar": "https://avatars3.githubusercontent.com/u/583231?v=4"
1818
},
19-
"Link": "https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d"
19+
"Link": "https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
20+
"Files": []
2021
}
2122
]

scm/git.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ type (
3333
Author Signature
3434
Committer Signature
3535
Link string
36+
Files []Files
37+
}
38+
39+
Files struct {
40+
Sha string
41+
FileName string
42+
Status string
3643
}
3744

3845
// CommitListOptions provides options for querying a

0 commit comments

Comments
 (0)