Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cluster pull request statuses #1064

Merged
merged 7 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/adapters/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ func (c *HTTPClient) RetrieveClusters() ([]clusters.Cluster, error) {
endpoint := "gitops/api/clusters"

type ClusterView struct {
Name string `json:"name"`
Status string `json:"status"`
PullRequestType string `json:"pr-type"`
Name string `json:"name"`
Status string `json:"status"`
PullRequest clusters.PullRequest `json:"pullRequest"`
}

type ClustersResponse struct {
Expand All @@ -368,9 +368,9 @@ func (c *HTTPClient) RetrieveClusters() ([]clusters.Cluster, error) {
var cs []clusters.Cluster
for _, c := range clustersResponse.Clusters {
cs = append(cs, clusters.Cluster{
Name: c.Name,
Status: c.Status,
PullRequestType: c.PullRequestType,
Name: c.Name,
Status: c.Status,
PullRequest: c.PullRequest,
})
}

Expand Down
23 changes: 14 additions & 9 deletions pkg/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ type ClustersRetriever interface {
}

type Cluster struct {
Name string
Status string
PullRequestType string
Name string `json:"name"`
Status string `json:"status"`
PullRequest PullRequest `json:"pullRequest"`
}

type PullRequest struct {
Type string `json:"type"`
Url string `json:"url"`
}

// GetClusters uses a ClustersRetriever adapter to show
Expand All @@ -29,16 +34,16 @@ func GetClusters(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.PullRequestType == "create" {
if c.PullRequest.Type == "create" {
c.Status = "Creation PR"
} else if c.PullRequestType == "delete" {
} else if c.PullRequest.Type == "delete" {
c.Status = "Deletion PR"
}

fmt.Fprintf(w, "%s\t%s", c.Name, c.Status)
fmt.Fprintf(w, "%s\t%s\t%s", c.Name, c.Status, c.PullRequest.Url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌 , maybe only if c.status is creation/deletion PR. e.g. I guess leave it blank for "clusterFound" etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! 👌 Thank you Simon 🙏

fmt.Fprintln(w, "")
}

Expand All @@ -63,9 +68,9 @@ func GetClusterByName(name string, r ClustersRetriever, w io.Writer) error {

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

Expand Down
16 changes: 10 additions & 6 deletions pkg/clusters/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ func TestGetClusters(t *testing.T) {
name: "different status for creation and deletion PR",
cs: []clusters.Cluster{
{
Name: "cluster-a",
Status: "pullRequestCreated",
PullRequestType: "create",
Name: "cluster-a",
Status: "pullRequestCreated",
PullRequest: clusters.PullRequest{
Type: "create",
},
},
{
Name: "cluster-b",
Status: "pullRequestCreated",
PullRequestType: "delete",
Name: "cluster-b",
Status: "pullRequestCreated",
PullRequest: clusters.PullRequest{
Type: "delete",
},
},
},
expected: "NAME\tSTATUS\ncluster-a\tCreation PR\ncluster-b\tDeletion PR\n",
Expand Down