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

feat: support multiple reporters at once + make reporters and github details configurable from config file, env variables, CLI flags #171

Merged
merged 17 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 195 additions & 22 deletions cmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"os"
"path"
"strings"
"testing"

Expand All @@ -38,6 +39,8 @@ type testCase struct {
}

func TestChildCommands(t *testing.T) {
cwd, _ := os.Getwd()

cases := []testCase{
{
cmdline: []string{"in"},
Expand Down Expand Up @@ -78,6 +81,12 @@ Debug Flags:
Registry Flags:
--npm-registry string set a custom NPM registry (default "https://registry.npmjs.org")

Reporting Flags:
--gh-owner string set the GitHub owner name (org|user)
--gh-pull-id int set the GitHub pull request ID
--gh-repo string set the GitHub repository name
-r, --reporter (gh-pull-check,gh-pull-comment,gh-pull-review) set one or more reporters to use (default [])

Token Flags:
--gh-token string set the GitHub token

Expand All @@ -92,13 +101,40 @@ Global Flags:
stdout: heredoc.Doc(`{
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"gh-owner": "",
"gh-pull-id": 0,
"gh-repo": "",
"gh-token": "",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": null,
"timeout": 60
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
},
{
envvar: map[string]string{
"LSTN_TIMEOUT": "9999",
},
cmdline: []string{"in", "--debug-options", "--timeout", "8888"},
stdout: heredoc.Doc(`{
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"gh-owner": "",
"gh-pull-id": 0,
"gh-repo": "",
"gh-token": "",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": null,
"timeout": 8888
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
Expand All @@ -111,70 +147,149 @@ Global Flags:
stdout: heredoc.Doc(`{
"debug-options": true,
"endpoint": "https://npm-staging.listen.dev",
"gh-owner": "",
"gh-pull-id": 0,
"gh-repo": "",
"gh-token": "",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": null,
"timeout": 60
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
},
{
cmdline: []string{"scan", "-e", "dev,peer", "--debug-options"},
stdout: heredoc.Doc(`{
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"exclude": [
110,
66,
88
],
"gh-owner": "",
"gh-pull-id": 0,
"gh-repo": "",
"gh-token": "",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": null,
"timeout": 60
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
},
{
envvar: map[string]string{
"LSTN_REPORTER": "gh-pull-check",
},
cmdline: []string{"scan", "--debug-options"},
stdout: heredoc.Doc(`{
"GithubPRReviewReporterOwner": "",
"GithubPRReviewReporterPRID": 0,
"GithubPRReviewReporterRepository": "",
"Reporter": "",
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"exclude": [
110
],
"gh-owner": "",
"gh-pull-id": 0,
"gh-repo": "",
"gh-token": "",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": [
44
],
"timeout": 60
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
},
{
cmdline: []string{
"scan",
"--debug-options",
"--gh-token",
"xxx",
"-r",
"gh-pull-review,gh-pull-comment",
"--gh-owner",
"leodido",
"--gh-repo",
"go-urn",
"--gh-pull-id",
"111",
},
stdout: heredoc.Doc(`{
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"exclude": [
110
],
"gh-owner": "leodido",
"gh-pull-id": 111,
"gh-repo": "go-urn",
"gh-token": "xxx",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": [
33,
22
],
"timeout": 60
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
},
{
envvar: map[string]string{
"LSTN_REPORTER": "gh-pull-check",
},
cmdline: []string{
"scan",
"--debug-options",
"--gh-token",
"xxx",
"--reporter",
"github-pr-review",
"--github_pr_owner",
"fntlnz",
"--github_pr_repository",
"lstnrepotest",
"--github_pr_id",
"1",
"-r",
"gh-pull-review",
"--gh-owner",
"leodido",
"--gh-repo",
"go-urn",
"--gh-pull-id",
"111",
},
stdout: heredoc.Doc(`{
"GithubPRReviewReporterOwner": "fntlnz",
"GithubPRReviewReporterPRID": 1,
"GithubPRReviewReporterRepository": "lstnrepotest",
"Reporter": "github-pr-review",
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"exclude": [
110
],
"gh-owner": "leodido",
"gh-pull-id": 111,
"gh-repo": "go-urn",
"gh-token": "xxx",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": [
33,
44
],
"timeout": 60
}
`),
Expand All @@ -183,31 +298,91 @@ Global Flags:
},
{
envvar: map[string]string{
"LSTN_GH_OWNER": "fntlnz",
"LSTN_GH_PULL_ID": "654",
"LSTN_GH_TOKEN": "yyy",
"LSTN_NPM_REGISTRY": "https://registry.npmjs.com",
},
cmdline: []string{"scan", "--debug-options"},
stdout: heredoc.Doc(`{
"GithubPRReviewReporterOwner": "",
"GithubPRReviewReporterPRID": 0,
"GithubPRReviewReporterRepository": "",
"Reporter": "",
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"exclude": [
110
],
"gh-owner": "fntlnz",
"gh-pull-id": 654,
"gh-repo": "",
"gh-token": "yyy",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.com",
"reporter": null,
"timeout": 60
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
},
{
cmdline: []string{"scan", "--debug-options", "--config", path.Join(cwd, "testdata", "c1.yaml")},
stdout: heredoc.Doc(`Using config file: _CWD_/testdata/c1.yaml
{
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"exclude": [
110
],
"gh-owner": "leodido",
"gh-pull-id": 78999,
"gh-repo": "go-urn",
"gh-token": "zzz",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://some.io",
"reporter": [
33
],
"timeout": 2222
}
`),
stderr: "",
errstr: "",
},
{
envvar: map[string]string{
"LSTN_GH_PULL_ID": "887755",
"LSTN_GH_REPO": "go-conventionalcommits",
"LSTN_ENDPOINT": "https://npm-stage.listen.dev",
"LSTN_TIMEOUT": "33331",
},
cmdline: []string{"scan", "--debug-options", "--config", path.Join(cwd, "testdata", "c1.yaml")},
stdout: heredoc.Doc(`Using config file: _CWD_/testdata/c1.yaml
{
"debug-options": true,
"endpoint": "https://npm-stage.listen.dev",
"exclude": [
110
],
"gh-owner": "leodido",
"gh-pull-id": 887755,
"gh-repo": "go-conventionalcommits",
"gh-token": "zzz",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://some.io",
"reporter": [
33
],
"timeout": 33331
}
`),
stderr: "",
errstr: "",
},
{
cmdline: []string{"version", "--debug-options"},
stdout: heredoc.Doc(`{
Expand Down Expand Up @@ -243,8 +418,6 @@ Global Flags:
},
}

cwd, _ := os.Getwd()

for _, tc := range cases {
tc := tc

Expand Down
Loading