-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from mozilla-services/add-metrics-cli-app
Add metrics CLI app π
- Loading branch information
Showing
39 changed files
with
1,757 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/mozilla-services/rapid-release-model/metrics/internal/factory" | ||
"github.com/mozilla-services/rapid-release-model/metrics/internal/github" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type DeploymentsOptions struct { | ||
Limit int | ||
Environments *[]string | ||
} | ||
|
||
func newDeploymentsCmd(f *factory.Factory) *cobra.Command { | ||
opts := new(DeploymentsOptions) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "deployments", | ||
Short: "Retrieve data about GitHub Deployments", | ||
Long: "Retrieve data about GitHub Deployments", | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
if opts.Limit < 1 { | ||
return fmt.Errorf("Limit cannot be smaller than 1.") | ||
} | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runDeployments(cmd.Root().Context(), f, opts) | ||
}, | ||
} | ||
cmd.Flags().IntVarP(&opts.Limit, "limit", "l", 10, "limit for how many Deployments to fetch") | ||
|
||
opts.Environments = cmd.Flags().StringArray("env", nil, "multiple use for Deployment environments") | ||
|
||
return cmd | ||
} | ||
|
||
func runDeployments(ctx context.Context, f *factory.Factory, opts *DeploymentsOptions) error { | ||
repo, err := f.NewGitHubRepo() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
gqlClient, err := f.NewGitHubGraphQLClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
deployments, err := github.QueryDeployments(gqlClient, repo, opts.Limit, opts.Environments) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
exporter, err := f.NewExporter() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return exporter.Export(deployments) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package cmd | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/mozilla-services/rapid-release-model/metrics/internal/config" | ||
"github.com/mozilla-services/rapid-release-model/metrics/internal/github" | ||
"github.com/mozilla-services/rapid-release-model/metrics/internal/test" | ||
"github.com/shurcooL/githubv4" | ||
) | ||
|
||
func TestDeployments(t *testing.T) { | ||
repo := &github.Repo{Owner: "hackebrot", Name: "turtle"} | ||
|
||
env := map[string]string{ | ||
config.EnvKey("GITHUB", "REPO_OWNER"): "", | ||
config.EnvKey("GITHUB", "REPO_NAME"): "", | ||
} | ||
|
||
tempDir := t.TempDir() | ||
|
||
tests := []test.TestCase{{ | ||
Name: "deployments__repo_owner__required", | ||
Args: []string{"github", "-n", repo.Name, "deployments"}, | ||
ErrContains: "Repo.Owner and Repo.Name are required. Set env vars or pass flags", | ||
Env: env, | ||
}, { | ||
Name: "deployments__repo_name__required", | ||
Args: []string{"github", "-o", repo.Owner, "deployments"}, | ||
ErrContains: "Repo.Owner and Repo.Name are required. Set env vars or pass flags", | ||
Env: env, | ||
}, { | ||
Name: "deployments__default", | ||
Args: []string{"github", "-o", repo.Owner, "-n", repo.Name, "deployments"}, | ||
WantFixture: test.NewFixture("deployments", "want__default.json"), | ||
Env: env, | ||
}, { | ||
Name: "deployments__limit", | ||
Args: []string{"github", "-o", repo.Owner, "-n", repo.Name, "deployments", "-l", "2"}, | ||
WantFixture: test.NewFixture("deployments", "want__limit.json"), | ||
Env: env, | ||
}, { | ||
Name: "deployments__json", | ||
Args: []string{"github", "-o", repo.Owner, "-n", repo.Name, "deployments", "-e", "json"}, | ||
WantFixture: test.NewFixture("deployments", "want__default.json"), | ||
Env: env, | ||
}, { | ||
Name: "deployments__csv", | ||
Args: []string{"github", "-o", repo.Owner, "-n", repo.Name, "deployments", "-e", "csv"}, | ||
WantFixture: test.NewFixture("deployments", "want__default.csv"), | ||
Env: env, | ||
}, { | ||
Name: "deployments__filename", | ||
Args: []string{"github", "-o", repo.Owner, "-n", repo.Name, "deployments", "-f", filepath.Join(tempDir, "r.json")}, | ||
WantFixture: test.NewFixture("deployments", "want__default.json"), | ||
WantFile: filepath.Join(tempDir, "r.json"), | ||
Env: env, | ||
}, { | ||
Name: "deployments__env__single", | ||
Args: []string{"github", "-o", repo.Owner, "-n", repo.Name, "deployments", "--env", "prod"}, | ||
WantVariables: map[string]interface{}{"environments": []githubv4.String{githubv4.String("prod")}}, | ||
Env: env, | ||
}, { | ||
Name: "deployments__env__multiple", | ||
Args: []string{"github", "-o", repo.Owner, "-n", repo.Name, "deployments", "--env", "prod", "--env", "hello"}, | ||
WantVariables: map[string]interface{}{"environments": []githubv4.String{githubv4.String("prod"), githubv4.String("hello")}}, | ||
Env: env, | ||
}} | ||
|
||
test.RunTests(t, newRootCmd, tests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"Repository": { | ||
"Name": "turtle", | ||
"Owner": { | ||
"Login": "hackebrot" | ||
}, | ||
"Deployments": { | ||
"PageInfo": { | ||
"HasNextPage": true, | ||
"EndCursor": "abc123" | ||
}, | ||
"Nodes": [ | ||
{ | ||
"Description": "Deployment03", | ||
"CreatedAt": "2022-05-02T20:25:05Z", | ||
"UpdatedAt": "2022-05-02T20:25:05Z", | ||
"OriginalEnvironment": "prod", | ||
"LatestEnvironment": "prod", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "1abc111" | ||
} | ||
}, | ||
{ | ||
"Description": "Deployment03", | ||
"CreatedAt": "2022-05-01T20:20:05Z", | ||
"UpdatedAt": "2022-05-01T20:20:05Z", | ||
"OriginalEnvironment": "stage", | ||
"LatestEnvironment": "stage", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "1abc111" | ||
} | ||
}, | ||
{ | ||
"Description": "Deployment02", | ||
"CreatedAt": "2022-04-01T20:25:05Z", | ||
"UpdatedAt": "2022-04-01T20:25:05Z", | ||
"OriginalEnvironment": "stage", | ||
"LatestEnvironment": "stage", | ||
"Task": "deploy", | ||
"State": "INACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "2abc111" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"Repository": { | ||
"Name": "turtle", | ||
"Owner": { | ||
"Login": "hackebrot" | ||
}, | ||
"Deployments": { | ||
"PageInfo": { | ||
"HasNextPage": false, | ||
"EndCursor": "abc456" | ||
}, | ||
"Nodes": [ | ||
{ | ||
"Description": "Deployment01", | ||
"CreatedAt": "2022-02-01T20:25:05Z", | ||
"UpdatedAt": "2022-02-01T20:25:05Z", | ||
"OriginalEnvironment": "hello", | ||
"LatestEnvironment": "hello", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "3abc111" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
description,createdAt,updatedAt,originalEnvironment,latestEnvironment,task,state,commitOid | ||
Deployment03,2022-05-02T20:25:05Z,2022-05-02T20:25:05Z,prod,prod,deploy,ACTIVE,1abc111 | ||
Deployment03,2022-05-01T20:20:05Z,2022-05-01T20:20:05Z,stage,stage,deploy,ACTIVE,1abc111 | ||
Deployment02,2022-04-01T20:25:05Z,2022-04-01T20:25:05Z,stage,stage,deploy,INACTIVE,2abc111 | ||
Deployment01,2022-02-01T20:25:05Z,2022-02-01T20:25:05Z,hello,hello,deploy,ACTIVE,3abc111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"Description": "Deployment03", | ||
"CreatedAt": "2022-05-02T20:25:05Z", | ||
"UpdatedAt": "2022-05-02T20:25:05Z", | ||
"OriginalEnvironment": "prod", | ||
"LatestEnvironment": "prod", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "1abc111" | ||
} | ||
}, | ||
{ | ||
"Description": "Deployment03", | ||
"CreatedAt": "2022-05-01T20:20:05Z", | ||
"UpdatedAt": "2022-05-01T20:20:05Z", | ||
"OriginalEnvironment": "stage", | ||
"LatestEnvironment": "stage", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "1abc111" | ||
} | ||
}, | ||
{ | ||
"Description": "Deployment02", | ||
"CreatedAt": "2022-04-01T20:25:05Z", | ||
"UpdatedAt": "2022-04-01T20:25:05Z", | ||
"OriginalEnvironment": "stage", | ||
"LatestEnvironment": "stage", | ||
"Task": "deploy", | ||
"State": "INACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "2abc111" | ||
} | ||
}, | ||
{ | ||
"Description": "Deployment01", | ||
"CreatedAt": "2022-02-01T20:25:05Z", | ||
"UpdatedAt": "2022-02-01T20:25:05Z", | ||
"OriginalEnvironment": "hello", | ||
"LatestEnvironment": "hello", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "3abc111" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"Description": "Deployment03", | ||
"CreatedAt": "2022-05-02T20:25:05Z", | ||
"UpdatedAt": "2022-05-02T20:25:05Z", | ||
"OriginalEnvironment": "prod", | ||
"LatestEnvironment": "prod", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "1abc111" | ||
} | ||
}, | ||
{ | ||
"Description": "Deployment03", | ||
"CreatedAt": "2022-05-01T20:20:05Z", | ||
"UpdatedAt": "2022-05-01T20:20:05Z", | ||
"OriginalEnvironment": "stage", | ||
"LatestEnvironment": "stage", | ||
"Task": "deploy", | ||
"State": "ACTIVE", | ||
"Commit": { | ||
"AbbreviatedOid": "1abc111" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"Repository": { | ||
"Name": "turtle", | ||
"Owner": { | ||
"Login": "hackebrot" | ||
}, | ||
"PullRequests": { | ||
"PageInfo": { | ||
"HasNextPage": true, | ||
"EndCursor": "abc" | ||
}, | ||
"Nodes": [ | ||
{ | ||
"ID": "PULLREQUEST1", | ||
"Number": 1, | ||
"Title": "Set up CI/CD workflow π¦", | ||
"CreatedAt": "2023-09-08T16:33:20Z", | ||
"UpdatedAt": "2023-09-10T07:24:20Z", | ||
"ClosedAt": "2023-09-10T07:24:17Z", | ||
"MergedAt": "2023-09-10T07:24:16Z" | ||
}, | ||
{ | ||
"ID": "PULLREQUEST2", | ||
"Number": 2, | ||
"Title": "Refactor test framework π€", | ||
"CreatedAt": "2023-09-08T09:18:42Z", | ||
"UpdatedAt": "2023-09-08T09:40:23Z", | ||
"ClosedAt": "2023-09-08T09:40:20Z", | ||
"MergedAt": "2023-09-08T09:40:19Z" | ||
}, | ||
{ | ||
"ID": "PULLREQUEST3", | ||
"Number": 3, | ||
"Title": "Fetch deployment metrics π", | ||
"CreatedAt": "2023-10-08T08:09:38Z", | ||
"UpdatedAt": "2023-10-08T08:58:13Z", | ||
"ClosedAt": "2023-11-08T08:58:10Z", | ||
"MergedAt": "2023-11-08T08:58:10Z" | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"Repository": { | ||
"Name": "turtle", | ||
"Owner": { | ||
"Login": "hackebrot" | ||
}, | ||
"PullRequests": { | ||
"PageInfo": { | ||
"HasNextPage": false, | ||
"EndCursor": "hello" | ||
}, | ||
"Nodes": [ | ||
{ | ||
"ID": "PULLREQUEST4", | ||
"Number": 4, | ||
"Title": "Updating Docker image π¦", | ||
"CreatedAt": "2023-12-08T16:33:20Z", | ||
"UpdatedAt": "2023-12-10T07:24:20Z", | ||
"ClosedAt": "2023-12-10T07:24:17Z", | ||
"MergedAt": "2023-12-10T07:24:16Z" | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
id,number,title,createdAt,updatedAt,closedAt,mergedAt | ||
PULLREQUEST1,1,Set up CI/CD workflow π¦,2023-09-08T16:33:20Z,2023-09-10T07:24:20Z,2023-09-10T07:24:17Z,2023-09-10T07:24:16Z | ||
PULLREQUEST2,2,Refactor test framework π€,2023-09-08T09:18:42Z,2023-09-08T09:40:23Z,2023-09-08T09:40:20Z,2023-09-08T09:40:19Z | ||
PULLREQUEST3,3,Fetch deployment metrics π,2023-10-08T08:09:38Z,2023-10-08T08:58:13Z,2023-11-08T08:58:10Z,2023-11-08T08:58:10Z | ||
PULLREQUEST4,4,Updating Docker image π¦,2023-12-08T16:33:20Z,2023-12-10T07:24:20Z,2023-12-10T07:24:17Z,2023-12-10T07:24:16Z |
Oops, something went wrong.