-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_api.go
51 lines (42 loc) · 1.12 KB
/
github_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package github
import "redhat-sre-task-dockerfile-scanner/src/models"
type gitHubApi struct {
Client AbstractGitHubClient
}
func Api(client AbstractGitHubClient) *gitHubApi {
return &gitHubApi{
Client: client,
}
}
func (api *gitHubApi) Query(data *models.Data) error {
var err error
var repos []models.Repo
for _, credentials := range data.Credentials {
files, err := api.fetchFiles(credentials)
if err != nil {
return err
}
repos = append(repos, models.Repo{
Files: files,
})
}
data.Repositories = repos
return err
}
func (api *gitHubApi) fetchFiles(credentials models.RepoCredentials) ([]models.File, error) {
var err error
var files []models.File
fileNamePattern := "Dockerfile"
dockerExists, errLocal := api.Client.CheckFileFormat(credentials, fileNamePattern)
err = errLocal
if dockerExists {
paths, errLocal := api.Client.GetFilePaths(credentials, fileNamePattern)
err = errLocal
for _, path := range paths {
content, errLocal := api.Client.GetContent(credentials, path)
err = errLocal
files = append(files, models.File{Path: path, Content: content})
}
}
return files, err
}