added checkout types https and ssh
This commit is contained in:
parent
934f62af0f
commit
5bd2a3cee1
@ -19,6 +19,9 @@ inputs:
|
||||
serverURL:
|
||||
description: 'address of the unique server on which the company`s gitea server is running'
|
||||
required: true
|
||||
checkoutType:
|
||||
description: 'Type of checkout to use. Supported: `https`, `ssh`'
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: 'go'
|
||||
|
@ -9,20 +9,29 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Repository string
|
||||
Ref string
|
||||
Token string
|
||||
Path string
|
||||
ServerURL string
|
||||
Repository string
|
||||
Ref string
|
||||
Token string
|
||||
Path string
|
||||
ServerURL string
|
||||
CheckoutType CheckoutType
|
||||
}
|
||||
|
||||
type CheckoutType string
|
||||
|
||||
const (
|
||||
HttpsType = "https"
|
||||
SshType = "ssh"
|
||||
)
|
||||
|
||||
func getConfig() Config {
|
||||
return Config{
|
||||
Repository: os.Getenv("INPUT_REPOSITORY"),
|
||||
Ref: os.Getenv("INPUT_REF"),
|
||||
Token: os.Getenv("INPUT_TOKEN"),
|
||||
Path: os.Getenv("INPUT_PATH"),
|
||||
ServerURL: os.Getenv("INPUT_SERVERURL"),
|
||||
Repository: os.Getenv("INPUT_REPOSITORY"),
|
||||
Ref: os.Getenv("INPUT_REF"),
|
||||
Token: os.Getenv("INPUT_TOKEN"),
|
||||
Path: os.Getenv("INPUT_PATH"),
|
||||
ServerURL: os.Getenv("INPUT_SERVERURL"),
|
||||
CheckoutType: CheckoutType(os.Getenv("INPUT_CHECKOUTTYPE")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,9 +51,7 @@ func main() {
|
||||
log.Fatal("field serverURL is required")
|
||||
}
|
||||
|
||||
cloneURL := fmt.Sprintf("https://x-access-token:%s@%s/%s.git", cfg.Token,
|
||||
strings.TrimPrefix(cfg.ServerURL, "https://"), cfg.Repository,
|
||||
)
|
||||
cloneURL := cfg.CheckoutType.GenerateCloneURL(cfg)
|
||||
|
||||
fmt.Println("Cloning", cloneURL, "into", cfg.Path)
|
||||
run("git", "clone", "--depth=1", cloneURL, cfg.Path)
|
||||
@ -64,3 +71,20 @@ func run(name string, args ...string) {
|
||||
log.Fatalf("Command failed: %s %s Error: %v", name, strings.Join(args, " "), err)
|
||||
}
|
||||
}
|
||||
|
||||
func (t CheckoutType) GenerateCloneURL(cfg Config) string {
|
||||
switch t {
|
||||
case HttpsType:
|
||||
return fmt.Sprintf("https://x-access-token:%s@%s/%s.git", cfg.Token,
|
||||
strings.TrimPrefix(cfg.ServerURL, "https://"), cfg.Repository,
|
||||
)
|
||||
case SshType:
|
||||
return fmt.Sprintf("git@%s:%s.git",
|
||||
strings.TrimPrefix(cfg.ServerURL, "git@"),
|
||||
cfg.Repository,
|
||||
)
|
||||
default:
|
||||
log.Fatalf("Unknown checkout type: %s", t)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user