From 94bbe8d56b9c26f7f7f5fcddd599e8a9b6d0ce44 Mon Sep 17 00:00:00 2001 From: Rory Quinn Date: Sat, 20 Apr 2024 15:14:30 +1000 Subject: [PATCH 1/6] test action --- .github/workflows/test-action.yaml | 5 +- .github/workflows/test.yaml | 4 +- .gitignore | 23 ++++++++ pkg/pullrequest/client.go | 8 +-- pkg/reqcheck/action.go | 93 +++++++++++++++++++++++++++++- pkg/reqcheck/config.go | 41 +++++++++++-- pkg/reqcheck/inputs/inputs.go | 4 +- 7 files changed, 160 insertions(+), 18 deletions(-) create mode 100644 .gitignore diff --git a/.github/workflows/test-action.yaml b/.github/workflows/test-action.yaml index 93f43fb..ab27ed3 100644 --- a/.github/workflows/test-action.yaml +++ b/.github/workflows/test-action.yaml @@ -25,7 +25,6 @@ jobs: go-version: stable - run: go run main.go env: - INPUT_PATHS: | - - Dummy Test Item - - Dummy Test Item 2 + INPUT_REQUIRED: | + - unit-tests INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ba0f1c8..01a08e9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,4 +12,6 @@ jobs: - uses: actions/setup-go@v3 with: go-version: stable - - run: go test ./... + - run: | + sleep 60 + go test ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78f591a --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +### Go template +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + diff --git a/pkg/pullrequest/client.go b/pkg/pullrequest/client.go index 9541d12..69d8ceb 100644 --- a/pkg/pullrequest/client.go +++ b/pkg/pullrequest/client.go @@ -13,14 +13,14 @@ type Client struct { Owner string Repo string Number int - ctx *githubactions.GitHubContext + ctx *githubactions.GitHubContext gh *github.Client } -func (pr Client) ListChecks(ctx context.Context, options *github.ListCheckRunsOptions) ([]*github.CheckRun, error) { +func (pr Client) ListChecks(ctx context.Context, sha string, options *github.ListCheckRunsOptions) ([]*github.CheckRun, error) { var checks []*github.CheckRun for { - checksPage, resp, err := pr.gh.Checks.ListCheckRunsForRef(ctx, pr.Owner, pr.Repo, pr.ctx.SHA, options) + checksPage, resp, err := pr.gh.Checks.ListCheckRunsForRef(ctx, pr.Owner, pr.Repo, sha, options) if err != nil { return nil, err } @@ -89,7 +89,7 @@ func NewClient(action *githubactions.Action, gh *github.Client) (Client, error) Owner: owner, Repo: repo, Number: number, - ctx: ctx, + ctx: ctx, gh: gh, }, nil } diff --git a/pkg/reqcheck/action.go b/pkg/reqcheck/action.go index 5cdc84c..0734603 100644 --- a/pkg/reqcheck/action.go +++ b/pkg/reqcheck/action.go @@ -2,9 +2,12 @@ package reqcheck import ( "context" + "fmt" + "slices" + "time" "github.com/google/go-github/v61/github" - "github.com/sanity-io/litter" + "github.com/samber/lo" "github.com/sethvargo/go-githubactions" "github.com/roryq/required-checks/pkg/pullrequest" @@ -16,8 +19,92 @@ func Run(ctx context.Context, cfg *Config, action *githubactions.Action, gh *git return err } - checks, err := pr.ListChecks(ctx, nil) - litter.Dump(checks) + action.Infof("Waiting %s before initial check", cfg.InitialDelay) + time.Sleep(cfg.InitialDelay) + for { + checks, err := pr.ListChecks(ctx, cfg.TargetSHA, nil) + if err != nil { + return err + } + action.Infof("Got %d checks", len(checks)) + action.Debugf("Checks: %q", checkNames(checks)) + + requiredSet := lo.SliceToMap(cfg.RequiredWorkflowPatterns, func(item string) (string, struct{}) { return item, struct{}{} }) + toCheck := []*github.CheckRun{} + for _, c := range checks { + if _, ok := requiredSet[c.GetName()]; ok { + toCheck = append(toCheck, c) + delete(requiredSet, c.GetName()) + } + } + + if len(requiredSet) > 0 { + return fmt.Errorf("requiredSet checks not found: %q", keys(requiredSet)) + } + + // any failed + failed := lo.Filter(toCheck, func(item *github.CheckRun, _ int) bool { + return slices.Contains(failed, item.GetConclusion()) + }) + + if len(failed) > 0 { + return fmt.Errorf("requiredSet checks failed: %q", checkNames(failed)) + } + + // not completed + notCompleted := lo.Filter(toCheck, func(item *github.CheckRun, _ int) bool { + return item.GetStatus() != StatusCompleted + }) + + if len(notCompleted) == 0 { + action.Infof("All checks completed") + break + } + + action.Infof("Not all checks completed: %q", checkNames(notCompleted)) + action.Infof("Waiting %s before next check", cfg.PollFrequency) + time.Sleep(cfg.PollFrequency) + } return nil } + +func keys(m map[string]struct{}) []string { + keys := make([]string, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + return keys +} + +func checkNames(checks []*github.CheckRun) []string { + names := make([]string, 0, len(checks)) + for _, c := range checks { + names = append(names, c.GetName()) + } + return names +} + +// Conclusion: action_required, cancelled, failure, neutral, success, skipped, stale, timed_out +const ( + ConclusionActionRequired = "action_required" + ConclusionCancelled = "cancelled" + ConclusionFailure = "failure" + ConclusionNeutral = "neutral" + ConclusionSuccess = "success" + ConclusionSkipped = "skipped" + ConclusionStale = "stale" + ConclusionTimedOut = "timed_out" +) + +// StatusL queued, in_progress, completed, waiting, requested, pending +const ( + StatusQueued = "queued" + StatusInProgress = "in_progress" + StatusCompleted = "completed" + StatusWaiting = "waiting" + StatusRequested = "requested" + StatusPending = "pending" +) + +var failed = []string{ConclusionFailure, ConclusionCancelled, ConclusionTimedOut} diff --git a/pkg/reqcheck/config.go b/pkg/reqcheck/config.go index 90c5740..bb82827 100644 --- a/pkg/reqcheck/config.go +++ b/pkg/reqcheck/config.go @@ -12,12 +12,13 @@ import ( type Config struct { RequiredWorkflowPatterns []string - InitialDelay time.Duration - PollFrequency time.Duration + InitialDelay time.Duration + PollFrequency time.Duration + TargetSHA string } const ( - InitialDelayDefault = 10 * time.Second + InitialDelayDefault = 10 * time.Second PollFrequencyDefault = 15 * time.Second ) @@ -28,11 +29,15 @@ func ConfigFromInputs(action *githubactions.Action) (*Config, error) { PollFrequency: PollFrequencyDefault, } requiredWorkflowPatterns := action.GetInput(inputs.RequiredWorkflowPatterns) - if requiredWorkflowPatterns == "" { - return &c, nil + if requiredWorkflowPatterns != "" { + if err := yaml.Unmarshal([]byte(requiredWorkflowPatterns), &c.RequiredWorkflowPatterns); err != nil { + return nil, err + } } - if err := yaml.Unmarshal([]byte(requiredWorkflowPatterns), &c.RequiredWorkflowPatterns); err != nil { + var err error + c.TargetSHA, err = defaultTargetSHA(action) + if err != nil { return nil, err } @@ -40,3 +45,27 @@ func ConfigFromInputs(action *githubactions.Action) (*Config, error) { return &c, nil } + +// equivalent of ${{ github.event.pull_request.head.sha || github.sha }} +func defaultTargetSHA(action *githubactions.Action) (string, error) { + targetSha := action.GetInput(inputs.TargetSHA) + if targetSha != "" { + action.Infof("Target SHA: %s", targetSha) + return targetSha, nil + } + ctx, err := action.Context() + if err != nil { + return "", err + } + + sha := ctx.SHA + + if pr, ok := ctx.Event["pull_request"]; ok { + sha = pr.(map[string]any)["head"].(map[string]any)["sha"].(string) + action.Infof("Pull Request SHA: %s", sha) + } else { + action.Infof("Commit SHA: %s", sha) + } + + return sha, nil +} diff --git a/pkg/reqcheck/inputs/inputs.go b/pkg/reqcheck/inputs/inputs.go index 92a07b0..39aaba9 100644 --- a/pkg/reqcheck/inputs/inputs.go +++ b/pkg/reqcheck/inputs/inputs.go @@ -5,7 +5,7 @@ const ( Token = "token" // RequiredWorkflowPatterns is a yaml list of patterns to check - RequiredWorkflowPatterns = "required-workflow-patterns" + RequiredWorkflowPatterns = "required" // InitialDelaySeconds Initial delay before polling InitialDelaySeconds = "initial-delay-seconds" @@ -13,6 +13,8 @@ const ( // PollFrequencySeconds Polling frequency PollFrequencySeconds = "poll-frequency-seconds" + TargetSHA = "target-sha" + // Version release version of the action to run Version = "version" ) From 0aa4a8ffeb13cef4c7d29f5aeb551ac817bf6354 Mon Sep 17 00:00:00 2001 From: Rory Quinn Date: Mon, 22 Apr 2024 08:39:13 +1000 Subject: [PATCH 2/6] passing test --- check-runs.json | 410 --------------------- check-suites.json | 423 ---------------------- pkg/pullrequest/client_test.go | 8 +- pkg/reqcheck/action.go | 8 +- pkg/reqcheck/config.go | 4 +- test/events/pull-request.opened.json | 514 +++++++++++++++++++++++++++ 6 files changed, 521 insertions(+), 846 deletions(-) delete mode 100644 check-runs.json delete mode 100644 check-suites.json create mode 100644 test/events/pull-request.opened.json diff --git a/check-runs.json b/check-runs.json deleted file mode 100644 index 3dbc824..0000000 --- a/check-runs.json +++ /dev/null @@ -1,410 +0,0 @@ -{ - "total_count": 3, - "check_runs": [ - { - "id": 23810722873, - "name": "line-coverage", - "node_id": "CR_kwDOLuMX8c8AAAAFizrMOQ", - "head_sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "external_id": "d8a5ceb2-10cd-5c0c-5b0d-baaae43e1d18", - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-runs/23810722873", - "html_url": "https://github.com/RoryQ/glowing-octo-couscous/actions/runs/8683951957/job/23810722873", - "details_url": "https://github.com/RoryQ/glowing-octo-couscous/actions/runs/8683951957/job/23810722873", - "status": "completed", - "conclusion": "success", - "started_at": "2024-04-15T05:32:55Z", - "completed_at": "2024-04-15T05:32:55Z", - "output": { - "title": null, - "summary": null, - "text": null, - "annotations_count": 0, - "annotations_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-runs/23810722873/annotations" - }, - "check_suite": { - "id": 22752529165 - }, - "app": { - "id": 15368, - "slug": "github-actions", - "node_id": "MDM6QXBwMTUzNjg=", - "owner": { - "login": "github", - "id": 9919, - "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", - "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/github", - "html_url": "https://github.com/github", - "followers_url": "https://api.github.com/users/github/followers", - "following_url": "https://api.github.com/users/github/following{/other_user}", - "gists_url": "https://api.github.com/users/github/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github/subscriptions", - "organizations_url": "https://api.github.com/users/github/orgs", - "repos_url": "https://api.github.com/users/github/repos", - "events_url": "https://api.github.com/users/github/events{/privacy}", - "received_events_url": "https://api.github.com/users/github/received_events", - "type": "Organization", - "site_admin": false - }, - "name": "GitHub Actions", - "description": "Automate your workflow from idea to production", - "external_url": "https://help.github.com/en/actions", - "html_url": "https://github.com/apps/github-actions", - "created_at": "2018-07-30T09:30:17Z", - "updated_at": "2024-04-10T20:33:16Z", - "permissions": { - "actions": "write", - "administration": "read", - "attestations": "write", - "checks": "write", - "contents": "write", - "deployments": "write", - "discussions": "write", - "issues": "write", - "merge_queues": "write", - "metadata": "read", - "packages": "write", - "pages": "write", - "pull_requests": "write", - "repository_hooks": "write", - "repository_projects": "write", - "security_events": "write", - "statuses": "write", - "vulnerability_alerts": "read" - }, - "events": [ - "branch_protection_rule", - "check_run", - "check_suite", - "create", - "delete", - "deployment", - "deployment_status", - "discussion", - "discussion_comment", - "fork", - "gollum", - "issues", - "issue_comment", - "label", - "merge_group", - "milestone", - "page_build", - "project", - "project_card", - "project_column", - "public", - "pull_request", - "pull_request_review", - "pull_request_review_comment", - "push", - "registry_package", - "release", - "repository", - "repository_dispatch", - "status", - "watch", - "workflow_dispatch", - "workflow_run" - ] - }, - "pull_requests": [ - { - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/pulls/1", - "id": 1822296646, - "number": 1, - "head": { - "ref": "test-required", - "sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - }, - "base": { - "ref": "master", - "sha": "7e39f9930800733eceee9a2983e17987d80d3ef9", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - } - } - ] - }, - { - "id": 23810722766, - "name": "not-required", - "node_id": "CR_kwDOLuMX8c8AAAAFizrLzg", - "head_sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "external_id": "846e404b-3678-54b8-b528-32dd0c25d0c6", - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-runs/23810722766", - "html_url": "https://github.com/RoryQ/glowing-octo-couscous/actions/runs/8683951957/job/23810722766", - "details_url": "https://github.com/RoryQ/glowing-octo-couscous/actions/runs/8683951957/job/23810722766", - "status": "completed", - "conclusion": "success", - "started_at": "2024-04-15T05:32:55Z", - "completed_at": "2024-04-15T05:32:55Z", - "output": { - "title": null, - "summary": null, - "text": null, - "annotations_count": 0, - "annotations_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-runs/23810722766/annotations" - }, - "check_suite": { - "id": 22752529165 - }, - "app": { - "id": 15368, - "slug": "github-actions", - "node_id": "MDM6QXBwMTUzNjg=", - "owner": { - "login": "github", - "id": 9919, - "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", - "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/github", - "html_url": "https://github.com/github", - "followers_url": "https://api.github.com/users/github/followers", - "following_url": "https://api.github.com/users/github/following{/other_user}", - "gists_url": "https://api.github.com/users/github/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github/subscriptions", - "organizations_url": "https://api.github.com/users/github/orgs", - "repos_url": "https://api.github.com/users/github/repos", - "events_url": "https://api.github.com/users/github/events{/privacy}", - "received_events_url": "https://api.github.com/users/github/received_events", - "type": "Organization", - "site_admin": false - }, - "name": "GitHub Actions", - "description": "Automate your workflow from idea to production", - "external_url": "https://help.github.com/en/actions", - "html_url": "https://github.com/apps/github-actions", - "created_at": "2018-07-30T09:30:17Z", - "updated_at": "2024-04-10T20:33:16Z", - "permissions": { - "actions": "write", - "administration": "read", - "attestations": "write", - "checks": "write", - "contents": "write", - "deployments": "write", - "discussions": "write", - "issues": "write", - "merge_queues": "write", - "metadata": "read", - "packages": "write", - "pages": "write", - "pull_requests": "write", - "repository_hooks": "write", - "repository_projects": "write", - "security_events": "write", - "statuses": "write", - "vulnerability_alerts": "read" - }, - "events": [ - "branch_protection_rule", - "check_run", - "check_suite", - "create", - "delete", - "deployment", - "deployment_status", - "discussion", - "discussion_comment", - "fork", - "gollum", - "issues", - "issue_comment", - "label", - "merge_group", - "milestone", - "page_build", - "project", - "project_card", - "project_column", - "public", - "pull_request", - "pull_request_review", - "pull_request_review_comment", - "push", - "registry_package", - "release", - "repository", - "repository_dispatch", - "status", - "watch", - "workflow_dispatch", - "workflow_run" - ] - }, - "pull_requests": [ - { - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/pulls/1", - "id": 1822296646, - "number": 1, - "head": { - "ref": "test-required", - "sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - }, - "base": { - "ref": "master", - "sha": "7e39f9930800733eceee9a2983e17987d80d3ef9", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - } - } - ] - }, - { - "id": 23810722719, - "name": "required", - "node_id": "CR_kwDOLuMX8c8AAAAFizrLnw", - "head_sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "external_id": "34c5d220-ff6f-578f-0029-72a61fda5532", - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-runs/23810722719", - "html_url": "https://github.com/RoryQ/glowing-octo-couscous/actions/runs/8683951949/job/23810722719", - "details_url": "https://github.com/RoryQ/glowing-octo-couscous/actions/runs/8683951949/job/23810722719", - "status": "completed", - "conclusion": "success", - "started_at": "2024-04-15T05:32:53Z", - "completed_at": "2024-04-15T05:33:05Z", - "output": { - "title": null, - "summary": null, - "text": null, - "annotations_count": 0, - "annotations_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-runs/23810722719/annotations" - }, - "check_suite": { - "id": 22752529149 - }, - "app": { - "id": 15368, - "slug": "github-actions", - "node_id": "MDM6QXBwMTUzNjg=", - "owner": { - "login": "github", - "id": 9919, - "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", - "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/github", - "html_url": "https://github.com/github", - "followers_url": "https://api.github.com/users/github/followers", - "following_url": "https://api.github.com/users/github/following{/other_user}", - "gists_url": "https://api.github.com/users/github/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github/subscriptions", - "organizations_url": "https://api.github.com/users/github/orgs", - "repos_url": "https://api.github.com/users/github/repos", - "events_url": "https://api.github.com/users/github/events{/privacy}", - "received_events_url": "https://api.github.com/users/github/received_events", - "type": "Organization", - "site_admin": false - }, - "name": "GitHub Actions", - "description": "Automate your workflow from idea to production", - "external_url": "https://help.github.com/en/actions", - "html_url": "https://github.com/apps/github-actions", - "created_at": "2018-07-30T09:30:17Z", - "updated_at": "2024-04-10T20:33:16Z", - "permissions": { - "actions": "write", - "administration": "read", - "attestations": "write", - "checks": "write", - "contents": "write", - "deployments": "write", - "discussions": "write", - "issues": "write", - "merge_queues": "write", - "metadata": "read", - "packages": "write", - "pages": "write", - "pull_requests": "write", - "repository_hooks": "write", - "repository_projects": "write", - "security_events": "write", - "statuses": "write", - "vulnerability_alerts": "read" - }, - "events": [ - "branch_protection_rule", - "check_run", - "check_suite", - "create", - "delete", - "deployment", - "deployment_status", - "discussion", - "discussion_comment", - "fork", - "gollum", - "issues", - "issue_comment", - "label", - "merge_group", - "milestone", - "page_build", - "project", - "project_card", - "project_column", - "public", - "pull_request", - "pull_request_review", - "pull_request_review_comment", - "push", - "registry_package", - "release", - "repository", - "repository_dispatch", - "status", - "watch", - "workflow_dispatch", - "workflow_run" - ] - }, - "pull_requests": [ - { - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/pulls/1", - "id": 1822296646, - "number": 1, - "head": { - "ref": "test-required", - "sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - }, - "base": { - "ref": "master", - "sha": "7e39f9930800733eceee9a2983e17987d80d3ef9", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - } - } - ] - } - ] -} \ No newline at end of file diff --git a/check-suites.json b/check-suites.json deleted file mode 100644 index d1ef15d..0000000 --- a/check-suites.json +++ /dev/null @@ -1,423 +0,0 @@ -{ - "total_count": 2, - "check_suites": [ - { - "id": 22752529149, - "node_id": "CS_kwDOLuMX8c8AAAAFTCgK_Q", - "head_branch": "test-required", - "head_sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "status": "completed", - "conclusion": "success", - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-suites/22752529149", - "before": "f929a2655fd0331574d360eb13bc1a2b006c0a2d", - "after": "26f1197996208d93b9f3482b93638baa2b660d95", - "pull_requests": [ - { - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/pulls/1", - "id": 1822296646, - "number": 1, - "head": { - "ref": "test-required", - "sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - }, - "base": { - "ref": "master", - "sha": "7e39f9930800733eceee9a2983e17987d80d3ef9", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - } - } - ], - "app": { - "id": 15368, - "slug": "github-actions", - "node_id": "MDM6QXBwMTUzNjg=", - "owner": { - "login": "github", - "id": 9919, - "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", - "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/github", - "html_url": "https://github.com/github", - "followers_url": "https://api.github.com/users/github/followers", - "following_url": "https://api.github.com/users/github/following{/other_user}", - "gists_url": "https://api.github.com/users/github/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github/subscriptions", - "organizations_url": "https://api.github.com/users/github/orgs", - "repos_url": "https://api.github.com/users/github/repos", - "events_url": "https://api.github.com/users/github/events{/privacy}", - "received_events_url": "https://api.github.com/users/github/received_events", - "type": "Organization", - "site_admin": false - }, - "name": "GitHub Actions", - "description": "Automate your workflow from idea to production", - "external_url": "https://help.github.com/en/actions", - "html_url": "https://github.com/apps/github-actions", - "created_at": "2018-07-30T09:30:17Z", - "updated_at": "2024-04-10T20:33:16Z", - "permissions": { - "actions": "write", - "administration": "read", - "attestations": "write", - "checks": "write", - "contents": "write", - "deployments": "write", - "discussions": "write", - "issues": "write", - "merge_queues": "write", - "metadata": "read", - "packages": "write", - "pages": "write", - "pull_requests": "write", - "repository_hooks": "write", - "repository_projects": "write", - "security_events": "write", - "statuses": "write", - "vulnerability_alerts": "read" - }, - "events": [ - "branch_protection_rule", - "check_run", - "check_suite", - "create", - "delete", - "deployment", - "deployment_status", - "discussion", - "discussion_comment", - "fork", - "gollum", - "issues", - "issue_comment", - "label", - "merge_group", - "milestone", - "page_build", - "project", - "project_card", - "project_column", - "public", - "pull_request", - "pull_request_review", - "pull_request_review_comment", - "push", - "registry_package", - "release", - "repository", - "repository_dispatch", - "status", - "watch", - "workflow_dispatch", - "workflow_run" - ] - }, - "created_at": "2024-04-15T05:32:46Z", - "updated_at": "2024-04-15T05:33:07Z", - "rerequestable": true, - "runs_rerequestable": false, - "latest_check_runs_count": 1, - "check_runs_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-suites/22752529149/check-runs", - "head_commit": { - "id": "26f1197996208d93b9f3482b93638baa2b660d95", - "tree_id": "f3583c15f0615f747b561a07badb1b06882f0bb1", - "message": "pass test", - "timestamp": "2024-04-15T05:32:38Z", - "author": { - "name": "Rory Quinn", - "email": "rory.quinn@anz.com" - }, - "committer": { - "name": "Rory Quinn", - "email": "rory.quinn@anz.com" - } - }, - "repository": { - "id": 786634737, - "node_id": "R_kgDOLuMX8Q", - "name": "glowing-octo-couscous", - "full_name": "RoryQ/glowing-octo-couscous", - "private": false, - "owner": { - "login": "RoryQ", - "id": 40379, - "node_id": "MDQ6VXNlcjQwMzc5", - "avatar_url": "https://avatars.githubusercontent.com/u/40379?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/RoryQ", - "html_url": "https://github.com/RoryQ", - "followers_url": "https://api.github.com/users/RoryQ/followers", - "following_url": "https://api.github.com/users/RoryQ/following{/other_user}", - "gists_url": "https://api.github.com/users/RoryQ/gists{/gist_id}", - "starred_url": "https://api.github.com/users/RoryQ/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/RoryQ/subscriptions", - "organizations_url": "https://api.github.com/users/RoryQ/orgs", - "repos_url": "https://api.github.com/users/RoryQ/repos", - "events_url": "https://api.github.com/users/RoryQ/events{/privacy}", - "received_events_url": "https://api.github.com/users/RoryQ/received_events", - "type": "User", - "site_admin": false - }, - "html_url": "https://github.com/RoryQ/glowing-octo-couscous", - "description": null, - "fork": false, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "forks_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/forks", - "keys_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/teams", - "hooks_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/hooks", - "issue_events_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/issues/events{/number}", - "events_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/events", - "assignees_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/assignees{/user}", - "branches_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/branches{/branch}", - "tags_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/tags", - "blobs_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/statuses/{sha}", - "languages_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/languages", - "stargazers_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/stargazers", - "contributors_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/contributors", - "subscribers_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/subscribers", - "subscription_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/subscription", - "commits_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/contents/{+path}", - "compare_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/merges", - "archive_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/downloads", - "issues_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/issues{/number}", - "pulls_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/pulls{/number}", - "milestones_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/milestones{/number}", - "notifications_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/labels{/name}", - "releases_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/releases{/id}", - "deployments_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/deployments" - } - }, - { - "id": 22752529165, - "node_id": "CS_kwDOLuMX8c8AAAAFTCgLDQ", - "head_branch": "test-required", - "head_sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "status": "completed", - "conclusion": "success", - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-suites/22752529165", - "before": "f929a2655fd0331574d360eb13bc1a2b006c0a2d", - "after": "26f1197996208d93b9f3482b93638baa2b660d95", - "pull_requests": [ - { - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/pulls/1", - "id": 1822296646, - "number": 1, - "head": { - "ref": "test-required", - "sha": "26f1197996208d93b9f3482b93638baa2b660d95", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - }, - "base": { - "ref": "master", - "sha": "7e39f9930800733eceee9a2983e17987d80d3ef9", - "repo": { - "id": 786634737, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "name": "glowing-octo-couscous" - } - } - } - ], - "app": { - "id": 15368, - "slug": "github-actions", - "node_id": "MDM6QXBwMTUzNjg=", - "owner": { - "login": "github", - "id": 9919, - "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", - "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/github", - "html_url": "https://github.com/github", - "followers_url": "https://api.github.com/users/github/followers", - "following_url": "https://api.github.com/users/github/following{/other_user}", - "gists_url": "https://api.github.com/users/github/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github/subscriptions", - "organizations_url": "https://api.github.com/users/github/orgs", - "repos_url": "https://api.github.com/users/github/repos", - "events_url": "https://api.github.com/users/github/events{/privacy}", - "received_events_url": "https://api.github.com/users/github/received_events", - "type": "Organization", - "site_admin": false - }, - "name": "GitHub Actions", - "description": "Automate your workflow from idea to production", - "external_url": "https://help.github.com/en/actions", - "html_url": "https://github.com/apps/github-actions", - "created_at": "2018-07-30T09:30:17Z", - "updated_at": "2024-04-10T20:33:16Z", - "permissions": { - "actions": "write", - "administration": "read", - "attestations": "write", - "checks": "write", - "contents": "write", - "deployments": "write", - "discussions": "write", - "issues": "write", - "merge_queues": "write", - "metadata": "read", - "packages": "write", - "pages": "write", - "pull_requests": "write", - "repository_hooks": "write", - "repository_projects": "write", - "security_events": "write", - "statuses": "write", - "vulnerability_alerts": "read" - }, - "events": [ - "branch_protection_rule", - "check_run", - "check_suite", - "create", - "delete", - "deployment", - "deployment_status", - "discussion", - "discussion_comment", - "fork", - "gollum", - "issues", - "issue_comment", - "label", - "merge_group", - "milestone", - "page_build", - "project", - "project_card", - "project_column", - "public", - "pull_request", - "pull_request_review", - "pull_request_review_comment", - "push", - "registry_package", - "release", - "repository", - "repository_dispatch", - "status", - "watch", - "workflow_dispatch", - "workflow_run" - ] - }, - "created_at": "2024-04-15T05:32:46Z", - "updated_at": "2024-04-15T05:32:57Z", - "rerequestable": true, - "runs_rerequestable": false, - "latest_check_runs_count": 2, - "check_runs_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/check-suites/22752529165/check-runs", - "head_commit": { - "id": "26f1197996208d93b9f3482b93638baa2b660d95", - "tree_id": "f3583c15f0615f747b561a07badb1b06882f0bb1", - "message": "pass test", - "timestamp": "2024-04-15T05:32:38Z", - "author": { - "name": "Rory Quinn", - "email": "rory.quinn@anz.com" - }, - "committer": { - "name": "Rory Quinn", - "email": "rory.quinn@anz.com" - } - }, - "repository": { - "id": 786634737, - "node_id": "R_kgDOLuMX8Q", - "name": "glowing-octo-couscous", - "full_name": "RoryQ/glowing-octo-couscous", - "private": false, - "owner": { - "login": "RoryQ", - "id": 40379, - "node_id": "MDQ6VXNlcjQwMzc5", - "avatar_url": "https://avatars.githubusercontent.com/u/40379?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/RoryQ", - "html_url": "https://github.com/RoryQ", - "followers_url": "https://api.github.com/users/RoryQ/followers", - "following_url": "https://api.github.com/users/RoryQ/following{/other_user}", - "gists_url": "https://api.github.com/users/RoryQ/gists{/gist_id}", - "starred_url": "https://api.github.com/users/RoryQ/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/RoryQ/subscriptions", - "organizations_url": "https://api.github.com/users/RoryQ/orgs", - "repos_url": "https://api.github.com/users/RoryQ/repos", - "events_url": "https://api.github.com/users/RoryQ/events{/privacy}", - "received_events_url": "https://api.github.com/users/RoryQ/received_events", - "type": "User", - "site_admin": false - }, - "html_url": "https://github.com/RoryQ/glowing-octo-couscous", - "description": null, - "fork": false, - "url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous", - "forks_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/forks", - "keys_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/teams", - "hooks_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/hooks", - "issue_events_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/issues/events{/number}", - "events_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/events", - "assignees_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/assignees{/user}", - "branches_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/branches{/branch}", - "tags_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/tags", - "blobs_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/statuses/{sha}", - "languages_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/languages", - "stargazers_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/stargazers", - "contributors_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/contributors", - "subscribers_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/subscribers", - "subscription_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/subscription", - "commits_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/contents/{+path}", - "compare_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/merges", - "archive_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/downloads", - "issues_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/issues{/number}", - "pulls_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/pulls{/number}", - "milestones_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/milestones{/number}", - "notifications_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/labels{/name}", - "releases_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/releases{/id}", - "deployments_url": "https://api.github.com/repos/RoryQ/glowing-octo-couscous/deployments" - } - } - ] -} \ No newline at end of file diff --git a/pkg/pullrequest/client_test.go b/pkg/pullrequest/client_test.go index 845fa48..da05fa8 100644 --- a/pkg/pullrequest/client_test.go +++ b/pkg/pullrequest/client_test.go @@ -21,14 +21,8 @@ func Test_getPRNumber(t *testing.T) { } t.Run("pull_request_event", func(t *testing.T) { - prNum, err := getPRNumber(readEvent("pull-request.edited")) + prNum, err := getPRNumber(readEvent("pull-request.opened")) assert.NoError(t, err) assert.Equal(t, 2, prNum) }) - - t.Run("issue_comment_event", func(t *testing.T) { - prNum, err := getPRNumber(readEvent("issue-comment.created")) - assert.NoError(t, err) - assert.Equal(t, 1, prNum) - }) } diff --git a/pkg/reqcheck/action.go b/pkg/reqcheck/action.go index 0734603..7807a63 100644 --- a/pkg/reqcheck/action.go +++ b/pkg/reqcheck/action.go @@ -40,16 +40,16 @@ func Run(ctx context.Context, cfg *Config, action *githubactions.Action, gh *git } if len(requiredSet) > 0 { - return fmt.Errorf("requiredSet checks not found: %q", keys(requiredSet)) + return fmt.Errorf("required checks not found: %q", keys(requiredSet)) } // any failed failed := lo.Filter(toCheck, func(item *github.CheckRun, _ int) bool { - return slices.Contains(failed, item.GetConclusion()) + return slices.Contains(failedConclusions, item.GetConclusion()) }) if len(failed) > 0 { - return fmt.Errorf("requiredSet checks failed: %q", checkNames(failed)) + return fmt.Errorf("required checks failed: %q", checkNames(failed)) } // not completed @@ -107,4 +107,4 @@ const ( StatusPending = "pending" ) -var failed = []string{ConclusionFailure, ConclusionCancelled, ConclusionTimedOut} +var failedConclusions = []string{ConclusionFailure, ConclusionCancelled, ConclusionTimedOut} diff --git a/pkg/reqcheck/config.go b/pkg/reqcheck/config.go index bb82827..827dee2 100644 --- a/pkg/reqcheck/config.go +++ b/pkg/reqcheck/config.go @@ -18,8 +18,8 @@ type Config struct { } const ( - InitialDelayDefault = 10 * time.Second - PollFrequencyDefault = 15 * time.Second + InitialDelayDefault = 15 * time.Second + PollFrequencyDefault = 30 * time.Second ) func ConfigFromInputs(action *githubactions.Action) (*Config, error) { diff --git a/test/events/pull-request.opened.json b/test/events/pull-request.opened.json new file mode 100644 index 0000000..8f73b8f --- /dev/null +++ b/test/events/pull-request.opened.json @@ -0,0 +1,514 @@ +{ + "action": "opened", + "number": 2, + "pull_request": { + "url": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2", + "id": 279147437, + "node_id": "MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3", + "html_url": "https://github.com/Codertocat/Hello-World/pull/2", + "diff_url": "https://github.com/Codertocat/Hello-World/pull/2.diff", + "patch_url": "https://github.com/Codertocat/Hello-World/pull/2.patch", + "issue_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/2", + "number": 2, + "state": "open", + "locked": false, + "title": "Update the README with new information.", + "user": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "body": null, + "created_at": "2019-05-15T15:20:33Z", + "updated_at": "2019-05-15T15:20:33Z", + "closed_at": null, + "merged_at": null, + "merge_commit_sha": null, + "assignee": null, + "assignees": [ + { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + } + ], + "requested_reviewers": [ + { + "login": "octocat", + "id": 5346, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "http://alambic.github.com/avatars/u/5346?", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "http://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + } + ], + "requested_teams": [], + "labels": [ + { + "id": 1362934389, + "node_id": "MDU6TGFiZWwxMzYyOTM0Mzg5", + "url": "https://api.github.com/repos/Codertocat/Hello-World/labels/bug", + "name": "bug", + "color": "d73a4a", + "default": true, + "description": "Something isn't working" + } + ], + "milestone": null, + "commits_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2/commits", + "review_comments_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2/comments", + "review_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls/comments{/number}", + "comments_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/2/comments", + "statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/ec26c3e57ca3a959ca5aad62de7213c562f8c821", + "head": { + "label": "Codertocat:changes", + "ref": "changes", + "sha": "ec26c3e57ca3a959ca5aad62de7213c562f8c821", + "user": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 186853002, + "node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDI=", + "name": "Hello-World", + "full_name": "Codertocat/Hello-World", + "private": false, + "owner": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/Codertocat/Hello-World", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/Codertocat/Hello-World", + "forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks", + "keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams", + "hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks", + "issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}", + "events_url": "https://api.github.com/repos/Codertocat/Hello-World/events", + "assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}", + "branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}", + "tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags", + "blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}", + "languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages", + "stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers", + "contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors", + "subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription", + "commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}", + "compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges", + "archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads", + "issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}", + "pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}", + "milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}", + "releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}", + "deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments", + "created_at": "2019-05-15T15:19:25Z", + "updated_at": "2019-05-15T15:19:27Z", + "pushed_at": "2019-05-15T15:20:32Z", + "git_url": "git://github.com/Codertocat/Hello-World.git", + "ssh_url": "git@github.com:Codertocat/Hello-World.git", + "clone_url": "https://github.com/Codertocat/Hello-World.git", + "svn_url": "https://github.com/Codertocat/Hello-World", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": null, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "master", + "is_template": false, + "topics": [], + "visibility": "public", + "web_commit_signoff_required": false + } + }, + "base": { + "label": "Codertocat:master", + "ref": "master", + "sha": "f95f852bd8fca8fcc58a9a2d6c842781e32a215e", + "user": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 186853002, + "node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDI=", + "name": "Hello-World", + "full_name": "Codertocat/Hello-World", + "private": false, + "owner": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/Codertocat/Hello-World", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/Codertocat/Hello-World", + "forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks", + "keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams", + "hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks", + "issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}", + "events_url": "https://api.github.com/repos/Codertocat/Hello-World/events", + "assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}", + "branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}", + "tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags", + "blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}", + "languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages", + "stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers", + "contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors", + "subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription", + "commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}", + "compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges", + "archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads", + "issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}", + "pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}", + "milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}", + "releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}", + "deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments", + "created_at": "2019-05-15T15:19:25Z", + "updated_at": "2019-05-15T15:19:27Z", + "pushed_at": "2019-05-15T15:20:32Z", + "git_url": "git://github.com/Codertocat/Hello-World.git", + "ssh_url": "git@github.com:Codertocat/Hello-World.git", + "clone_url": "https://github.com/Codertocat/Hello-World.git", + "svn_url": "https://github.com/Codertocat/Hello-World", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": null, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "master", + "is_template": false, + "topics": [], + "visibility": "public", + "web_commit_signoff_required": false + } + }, + "_links": { + "self": { + "href": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2" + }, + "html": { "href": "https://github.com/Codertocat/Hello-World/pull/2" }, + "issue": { + "href": "https://api.github.com/repos/Codertocat/Hello-World/issues/2" + }, + "comments": { + "href": "https://api.github.com/repos/Codertocat/Hello-World/issues/2/comments" + }, + "review_comments": { + "href": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2/comments" + }, + "review_comment": { + "href": "https://api.github.com/repos/Codertocat/Hello-World/pulls/comments{/number}" + }, + "commits": { + "href": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2/commits" + }, + "statuses": { + "href": "https://api.github.com/repos/Codertocat/Hello-World/statuses/ec26c3e57ca3a959ca5aad62de7213c562f8c821" + } + }, + "author_association": "OWNER", + "auto_merge": null, + "active_lock_reason": null, + "draft": false, + "merged": false, + "mergeable": null, + "rebaseable": null, + "mergeable_state": "unknown", + "merged_by": null, + "comments": 0, + "review_comments": 0, + "maintainer_can_modify": false, + "commits": 1, + "additions": 1, + "deletions": 1, + "changed_files": 1 + }, + "repository": { + "id": 186853002, + "node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDI=", + "name": "checkmate", + "full_name": "RoryQ/checkmate", + "private": false, + "owner": { + "login": "RoryQ", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/Codertocat/Hello-World", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/Codertocat/Hello-World", + "forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks", + "keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams", + "hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks", + "issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}", + "events_url": "https://api.github.com/repos/Codertocat/Hello-World/events", + "assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}", + "branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}", + "tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags", + "blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}", + "languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages", + "stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers", + "contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors", + "subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription", + "commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}", + "compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges", + "archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads", + "issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}", + "pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}", + "milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}", + "releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}", + "deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments", + "created_at": "2019-05-15T15:19:25Z", + "updated_at": "2019-05-15T15:19:27Z", + "pushed_at": "2019-05-15T15:20:32Z", + "git_url": "git://github.com/Codertocat/Hello-World.git", + "ssh_url": "git@github.com:Codertocat/Hello-World.git", + "clone_url": "https://github.com/Codertocat/Hello-World.git", + "svn_url": "https://github.com/Codertocat/Hello-World", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": null, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "master", + "is_template": false, + "topics": [], + "visibility": "public", + "web_commit_signoff_required": false + }, + "installation": { + "id": 1, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMQ==" + }, + "sender": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file From 6b6867ccecb4545a8bdcdbd5c8472c80a0a85320 Mon Sep 17 00:00:00 2001 From: Rory Quinn Date: Mon, 22 Apr 2024 09:09:40 +1000 Subject: [PATCH 3/6] debug --- go.mod | 15 ++------------- go.sum | 19 ------------------- pkg/reqcheck/action.go | 32 ++++++++++++++++++-------------- 3 files changed, 20 insertions(+), 46 deletions(-) diff --git a/go.mod b/go.mod index 5844923..ef07986 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,9 @@ module github.com/roryq/required-checks -go 1.21 - -toolchain go1.22.1 +go 1.22 require ( - github.com/bmatcuk/doublestar/v4 v4.6.1 - github.com/google/go-cmp v0.6.0 - github.com/google/go-github/v48 v48.2.0 - github.com/migueleliasweb/go-github-mock v0.0.23 + github.com/google/go-github/v61 v61.0.0 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e github.com/samber/lo v1.39.0 github.com/sethvargo/go-githubactions v1.2.0 @@ -19,14 +14,8 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/google/go-github/v59 v59.0.0 // indirect - github.com/google/go-github/v61 v61.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect - github.com/gorilla/mux v1.8.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/sanity-io/litter v1.5.5 // indirect - golang.org/x/crypto v0.12.0 // indirect golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect - golang.org/x/time v0.3.0 // indirect ) diff --git a/go.sum b/go.sum index b8a462b..1a67712 100644 --- a/go.sum +++ b/go.sum @@ -1,50 +1,31 @@ -github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= -github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github/v48 v48.2.0 h1:68puzySE6WqUY9KWmpOsDEQfDZsso98rT6pZcz9HqcE= -github.com/google/go-github/v48 v48.2.0/go.mod h1:dDlehKBDo850ZPvCTK0sEqTCVWcrGl2LcDiajkYi89Y= -github.com/google/go-github/v59 v59.0.0 h1:7h6bgpF5as0YQLLkEiVqpgtJqjimMYhBkD4jT5aN3VA= -github.com/google/go-github/v59 v59.0.0/go.mod h1:rJU4R0rQHFVFDOkqGWxfLNo6vEk4dv40oDjhV/gH6wM= github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go= github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/migueleliasweb/go-github-mock v0.0.23 h1:GOi9oX/+Seu9JQ19V8bPDLqDI7M9iEOjo3g8v1k6L2c= -github.com/migueleliasweb/go-github-mock v0.0.23/go.mod h1:NsT8FGbkvIZQtDu38+295sZEX8snaUiiQgsGxi6GUxk= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA= github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= -github.com/sanity-io/litter v1.5.5 h1:iE+sBxPBzoK6uaEP5Lt3fHNgpKcHXc/A2HGETy0uJQo= -github.com/sanity-io/litter v1.5.5/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U= github.com/sethvargo/go-githubactions v1.2.0 h1:Gbr36trCAj6uq7Rx1DolY1NTIg0wnzw3/N5WHdKIjME= github.com/sethvargo/go-githubactions v1.2.0/go.mod h1:7/4WeHgYfSz9U5vwuToCK9KPnELVHAhGtRwLREOQV80= -github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o= golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/reqcheck/action.go b/pkg/reqcheck/action.go index 7807a63..90ea51e 100644 --- a/pkg/reqcheck/action.go +++ b/pkg/reqcheck/action.go @@ -3,12 +3,13 @@ package reqcheck import ( "context" "fmt" - "slices" + "strings" "time" "github.com/google/go-github/v61/github" "github.com/samber/lo" "github.com/sethvargo/go-githubactions" + "slices" "github.com/roryq/required-checks/pkg/pullrequest" ) @@ -22,25 +23,36 @@ func Run(ctx context.Context, cfg *Config, action *githubactions.Action, gh *git action.Infof("Waiting %s before initial check", cfg.InitialDelay) time.Sleep(cfg.InitialDelay) + ghCtx, err := action.Context() + if err != nil { + return err + } + for { checks, err := pr.ListChecks(ctx, cfg.TargetSHA, nil) if err != nil { return err } action.Infof("Got %d checks", len(checks)) - action.Debugf("Checks: %q", checkNames(checks)) + action.Infof("Checks: %q", checkNames(checks)) - requiredSet := lo.SliceToMap(cfg.RequiredWorkflowPatterns, func(item string) (string, struct{}) { return item, struct{}{} }) + requiredSet := lo.SliceToMap(cfg.RequiredWorkflowPatterns, func(item string) (string, bool) { return item, false }) toCheck := []*github.CheckRun{} for _, c := range checks { + if strings.Contains(c.GetDetailsURL(), fmt.Sprintf("runs/%d/job", ghCtx.RunID)) { + // skip waiting for this check if this is named the same as another check + action.Infof("Skipping check: %q", c.GetName()) + continue + } if _, ok := requiredSet[c.GetName()]; ok { toCheck = append(toCheck, c) - delete(requiredSet, c.GetName()) + requiredSet[c.GetName()] = true } } - if len(requiredSet) > 0 { - return fmt.Errorf("required checks not found: %q", keys(requiredSet)) + requiredNotFound := lo.OmitByValues(requiredSet, []bool{true}) + if len(requiredNotFound) > 0 { + return fmt.Errorf("required checks not found: %q in %q", lo.Keys(requiredNotFound)) } // any failed @@ -69,14 +81,6 @@ func Run(ctx context.Context, cfg *Config, action *githubactions.Action, gh *git return nil } -func keys(m map[string]struct{}) []string { - keys := make([]string, 0, len(m)) - for k := range m { - keys = append(keys, k) - } - return keys -} - func checkNames(checks []*github.CheckRun) []string { names := make([]string, 0, len(checks)) for _, c := range checks { From 0d8987a7b915ad660d1b383d5cbc81dba0c2fbe0 Mon Sep 17 00:00:00 2001 From: Rory Quinn Date: Mon, 22 Apr 2024 20:42:43 +1000 Subject: [PATCH 4/6] implement regex matcher --- .github/workflows/test-action.yaml | 2 +- pkg/reqcheck/action.go | 41 +++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-action.yaml b/.github/workflows/test-action.yaml index ab27ed3..2d3d8d3 100644 --- a/.github/workflows/test-action.yaml +++ b/.github/workflows/test-action.yaml @@ -26,5 +26,5 @@ jobs: - run: go run main.go env: INPUT_REQUIRED: | - - unit-tests + - tests INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/pkg/reqcheck/action.go b/pkg/reqcheck/action.go index 90ea51e..16d930b 100644 --- a/pkg/reqcheck/action.go +++ b/pkg/reqcheck/action.go @@ -3,6 +3,7 @@ package reqcheck import ( "context" "fmt" + "regexp" "strings" "time" @@ -28,6 +29,12 @@ func Run(ctx context.Context, cfg *Config, action *githubactions.Action, gh *git return err } + rules, err := NewRuleset(cfg.RequiredWorkflowPatterns) + if err != nil { + return err + } + + foundSelf := false for { checks, err := pr.ListChecks(ctx, cfg.TargetSHA, nil) if err != nil { @@ -41,18 +48,21 @@ func Run(ctx context.Context, cfg *Config, action *githubactions.Action, gh *git for _, c := range checks { if strings.Contains(c.GetDetailsURL(), fmt.Sprintf("runs/%d/job", ghCtx.RunID)) { // skip waiting for this check if this is named the same as another check - action.Infof("Skipping check: %q", c.GetName()) + if !foundSelf { + action.Infof("Skipping check: %q", c.GetName()) + foundSelf = true + } continue } - if _, ok := requiredSet[c.GetName()]; ok { + if found := rules.First(c.GetName()); found != nil { toCheck = append(toCheck, c) - requiredSet[c.GetName()] = true + requiredSet[found.String()] = true } } requiredNotFound := lo.OmitByValues(requiredSet, []bool{true}) if len(requiredNotFound) > 0 { - return fmt.Errorf("required checks not found: %q in %q", lo.Keys(requiredNotFound)) + return fmt.Errorf("required checks not found: %q", lo.Keys(requiredNotFound)) } // any failed @@ -112,3 +122,26 @@ const ( ) var failedConclusions = []string{ConclusionFailure, ConclusionCancelled, ConclusionTimedOut} + +type Ruleset []*regexp.Regexp + +func NewRuleset(patterns []string) (Ruleset, error) { + r := make([]*regexp.Regexp, 0, len(patterns)) + for _, p := range patterns { + re, err := regexp.Compile(p) + if err != nil { + return nil, err + } + r = append(r, re) + } + return r, nil +} + +func (r Ruleset) First(test string) *regexp.Regexp { + for _, re := range r { + if re.MatchString(test) { + return re + } + } + return nil +} From b7e44bf907019b23257b9a21dc2b469422154463 Mon Sep 17 00:00:00 2001 From: Rory Quinn Date: Mon, 22 Apr 2024 20:51:56 +1000 Subject: [PATCH 5/6] update entrypoint --- .github/workflows/test-action.yaml | 4 ++-- action.yaml | 10 ++++++++-- index.js | 4 ++-- pkg/reqcheck/inputs/inputs.go | 10 +++++----- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-action.yaml b/.github/workflows/test-action.yaml index 2d3d8d3..1d1a353 100644 --- a/.github/workflows/test-action.yaml +++ b/.github/workflows/test-action.yaml @@ -25,6 +25,6 @@ jobs: go-version: stable - run: go run main.go env: - INPUT_REQUIRED: | + INPUT_REQUIRED_WORKFLOW_PATTERNS: | - tests - INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + INPUT_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/action.yaml b/action.yaml index fe0b9af..30dac95 100644 --- a/action.yaml +++ b/action.yaml @@ -3,10 +3,16 @@ description: Define required checks inside your repository. author: "Rory Quinn" inputs: - github_token: - description: Required. + token: + description: GitHub token required_workflow_patterns: description: List of patterns to check. + target_sha: + description: Target SHA. + initial_delay_seconds: + description: Initial delay before polling. + poll_frequency_seconds: + description: Polling frequency. version: description: Release version of action to run. runs: diff --git a/index.js b/index.js index de6922a..0865679 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const os = require('os') const process = require('process') const OwnerRepo = "RoryQ/required-checks" -const BinaryName = "required_checks" +const BinaryName = "required-checks" function logDebug(...data) { if (!!process.env.REQUIRED_CHECKS_DEBUG) { @@ -63,7 +63,7 @@ function determineVersion() { } function main() { - logDebug(process.env.INPUT_PATHS) + logDebug(process.env.INPUT_REQUIRED) logDebug("started") const versionTag = determineVersion() let status = downloadBinary(versionTag, chooseBinary(versionTag)) diff --git a/pkg/reqcheck/inputs/inputs.go b/pkg/reqcheck/inputs/inputs.go index 39aaba9..3c51e0c 100644 --- a/pkg/reqcheck/inputs/inputs.go +++ b/pkg/reqcheck/inputs/inputs.go @@ -2,18 +2,18 @@ package inputs const ( // Token required for the GitHub API - Token = "token" + Token = "TOKEN" // RequiredWorkflowPatterns is a yaml list of patterns to check - RequiredWorkflowPatterns = "required" + RequiredWorkflowPatterns = "REQUIRED_WORKFLOW_PATTERN" // InitialDelaySeconds Initial delay before polling - InitialDelaySeconds = "initial-delay-seconds" + InitialDelaySeconds = "INITIAL_DELAY_SECONDS" // PollFrequencySeconds Polling frequency - PollFrequencySeconds = "poll-frequency-seconds" + PollFrequencySeconds = "POLL_FREQUENCY_SECONDS" - TargetSHA = "target-sha" + TargetSHA = "TARGET_SHA" // Version release version of the action to run Version = "version" From 8fdd98b5454b73169840cc837d52623540244c6c Mon Sep 17 00:00:00 2001 From: Rory Quinn Date: Tue, 23 Apr 2024 08:58:11 +1000 Subject: [PATCH 6/6] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 0865679..cc956e8 100644 --- a/index.js +++ b/index.js @@ -63,7 +63,7 @@ function determineVersion() { } function main() { - logDebug(process.env.INPUT_REQUIRED) + logDebug(process.env.INPUT_REQUIRED_WORKFLOW_PATTERNS) logDebug("started") const versionTag = determineVersion() let status = downloadBinary(versionTag, chooseBinary(versionTag))