Skip to content

Commit

Permalink
feat: [PLG-3112] Add a flag to accept github username for creating Gi…
Browse files Browse the repository at this point in the history
…tops-Application (#61)
  • Loading branch information
neelam-harness authored Jan 4, 2024
1 parent bb09d30 commit cd1411b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions gitops-application.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"harness/telemetry"
. "harness/types"
. "harness/utils"
"regexp"

"github.com/fatih/color"
"github.com/urfave/cli/v2"
)

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")

Expand All @@ -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:")
Expand Down Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit cd1411b

Please sign in to comment.