34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package common
|
|
|
|
import "fmt"
|
|
|
|
// RepoProvider abstracts the remote git host (Gitea, GitHub, etc.) so the
|
|
// client and server packages stay host-agnostic. Provider-specific code lives
|
|
// in a single file per host (e.g. provider_gitea.go) that implements this
|
|
// interface. Adding a new host is a matter of adding a new file and a case
|
|
// in ProviderFor; no caller needs to change.
|
|
type RepoProvider interface {
|
|
// CreateRepo creates a new private domain repo on the remote and returns
|
|
// its canonical clone URL.
|
|
CreateRepo(domain string, domainConfig *DomainConfig) (string, error)
|
|
|
|
// HeadCommit returns the commit SHA at the tip of branch for the domain's
|
|
// repo. It returns ErrRepoNotFound if either the repo or the branch does
|
|
// not exist, so callers can treat "not created yet" as a non-fatal state.
|
|
HeadCommit(domain, branch string, domainConfig *DomainConfig) (string, error)
|
|
}
|
|
|
|
// ProviderFor returns a RepoProvider matching config.Git.Host.
|
|
func ProviderFor(config *AppConfig) (RepoProvider, error) {
|
|
source, err := StrToGitSource(config.Git.Host)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch source {
|
|
case Gitea:
|
|
return newGiteaProvider(config)
|
|
default:
|
|
return nil, fmt.Errorf("git source %q is not implemented", config.Git.Host)
|
|
}
|
|
}
|