Skip to content

Commit

Permalink
Ignore showing clusters PR url for statuses other than creation/delet…
Browse files Browse the repository at this point in the history
…ion (#1117)

* Update if condition to check if status is pullRequestCreated

* print pr url in get cluster by name

* Add review changes
  • Loading branch information
sarataha committed Nov 22, 2021
1 parent 350e78d commit 9450e7c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
41 changes: 19 additions & 22 deletions pkg/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,7 @@ func GetClusters(r ClustersRetriever, w io.Writer) error {
fmt.Fprintf(w, "NAME\tSTATUS\tSTATUS_MESSAGE\n")

for _, c := range cs {
if c.PullRequest.Type == "create" {
c.Status = "Creation PR"
} else if c.PullRequest.Type == "delete" {
c.Status = "Deletion PR"
}

if c.Status == "Creation PR" || c.Status == "Deletion PR" {
fmt.Fprintf(w, "%s\t%s\t%s", c.Name, c.Status, c.PullRequest.Url)
fmt.Fprintln(w, "")
} else {
fmt.Fprintf(w, "%s\t%s", c.Name, c.Status)
fmt.Fprintln(w, "")
}
printCluster(c, w)
}

return nil
Expand All @@ -69,18 +57,11 @@ func GetClusterByName(name string, r ClustersRetriever, w io.Writer) error {
}

if len(cs) > 0 {
fmt.Fprintf(w, "NAME\tSTATUS\n")
fmt.Fprintf(w, "NAME\tSTATUS\tSTATUS_MESSAGE\n")

for _, c := range cs {
if c.Name == name {
if c.PullRequest.Type == "create" {
c.Status = "Creation PR"
} else if c.PullRequest.Type == "delete" {
c.Status = "Deletion PR"
}

fmt.Fprintf(w, "%s\t%s", c.Name, c.Status)
fmt.Fprintln(w, "")
printCluster(c, w)
}
}

Expand Down Expand Up @@ -124,3 +105,19 @@ type DeleteClustersParams struct {
ClustersNames []string
CommitMessage string
}

func printCluster(c Cluster, w io.Writer) {
if c.Status == "pullRequestCreated" && c.PullRequest.Type == "create" {
c.Status = "Creation PR"
} else if c.PullRequest.Type == "delete" {
c.Status = "Deletion PR"
}

if c.Status == "Creation PR" || c.Status == "Deletion PR" {
fmt.Fprintf(w, "%s\t%s\t%s", c.Name, c.Status, c.PullRequest.Url)
fmt.Fprintln(w, "")
} else {
fmt.Fprintf(w, "%s\t%s", c.Name, c.Status)
fmt.Fprintln(w, "")
}
}
19 changes: 17 additions & 2 deletions pkg/clusters/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestGetClusters(t *testing.T) {
Name: "cluster-b",
Status: "foo",
PullRequest: clusters.PullRequest{
Type: "foo",
Type: "create",
Url: "https://github.com/org/repo/pull/1",
},
},
Expand Down Expand Up @@ -120,7 +120,22 @@ func TestGetClusterByName(t *testing.T) {
Status: "status-a",
},
},
expected: "NAME\tSTATUS\ncluster-a\tstatus-a\n",
expected: "NAME\tSTATUS\tSTATUS_MESSAGE\ncluster-a\tstatus-a\n",
},
{
name: "Print cluster PR url",
clusterName: "cluster-a",
cs: []clusters.Cluster{
{
Name: "cluster-a",
Status: "pullRequestCreated",
PullRequest: clusters.PullRequest{
Type: "create",
Url: "https://github.com/org/repo/pull/1",
},
},
},
expected: "NAME\tSTATUS\tSTATUS_MESSAGE\ncluster-a\tCreation PR\thttps://github.com/org/repo/pull/1\n",
},
}

Expand Down

0 comments on commit 9450e7c

Please sign in to comment.