/
core.go
38 lines (31 loc) · 1.07 KB
/
core.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
package drivers
import "github.com/Originate/git-town/src/git"
// Core provides the public API for the drivers subsystem
var registry = Registry{}
var activeDriver CodeHostingDriver
// GetActiveDriver returns the code hosting driver to use based on the git config
func GetActiveDriver() CodeHostingDriver {
if activeDriver == nil {
activeDriver = GetDriver(DriverOptions{
DriverType: git.Config().GetCodeHostingDriverName(),
OriginURL: git.Config().GetRemoteOriginURL(),
OriginHostname: git.Config().GetCodeHostingOriginHostname(),
})
if activeDriver != nil {
activeDriver.SetAPIToken(activeDriver.GetAPIToken())
}
}
return activeDriver
}
// GetDriver returns the code hosting driver to use based on given origin url
func GetDriver(driverOptions DriverOptions) CodeHostingDriver {
return registry.DetermineActiveDriver(driverOptions)
}
// ValidateHasDriver returns an error if there is no code hosting driver
func ValidateHasDriver() error {
driver := GetActiveDriver()
if driver == nil {
return UnsupportedHostingServiceError{®istry}
}
return nil
}