diff --git a/gitops-application.go b/gitops-application.go index 5e5d4b9..1c5d41e 100644 --- a/gitops-application.go +++ b/gitops-application.go @@ -8,6 +8,7 @@ import ( "harness/telemetry" . "harness/types" . "harness/utils" + "regexp" "github.com/fatih/color" "github.com/urfave/cli/v2" @@ -15,6 +16,7 @@ import ( func applyGitopsApplications(c *cli.Context) error { filePath := c.String("file") + githubUsername := c.String("git-user") orgIdentifier := c.String("org-id") projectIdentifier := c.String("project-id") @@ -26,6 +28,13 @@ func applyGitopsApplications(c *cli.Context) error { fmt.Println("Trying to create or update gitops-application using the yaml=", GetColoredText(filePath, color.FgCyan)) var content, _ = ReadFromFile(c.String("file")) + if isGithubRepoUrl(content) { + if githubUsername == "" || githubUsername == defaults.GITHUB_USERNAME_PLACEHOLDER { + githubUsername = TextInput("Enter valid github username:") + } + content = ReplacePlaceholderValues(content, defaults.GITHUB_USERNAME_PLACEHOLDER, githubUsername) + } + agentIdentifier = c.String("agent-identifier") if agentIdentifier == "" || agentIdentifier == defaults.GITOPS_AGENT_IDENTIFIER_PLACEHOLDER { agentIdentifier = TextInput("Enter a valid AgentIdentifier:") @@ -176,3 +185,9 @@ func createGitOpsApplicationPUTPayload(requestBody map[string]interface{}) GitOp } return putApp } + +func isGithubRepoUrl(str string) bool { + regexPattern := `repoURL:\s+https:\/\/github.com\/GITHUB_USERNAME` + match, _ := regexp.MatchString(regexPattern, str) + return match +} diff --git a/main.go b/main.go index 194de64..3e1e0fb 100644 --- a/main.go +++ b/main.go @@ -109,11 +109,11 @@ func main() { Usage: "Create a new secret or Update an existing one.", Flags: []cli.Flag{ &cli.StringFlag{ - Name: "token", + Name: "token", Usage: "Specify your Secret Token", }, &cli.StringFlag{ - Name: "secret-name", + Name: "secret-name", Usage: "provide the secret name", }, &cli.StringFlag{ @@ -359,6 +359,10 @@ func main() { Name: "agent-identifier", Usage: "provide GitOps Agent Identifier.", }, + &cli.StringFlag{ + Name: "git-user", + Usage: "provide your Github username", + }, altsrc.NewStringFlag(&cli.StringFlag{ Name: "org-id", Usage: "provide an Organization Identifier",