Semaphore/db_lib/GitRepository.go

71 lines
1.5 KiB
Go
Raw Normal View History

2023-09-23 17:12:35 +02:00
package db_lib
import (
2023-09-23 17:12:35 +02:00
"github.com/ansible-semaphore/semaphore/lib"
"os"
2023-02-26 07:22:47 +01:00
"github.com/ansible-semaphore/semaphore/db"
)
type GitRepositoryDirType int
const (
GitRepositoryTmpDir GitRepositoryDirType = iota
GitRepositoryRepoDir
)
2023-02-26 07:22:47 +01:00
type GitClient interface {
Clone(r GitRepository) error
Pull(r GitRepository) error
Checkout(r GitRepository, target string) error
CanBePulled(r GitRepository) bool
GetLastCommitMessage(r GitRepository) (msg string, err error)
GetLastCommitHash(r GitRepository) (hash string, err error)
GetLastRemoteCommitHash(r GitRepository) (hash string, err error)
}
type GitRepository struct {
TemplateID int
Repository db.Repository
2023-09-23 17:12:35 +02:00
Logger lib.Logger
2023-02-26 07:22:47 +01:00
Client GitClient
}
2023-02-26 07:22:47 +01:00
func (r GitRepository) GetFullPath() (path string) {
path = r.Repository.GetFullPath(r.TemplateID)
return
}
2023-02-26 07:22:47 +01:00
func (r GitRepository) ValidateRepo() error {
_, err := os.Stat(r.GetFullPath())
return err
}
func (r GitRepository) Clone() error {
2023-02-26 07:22:47 +01:00
return r.Client.Clone(r)
}
func (r GitRepository) Pull() error {
2023-02-26 07:22:47 +01:00
return r.Client.Pull(r)
}
func (r GitRepository) Checkout(target string) error {
2023-02-26 07:22:47 +01:00
return r.Client.Checkout(r, target)
}
func (r GitRepository) CanBePulled() bool {
2023-02-26 07:22:47 +01:00
return r.Client.CanBePulled(r)
}
func (r GitRepository) GetLastCommitMessage() (msg string, err error) {
2023-02-26 07:22:47 +01:00
return r.Client.GetLastCommitMessage(r)
}
func (r GitRepository) GetLastCommitHash() (hash string, err error) {
2023-02-26 07:22:47 +01:00
return r.Client.GetLastCommitHash(r)
}
2022-01-30 18:43:15 +01:00
func (r GitRepository) GetLastRemoteCommitHash() (hash string, err error) {
2023-02-26 07:22:47 +01:00
return r.Client.GetLastRemoteCommitHash(r)
2022-01-30 18:43:15 +01:00
}