This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
service.go
47 lines (40 loc) · 1.88 KB
/
service.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
package repository
import (
"github.com/redhat-developer/devconsole-api/pkg/apis/devconsole/v1alpha1"
"github.com/redhat-developer/devconsole-git/pkg/git"
"github.com/redhat-developer/devconsole-git/pkg/git/detector/build"
"github.com/redhat-developer/devconsole-git/pkg/log"
)
type GitService interface {
// FileExistenceChecker returns an instance of checker for existence of files in the root directory
FileExistenceChecker() (FileExistenceChecker, error)
// GetLanguageList returns list of detected languages in the sorted order where the first one is the most used
GetLanguageList() ([]string, error)
// CheckCredentials tries to get user information associated with the attached secret from the git server
CheckCredentials() error
// Tries to connect to the git repository with the attached secret
CheckRepoAccessibility() error
// Checks if the branch exists in the git repository
CheckBranch() error
}
type FileExistenceChecker interface {
// GetListOfFoundFiles returns list of filenames present in the root directory
GetListOfFoundFiles() []string
// DetectFiles detects if any of the build tool files are present in the root directory
DetectFiles(buildTool build.Tool) []string
}
// ServiceCreator creates an instance of GitService for the given v1alpha1.GitSource
type ServiceCreator func(log *log.GitSourceLogger, gitSource *v1alpha1.GitSource, secret *git.SecretProvider) (GitService, error)
// NewGitService returns an instance of GitService for the given v1alpha1.GitSource. If no service is matched then returns nil
func NewGitService(log *log.GitSourceLogger, gitSource *v1alpha1.GitSource, secret *git.SecretProvider, serviceCreators []ServiceCreator) (GitService, error) {
for _, creator := range serviceCreators {
detector, err := creator(log, gitSource, secret)
if err != nil {
return nil, err
}
if detector != nil {
return detector, nil
}
}
return nil, nil
}