From be6c00a5b879ce2dc308cd6395a44cfb2b5be01a Mon Sep 17 00:00:00 2001 From: Masayoshi Mizutani Date: Mon, 18 Sep 2023 11:57:02 +0900 Subject: [PATCH] Add controller test for github webhook --- .gitignore | 2 +- .travis.yml | 26 - pkg/controller/server/github.go | 34 +- pkg/controller/server/github_test.go | 141 +++++ pkg/controller/server/server.go | 2 +- .../testdata/github/pull_request.opened.json | 510 +++++++++++++++++ .../github/pull_request.synchronize.json | 530 ++++++++++++++++++ .../server/testdata/github/push.default.json | 186 ++++++ .../server/testdata/github/push.json | 192 +++++++ pkg/usecase/mock.go | 15 + pkg/usecase/scan_github_repo.go | 19 +- pkg/usecase/usecase.go | 54 +- 12 files changed, 1612 insertions(+), 99 deletions(-) delete mode 100644 .travis.yml create mode 100644 pkg/controller/server/github_test.go create mode 100644 pkg/controller/server/testdata/github/pull_request.opened.json create mode 100644 pkg/controller/server/testdata/github/pull_request.synchronize.json create mode 100644 pkg/controller/server/testdata/github/push.default.json create mode 100644 pkg/controller/server/testdata/github/push.json create mode 100644 pkg/usecase/mock.go diff --git a/.gitignore b/.gitignore index 0e37898..16de438 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ node_modules assets/out assets/.next -*.json +/*.json tmp diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6eee728..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -dist: bionic -language: go -sudo: false -service: - - docker - -env: GO111MODULE=on - -os: - - linux - -go: - - 1.16.x - -git: - depth: 1 - -notifications: - email: false - -before_install: - - docker run -d -p 127.0.0.1:8000:8000 amazon/dynamodb-local - -script: - - go vet ./pkg/... - - go test ./pkg/... diff --git a/pkg/controller/server/github.go b/pkg/controller/server/github.go index 0177b6e..318aece 100644 --- a/pkg/controller/server/github.go +++ b/pkg/controller/server/github.go @@ -14,7 +14,7 @@ import ( "github.com/m-mizutani/octovy/pkg/utils" ) -func handleGitHubEvent(uc *usecase.UseCase, r *http.Request, key types.GitHubAppSecret) error { +func handleGitHubEvent(uc usecase.UseCase, r *http.Request, key types.GitHubAppSecret) error { payload, err := github.ValidatePayload(r, []byte(key)) if err != nil { return goerr.Wrap(err, "validating payload") @@ -46,22 +46,28 @@ func handleGitHubEvent(uc *usecase.UseCase, r *http.Request, key types.GitHubApp return nil } +func refToBranch(v string) string { + if ref := strings.SplitN(v, "/", 3); len(ref) == 3 && ref[1] == "heads" { + return ref[2] + } + return v +} + func githubEventToScanInput(event interface{}) *usecase.ScanGitHubRepoInput { switch ev := event.(type) { case *github.PushEvent: - var branch string - if ref := strings.Split(ev.GetRef(), "/"); len(ref) == 3 && ref[1] == "heads" { - branch = ref[2] - } + branch := refToBranch(ev.GetRef()) + isDefaultBranch := branch == ev.GetRepo().GetDefaultBranch() return &usecase.ScanGitHubRepoInput{ GitHubRepoMetadata: usecase.GitHubRepoMetadata{ - Owner: ev.GetRepo().GetOwner().GetLogin(), - Repo: ev.GetRepo().GetName(), - CommitID: ev.GetHeadCommit().GetID(), - Branch: branch, - BaseCommitID: ev.GetBefore(), - PullRequestID: 0, + Owner: ev.GetRepo().GetOwner().GetLogin(), + Repo: ev.GetRepo().GetName(), + CommitID: ev.GetHeadCommit().GetID(), + Branch: branch, + BaseCommitID: ev.GetBefore(), + PullRequestID: 0, + IsDefaultBranch: isDefaultBranch, }, InstallID: types.GitHubAppInstallID(ev.GetInstallation().GetID()), } @@ -72,11 +78,7 @@ func githubEventToScanInput(event interface{}) *usecase.ScanGitHubRepoInput { return nil } - var branch string - if ref := strings.Split(ev.GetPullRequest().GetHead().GetRef(), "/"); len(ref) == 3 && ref[1] == "heads" { - branch = ref[2] - } - + branch := refToBranch(ev.GetPullRequest().GetHead().GetRef()) baseCommitID := ev.GetBefore() if baseCommitID == "" { baseCommitID = ev.GetPullRequest().GetBase().GetSHA() diff --git a/pkg/controller/server/github_test.go b/pkg/controller/server/github_test.go new file mode 100644 index 0000000..6dfa5d9 --- /dev/null +++ b/pkg/controller/server/github_test.go @@ -0,0 +1,141 @@ +package server_test + +import ( + "bytes" + "crypto/hmac" + "crypto/sha256" + _ "embed" + "encoding/hex" + "net/http" + "net/http/httptest" + "testing" + + "github.com/google/uuid" + "github.com/m-mizutani/gt" + "github.com/m-mizutani/octovy/pkg/controller/server" + "github.com/m-mizutani/octovy/pkg/domain/model" + "github.com/m-mizutani/octovy/pkg/domain/types" + "github.com/m-mizutani/octovy/pkg/usecase" +) + +//go:embed testdata/github/pull_request.opened.json +var testGitHubPullRequestOpened []byte + +//go:embed testdata/github/pull_request.synchronize.json +var testGitHubPullRequestSynchronize []byte + +//go:embed testdata/github/push.json +var testGitHubPush []byte + +//go:embed testdata/github/push.default.json +var testGitHubPushDefault []byte + +func TestGitHubPullRequestSync(t *testing.T) { + const secret = "dummy" + + testCases := map[string]struct { + event string + body []byte + input usecase.ScanGitHubRepoInput + }{ + "pull_request.opened": { + event: "pull_request", + body: testGitHubPullRequestOpened, + input: usecase.ScanGitHubRepoInput{ + GitHubRepoMetadata: usecase.GitHubRepoMetadata{ + Owner: "m-mizutani", + Repo: "masq", + CommitID: "aa0378cad00d375c1897c1b5b5a4dd125984b511", + PullRequestID: 13, + Branch: "update/packages/20230918", + BaseCommitID: "8acdc26c9f12b9cc88e5f0b23f082f648d9e5645", + IsDefaultBranch: false, + }, + InstallID: 41633205, + }, + }, + "pull_request.synchronize": { + event: "pull_request", + body: testGitHubPullRequestSynchronize, + input: usecase.ScanGitHubRepoInput{ + GitHubRepoMetadata: usecase.GitHubRepoMetadata{ + Owner: "m-mizutani", + Repo: "octovy", + CommitID: "69454c171c2f0f2dbc9ccb0c9ef9b72fd769f046", + PullRequestID: 89, + Branch: "release/v0.2.0", + BaseCommitID: "bca5ddd2023d5c906a0420492deb2ede8d99eb79", + IsDefaultBranch: false, + }, + InstallID: 41633205, + }, + }, + + "push": { + event: "push", + body: testGitHubPush, + input: usecase.ScanGitHubRepoInput{ + GitHubRepoMetadata: usecase.GitHubRepoMetadata{ + Owner: "m-mizutani", + Repo: "masq", + CommitID: "aa0378cad00d375c1897c1b5b5a4dd125984b511", + PullRequestID: 0, + Branch: "update/packages/20230918", + BaseCommitID: "0000000000000000000000000000000000000000", + IsDefaultBranch: false, + }, + InstallID: 41633205, + }, + }, + "push: to default": { + event: "push", + body: testGitHubPushDefault, + input: usecase.ScanGitHubRepoInput{ + GitHubRepoMetadata: usecase.GitHubRepoMetadata{ + Owner: "m-mizutani", + Repo: "ops", + CommitID: "f58ae7668c3dfc193a1d2c0372cc52847613cde4", + PullRequestID: 0, + Branch: "master", + BaseCommitID: "987e1005c2e3c79631b620c4a76afd4b8111b7b1", + IsDefaultBranch: true, + }, + InstallID: 41633205, + }, + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + var called int + mock := &usecase.Mock{ + MockScanGitHubRepo: func(ctx *model.Context, input *usecase.ScanGitHubRepoInput) error { + called++ + gt.V(t, input).Equal(&tc.input) + return nil + }, + } + + serv := server.New(mock, secret) + req := newGitHubWebhookRequest(t, tc.event, tc.body, secret) + w := httptest.NewRecorder() + serv.Mux().ServeHTTP(w, req) + gt.V(t, w.Code).Equal(http.StatusOK) + gt.V(t, called).Equal(1) + }) + } +} + +func newGitHubWebhookRequest(t *testing.T, event string, body []byte, secret types.GitHubAppSecret) *http.Request { + req := gt.R1(http.NewRequest(http.MethodPost, "/webhook/github", bytes.NewReader(body))).NoError(t) + + h := hmac.New(sha256.New, []byte(secret)) + h.Write(body) + + req.Header.Set("X-GitHub-Event", event) + req.Header.Set("X-Hub-Signature-256", "sha256="+hex.EncodeToString(h.Sum(nil))) + req.Header.Set("X-GitHub-Delivery", uuid.NewString()) + req.Header.Set("Content-Type", "application/json") + + return req +} diff --git a/pkg/controller/server/server.go b/pkg/controller/server/server.go index bba9721..d8db2e0 100644 --- a/pkg/controller/server/server.go +++ b/pkg/controller/server/server.go @@ -22,7 +22,7 @@ func safeWrite(w http.ResponseWriter, code int, body []byte) { } } -func New(uc *usecase.UseCase, secret types.GitHubAppSecret) *Server { +func New(uc usecase.UseCase, secret types.GitHubAppSecret) *Server { r := chi.NewRouter() r.Use(preProcess) r.Get("/health", func(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/controller/server/testdata/github/pull_request.opened.json b/pkg/controller/server/testdata/github/pull_request.opened.json new file mode 100644 index 0000000..60487dd --- /dev/null +++ b/pkg/controller/server/testdata/github/pull_request.opened.json @@ -0,0 +1,510 @@ +{ + "action": "opened", + "number": 13, + "pull_request": { + "url": "https://api.github.com/repos/m-mizutani/masq/pulls/13", + "id": 1518635674, + "node_id": "PR_kwDOIrCKK85ahIqa", + "html_url": "https://github.com/m-mizutani/masq/pull/13", + "diff_url": "https://github.com/m-mizutani/masq/pull/13.diff", + "patch_url": "https://github.com/m-mizutani/masq/pull/13.patch", + "issue_url": "https://api.github.com/repos/m-mizutani/masq/issues/13", + "number": 13, + "state": "open", + "locked": false, + "title": "Update go packages", + "user": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "body": "SSIA", + "created_at": "2023-09-17T23:43:11Z", + "updated_at": "2023-09-17T23:43:11Z", + "closed_at": null, + "merged_at": null, + "merge_commit_sha": null, + "assignee": null, + "assignees": [], + "requested_reviewers": [], + "requested_teams": [], + "labels": [], + "milestone": null, + "draft": false, + "commits_url": "https://api.github.com/repos/m-mizutani/masq/pulls/13/commits", + "review_comments_url": "https://api.github.com/repos/m-mizutani/masq/pulls/13/comments", + "review_comment_url": "https://api.github.com/repos/m-mizutani/masq/pulls/comments{/number}", + "comments_url": "https://api.github.com/repos/m-mizutani/masq/issues/13/comments", + "statuses_url": "https://api.github.com/repos/m-mizutani/masq/statuses/aa0378cad00d375c1897c1b5b5a4dd125984b511", + "head": { + "label": "m-mizutani:update/packages/20230918", + "ref": "update/packages/20230918", + "sha": "aa0378cad00d375c1897c1b5b5a4dd125984b511", + "user": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 581995051, + "node_id": "R_kgDOIrCKKw", + "name": "masq", + "full_name": "m-mizutani/masq", + "private": false, + "owner": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/masq", + "description": "A utility to redact sensitive data for slog in Go", + "fork": false, + "url": "https://api.github.com/repos/m-mizutani/masq", + "forks_url": "https://api.github.com/repos/m-mizutani/masq/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/masq/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/masq/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/masq/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/masq/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/masq/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/masq/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/masq/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/masq/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/masq/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/masq/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/masq/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/masq/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/masq/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/masq/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/masq/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/masq/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/masq/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/masq/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/masq/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/masq/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/masq/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/masq/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/masq/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/masq/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/masq/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/masq/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/masq/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/masq/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/masq/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/masq/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/masq/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/masq/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/masq/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/masq/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/masq/deployments", + "created_at": "2022-12-25T08:05:37Z", + "updated_at": "2023-09-14T00:34:07Z", + "pushed_at": "2023-09-17T23:43:11Z", + "git_url": "git://github.com/m-mizutani/masq.git", + "ssh_url": "git@github.com:m-mizutani/masq.git", + "clone_url": "https://github.com/m-mizutani/masq.git", + "svn_url": "https://github.com/m-mizutani/masq", + "homepage": "", + "size": 36, + "stargazers_count": 48, + "watchers_count": 48, + "language": "Go", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": { + "key": "apache-2.0", + "name": "Apache License 2.0", + "spdx_id": "Apache-2.0", + "url": "https://api.github.com/licenses/apache-2.0", + "node_id": "MDc6TGljZW5zZTI=" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 0, + "open_issues": 2, + "watchers": 48, + "default_branch": "main", + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_auto_merge": false, + "delete_branch_on_merge": true, + "allow_update_branch": false, + "use_squash_pr_title_as_default": false, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE" + } + }, + "base": { + "label": "m-mizutani:main", + "ref": "main", + "sha": "8acdc26c9f12b9cc88e5f0b23f082f648d9e5645", + "user": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 581995051, + "node_id": "R_kgDOIrCKKw", + "name": "masq", + "full_name": "m-mizutani/masq", + "private": false, + "owner": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/masq", + "description": "A utility to redact sensitive data for slog in Go", + "fork": false, + "url": "https://api.github.com/repos/m-mizutani/masq", + "forks_url": "https://api.github.com/repos/m-mizutani/masq/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/masq/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/masq/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/masq/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/masq/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/masq/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/masq/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/masq/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/masq/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/masq/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/masq/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/masq/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/masq/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/masq/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/masq/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/masq/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/masq/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/masq/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/masq/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/masq/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/masq/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/masq/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/masq/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/masq/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/masq/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/masq/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/masq/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/masq/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/masq/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/masq/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/masq/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/masq/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/masq/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/masq/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/masq/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/masq/deployments", + "created_at": "2022-12-25T08:05:37Z", + "updated_at": "2023-09-14T00:34:07Z", + "pushed_at": "2023-09-17T23:43:11Z", + "git_url": "git://github.com/m-mizutani/masq.git", + "ssh_url": "git@github.com:m-mizutani/masq.git", + "clone_url": "https://github.com/m-mizutani/masq.git", + "svn_url": "https://github.com/m-mizutani/masq", + "homepage": "", + "size": 36, + "stargazers_count": 48, + "watchers_count": 48, + "language": "Go", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": { + "key": "apache-2.0", + "name": "Apache License 2.0", + "spdx_id": "Apache-2.0", + "url": "https://api.github.com/licenses/apache-2.0", + "node_id": "MDc6TGljZW5zZTI=" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 0, + "open_issues": 2, + "watchers": 48, + "default_branch": "main", + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_auto_merge": false, + "delete_branch_on_merge": true, + "allow_update_branch": false, + "use_squash_pr_title_as_default": false, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE" + } + }, + "_links": { + "self": { + "href": "https://api.github.com/repos/m-mizutani/masq/pulls/13" + }, + "html": { + "href": "https://github.com/m-mizutani/masq/pull/13" + }, + "issue": { + "href": "https://api.github.com/repos/m-mizutani/masq/issues/13" + }, + "comments": { + "href": "https://api.github.com/repos/m-mizutani/masq/issues/13/comments" + }, + "review_comments": { + "href": "https://api.github.com/repos/m-mizutani/masq/pulls/13/comments" + }, + "review_comment": { + "href": "https://api.github.com/repos/m-mizutani/masq/pulls/comments{/number}" + }, + "commits": { + "href": "https://api.github.com/repos/m-mizutani/masq/pulls/13/commits" + }, + "statuses": { + "href": "https://api.github.com/repos/m-mizutani/masq/statuses/aa0378cad00d375c1897c1b5b5a4dd125984b511" + } + }, + "author_association": "OWNER", + "auto_merge": null, + "active_lock_reason": null, + "merged": false, + "mergeable": null, + "rebaseable": null, + "mergeable_state": "unknown", + "merged_by": null, + "comments": 0, + "review_comments": 0, + "maintainer_can_modify": false, + "commits": 1, + "additions": 21, + "deletions": 22, + "changed_files": 3 + }, + "repository": { + "id": 581995051, + "node_id": "R_kgDOIrCKKw", + "name": "masq", + "full_name": "m-mizutani/masq", + "private": false, + "owner": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/masq", + "description": "A utility to redact sensitive data for slog in Go", + "fork": false, + "url": "https://api.github.com/repos/m-mizutani/masq", + "forks_url": "https://api.github.com/repos/m-mizutani/masq/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/masq/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/masq/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/masq/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/masq/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/masq/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/masq/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/masq/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/masq/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/masq/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/masq/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/masq/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/masq/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/masq/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/masq/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/masq/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/masq/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/masq/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/masq/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/masq/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/masq/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/masq/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/masq/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/masq/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/masq/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/masq/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/masq/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/masq/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/masq/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/masq/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/masq/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/masq/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/masq/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/masq/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/masq/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/masq/deployments", + "created_at": "2022-12-25T08:05:37Z", + "updated_at": "2023-09-14T00:34:07Z", + "pushed_at": "2023-09-17T23:43:11Z", + "git_url": "git://github.com/m-mizutani/masq.git", + "ssh_url": "git@github.com:m-mizutani/masq.git", + "clone_url": "https://github.com/m-mizutani/masq.git", + "svn_url": "https://github.com/m-mizutani/masq", + "homepage": "", + "size": 36, + "stargazers_count": 48, + "watchers_count": 48, + "language": "Go", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": { + "key": "apache-2.0", + "name": "Apache License 2.0", + "spdx_id": "Apache-2.0", + "url": "https://api.github.com/licenses/apache-2.0", + "node_id": "MDc6TGljZW5zZTI=" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 0, + "open_issues": 2, + "watchers": 48, + "default_branch": "main" + }, + "sender": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 41633205, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDE2MzMyMDU=" + } +} diff --git a/pkg/controller/server/testdata/github/pull_request.synchronize.json b/pkg/controller/server/testdata/github/pull_request.synchronize.json new file mode 100644 index 0000000..fe7fd3f --- /dev/null +++ b/pkg/controller/server/testdata/github/pull_request.synchronize.json @@ -0,0 +1,530 @@ +{ + "action": "synchronize", + "number": 89, + "pull_request": { + "url": "https://api.github.com/repos/m-mizutani/octovy/pulls/89", + "id": 1473604329, + "node_id": "PR_kwDOFWYRkM5X1Wrp", + "html_url": "https://github.com/m-mizutani/octovy/pull/89", + "diff_url": "https://github.com/m-mizutani/octovy/pull/89.diff", + "patch_url": "https://github.com/m-mizutani/octovy/pull/89.patch", + "issue_url": "https://api.github.com/repos/m-mizutani/octovy/issues/89", + "number": 89, + "state": "open", + "locked": false, + "title": "v0.2.0", + "user": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "body": "# Overview\r\n\r\n- Octovy's v0.1.x has become overly feature-rich, making continued maintenance difficult.\r\n - There were many implementations of UI that the developers were unfamiliar with.\r\n - In order to accommodate multiple use cases, the DB schema has become excessively complex.\r\n- In response to this, we will significantly renew the features in v0.2.0. This will involve a large amount of breaking changes.", + "created_at": "2023-08-14T01:55:48Z", + "updated_at": "2023-09-17T06:37:51Z", + "closed_at": null, + "merged_at": null, + "merge_commit_sha": "366e61bce88a7532ec2bfa9964a8399f36469e56", + "assignee": null, + "assignees": [], + "requested_reviewers": [], + "requested_teams": [], + "labels": [], + "milestone": null, + "draft": true, + "commits_url": "https://api.github.com/repos/m-mizutani/octovy/pulls/89/commits", + "review_comments_url": "https://api.github.com/repos/m-mizutani/octovy/pulls/89/comments", + "review_comment_url": "https://api.github.com/repos/m-mizutani/octovy/pulls/comments{/number}", + "comments_url": "https://api.github.com/repos/m-mizutani/octovy/issues/89/comments", + "statuses_url": "https://api.github.com/repos/m-mizutani/octovy/statuses/69454c171c2f0f2dbc9ccb0c9ef9b72fd769f046", + "head": { + "label": "m-mizutani:release/v0.2.0", + "ref": "release/v0.2.0", + "sha": "69454c171c2f0f2dbc9ccb0c9ef9b72fd769f046", + "user": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 359010704, + "node_id": "MDEwOlJlcG9zaXRvcnkzNTkwMTA3MDQ=", + "name": "octovy", + "full_name": "m-mizutani/octovy", + "private": false, + "owner": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/octovy", + "description": "Trivy based vulnerability management service", + "fork": false, + "url": "https://api.github.com/repos/m-mizutani/octovy", + "forks_url": "https://api.github.com/repos/m-mizutani/octovy/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/octovy/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/octovy/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/octovy/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/octovy/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/octovy/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/octovy/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/octovy/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/octovy/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/octovy/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/octovy/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/octovy/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/octovy/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/octovy/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/octovy/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/octovy/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/octovy/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/octovy/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/octovy/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/octovy/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/octovy/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/octovy/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/octovy/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/octovy/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/octovy/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/octovy/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/octovy/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/octovy/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/octovy/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/octovy/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/octovy/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/octovy/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/octovy/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/octovy/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/octovy/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/octovy/deployments", + "created_at": "2021-04-18T00:25:50Z", + "updated_at": "2023-08-10T05:59:13Z", + "pushed_at": "2023-09-17T06:37:52Z", + "git_url": "git://github.com/m-mizutani/octovy.git", + "ssh_url": "git@github.com:m-mizutani/octovy.git", + "clone_url": "https://github.com/m-mizutani/octovy.git", + "svn_url": "https://github.com/m-mizutani/octovy", + "homepage": "", + "size": 2230, + "stargazers_count": 51, + "watchers_count": 51, + "language": "Go", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 4, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 57, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + "github-app", + "golang", + "security", + "typescript", + "vulnerability-scanners" + ], + "visibility": "public", + "forks": 4, + "open_issues": 57, + "watchers": 51, + "default_branch": "main", + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_auto_merge": false, + "delete_branch_on_merge": true, + "allow_update_branch": false, + "use_squash_pr_title_as_default": false, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE" + } + }, + "base": { + "label": "m-mizutani:main", + "ref": "main", + "sha": "08fb7816c6d0a485239ca5f342342186f972a6e7", + "user": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 359010704, + "node_id": "MDEwOlJlcG9zaXRvcnkzNTkwMTA3MDQ=", + "name": "octovy", + "full_name": "m-mizutani/octovy", + "private": false, + "owner": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/octovy", + "description": "Trivy based vulnerability management service", + "fork": false, + "url": "https://api.github.com/repos/m-mizutani/octovy", + "forks_url": "https://api.github.com/repos/m-mizutani/octovy/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/octovy/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/octovy/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/octovy/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/octovy/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/octovy/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/octovy/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/octovy/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/octovy/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/octovy/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/octovy/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/octovy/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/octovy/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/octovy/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/octovy/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/octovy/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/octovy/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/octovy/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/octovy/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/octovy/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/octovy/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/octovy/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/octovy/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/octovy/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/octovy/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/octovy/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/octovy/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/octovy/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/octovy/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/octovy/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/octovy/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/octovy/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/octovy/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/octovy/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/octovy/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/octovy/deployments", + "created_at": "2021-04-18T00:25:50Z", + "updated_at": "2023-08-10T05:59:13Z", + "pushed_at": "2023-09-17T06:37:52Z", + "git_url": "git://github.com/m-mizutani/octovy.git", + "ssh_url": "git@github.com:m-mizutani/octovy.git", + "clone_url": "https://github.com/m-mizutani/octovy.git", + "svn_url": "https://github.com/m-mizutani/octovy", + "homepage": "", + "size": 2230, + "stargazers_count": 51, + "watchers_count": 51, + "language": "Go", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 4, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 57, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + "github-app", + "golang", + "security", + "typescript", + "vulnerability-scanners" + ], + "visibility": "public", + "forks": 4, + "open_issues": 57, + "watchers": 51, + "default_branch": "main", + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_auto_merge": false, + "delete_branch_on_merge": true, + "allow_update_branch": false, + "use_squash_pr_title_as_default": false, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE" + } + }, + "_links": { + "self": { + "href": "https://api.github.com/repos/m-mizutani/octovy/pulls/89" + }, + "html": { + "href": "https://github.com/m-mizutani/octovy/pull/89" + }, + "issue": { + "href": "https://api.github.com/repos/m-mizutani/octovy/issues/89" + }, + "comments": { + "href": "https://api.github.com/repos/m-mizutani/octovy/issues/89/comments" + }, + "review_comments": { + "href": "https://api.github.com/repos/m-mizutani/octovy/pulls/89/comments" + }, + "review_comment": { + "href": "https://api.github.com/repos/m-mizutani/octovy/pulls/comments{/number}" + }, + "commits": { + "href": "https://api.github.com/repos/m-mizutani/octovy/pulls/89/commits" + }, + "statuses": { + "href": "https://api.github.com/repos/m-mizutani/octovy/statuses/69454c171c2f0f2dbc9ccb0c9ef9b72fd769f046" + } + }, + "author_association": "OWNER", + "auto_merge": null, + "active_lock_reason": null, + "merged": false, + "mergeable": null, + "rebaseable": null, + "mergeable_state": "unknown", + "merged_by": null, + "comments": 0, + "review_comments": 3, + "maintainer_can_modify": false, + "commits": 22, + "additions": 3399, + "deletions": 72648, + "changed_files": 273 + }, + "before": "bca5ddd2023d5c906a0420492deb2ede8d99eb79", + "after": "69454c171c2f0f2dbc9ccb0c9ef9b72fd769f046", + "repository": { + "id": 359010704, + "node_id": "MDEwOlJlcG9zaXRvcnkzNTkwMTA3MDQ=", + "name": "octovy", + "full_name": "m-mizutani/octovy", + "private": false, + "owner": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/octovy", + "description": "Trivy based vulnerability management service", + "fork": false, + "url": "https://api.github.com/repos/m-mizutani/octovy", + "forks_url": "https://api.github.com/repos/m-mizutani/octovy/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/octovy/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/octovy/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/octovy/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/octovy/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/octovy/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/octovy/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/octovy/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/octovy/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/octovy/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/octovy/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/octovy/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/octovy/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/octovy/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/octovy/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/octovy/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/octovy/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/octovy/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/octovy/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/octovy/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/octovy/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/octovy/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/octovy/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/octovy/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/octovy/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/octovy/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/octovy/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/octovy/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/octovy/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/octovy/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/octovy/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/octovy/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/octovy/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/octovy/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/octovy/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/octovy/deployments", + "created_at": "2021-04-18T00:25:50Z", + "updated_at": "2023-08-10T05:59:13Z", + "pushed_at": "2023-09-17T06:37:52Z", + "git_url": "git://github.com/m-mizutani/octovy.git", + "ssh_url": "git@github.com:m-mizutani/octovy.git", + "clone_url": "https://github.com/m-mizutani/octovy.git", + "svn_url": "https://github.com/m-mizutani/octovy", + "homepage": "", + "size": 2230, + "stargazers_count": 51, + "watchers_count": 51, + "language": "Go", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 4, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 57, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + "github-app", + "golang", + "security", + "typescript", + "vulnerability-scanners" + ], + "visibility": "public", + "forks": 4, + "open_issues": 57, + "watchers": 51, + "default_branch": "main" + }, + "sender": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 41633205, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDE2MzMyMDU=" + } +} diff --git a/pkg/controller/server/testdata/github/push.default.json b/pkg/controller/server/testdata/github/push.default.json new file mode 100644 index 0000000..52b68b9 --- /dev/null +++ b/pkg/controller/server/testdata/github/push.default.json @@ -0,0 +1,186 @@ +{ + "ref": "refs/heads/master", + "before": "987e1005c2e3c79631b620c4a76afd4b8111b7b1", + "after": "f58ae7668c3dfc193a1d2c0372cc52847613cde4", + "repository": { + "id": 281879096, + "node_id": "MDEwOlJlcG9zaXRvcnkyODE4NzkwOTY=", + "name": "ops", + "full_name": "m-mizutani/ops", + "private": true, + "owner": { + "name": "m-mizutani", + "email": "mizutani@hey.com", + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/ops", + "description": null, + "fork": false, + "url": "https://github.com/m-mizutani/ops", + "forks_url": "https://api.github.com/repos/m-mizutani/ops/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/ops/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/ops/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/ops/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/ops/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/ops/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/ops/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/ops/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/ops/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/ops/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/ops/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/ops/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/ops/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/ops/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/ops/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/ops/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/ops/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/ops/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/ops/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/ops/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/ops/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/ops/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/ops/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/ops/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/ops/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/ops/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/ops/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/ops/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/ops/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/ops/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/ops/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/ops/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/ops/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/ops/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/ops/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/ops/deployments", + "created_at": 1595488464, + "updated_at": "2022-10-23T01:52:43Z", + "pushed_at": 1694834911, + "git_url": "git://github.com/m-mizutani/ops.git", + "ssh_url": "git@github.com:m-mizutani/ops.git", + "clone_url": "https://github.com/m-mizutani/ops.git", + "svn_url": "https://github.com/m-mizutani/ops", + "homepage": null, + "size": 495, + "stargazers_count": 0, + "watchers_count": 0, + "language": "HCL", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "private", + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "stargazers": 0, + "master_branch": "master" + }, + "pusher": { + "name": "m-mizutani", + "email": "mizutani@hey.com" + }, + "sender": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 41633205, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDE2MzMyMDU=" + }, + "created": false, + "deleted": false, + "forced": false, + "base_ref": null, + "compare": "https://github.com/m-mizutani/ops/compare/987e1005c2e3...f58ae7668c3d", + "commits": [ + { + "id": "f58ae7668c3dfc193a1d2c0372cc52847613cde4", + "tree_id": "6101b6784aec5d25a35cea43f6c6a85affe84e68", + "distinct": true, + "message": "empty commit", + "timestamp": "2023-09-16T12:28:28+09:00", + "url": "https://github.com/m-mizutani/ops/commit/f58ae7668c3dfc193a1d2c0372cc52847613cde4", + "author": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "committer": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "added": [], + "removed": [], + "modified": ["README.md"] + } + ], + "head_commit": { + "id": "f58ae7668c3dfc193a1d2c0372cc52847613cde4", + "tree_id": "6101b6784aec5d25a35cea43f6c6a85affe84e68", + "distinct": true, + "message": "empty commit", + "timestamp": "2023-09-16T12:28:28+09:00", + "url": "https://github.com/m-mizutani/ops/commit/f58ae7668c3dfc193a1d2c0372cc52847613cde4", + "author": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "committer": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "added": [], + "removed": [], + "modified": ["README.md"] + } +} diff --git a/pkg/controller/server/testdata/github/push.json b/pkg/controller/server/testdata/github/push.json new file mode 100644 index 0000000..072b203 --- /dev/null +++ b/pkg/controller/server/testdata/github/push.json @@ -0,0 +1,192 @@ +{ + "ref": "refs/heads/update/packages/20230918", + "before": "0000000000000000000000000000000000000000", + "after": "aa0378cad00d375c1897c1b5b5a4dd125984b511", + "repository": { + "id": 581995051, + "node_id": "R_kgDOIrCKKw", + "name": "masq", + "full_name": "m-mizutani/masq", + "private": false, + "owner": { + "name": "m-mizutani", + "email": "mizutani@hey.com", + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/m-mizutani/masq", + "description": "A utility to redact sensitive data for slog in Go", + "fork": false, + "url": "https://github.com/m-mizutani/masq", + "forks_url": "https://api.github.com/repos/m-mizutani/masq/forks", + "keys_url": "https://api.github.com/repos/m-mizutani/masq/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/m-mizutani/masq/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/m-mizutani/masq/teams", + "hooks_url": "https://api.github.com/repos/m-mizutani/masq/hooks", + "issue_events_url": "https://api.github.com/repos/m-mizutani/masq/issues/events{/number}", + "events_url": "https://api.github.com/repos/m-mizutani/masq/events", + "assignees_url": "https://api.github.com/repos/m-mizutani/masq/assignees{/user}", + "branches_url": "https://api.github.com/repos/m-mizutani/masq/branches{/branch}", + "tags_url": "https://api.github.com/repos/m-mizutani/masq/tags", + "blobs_url": "https://api.github.com/repos/m-mizutani/masq/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/m-mizutani/masq/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/m-mizutani/masq/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/m-mizutani/masq/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/m-mizutani/masq/statuses/{sha}", + "languages_url": "https://api.github.com/repos/m-mizutani/masq/languages", + "stargazers_url": "https://api.github.com/repos/m-mizutani/masq/stargazers", + "contributors_url": "https://api.github.com/repos/m-mizutani/masq/contributors", + "subscribers_url": "https://api.github.com/repos/m-mizutani/masq/subscribers", + "subscription_url": "https://api.github.com/repos/m-mizutani/masq/subscription", + "commits_url": "https://api.github.com/repos/m-mizutani/masq/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/m-mizutani/masq/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/m-mizutani/masq/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/m-mizutani/masq/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/m-mizutani/masq/contents/{+path}", + "compare_url": "https://api.github.com/repos/m-mizutani/masq/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/m-mizutani/masq/merges", + "archive_url": "https://api.github.com/repos/m-mizutani/masq/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/m-mizutani/masq/downloads", + "issues_url": "https://api.github.com/repos/m-mizutani/masq/issues{/number}", + "pulls_url": "https://api.github.com/repos/m-mizutani/masq/pulls{/number}", + "milestones_url": "https://api.github.com/repos/m-mizutani/masq/milestones{/number}", + "notifications_url": "https://api.github.com/repos/m-mizutani/masq/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/m-mizutani/masq/labels{/name}", + "releases_url": "https://api.github.com/repos/m-mizutani/masq/releases{/id}", + "deployments_url": "https://api.github.com/repos/m-mizutani/masq/deployments", + "created_at": 1671955537, + "updated_at": "2023-09-14T00:34:07Z", + "pushed_at": 1694994180, + "git_url": "git://github.com/m-mizutani/masq.git", + "ssh_url": "git@github.com:m-mizutani/masq.git", + "clone_url": "https://github.com/m-mizutani/masq.git", + "svn_url": "https://github.com/m-mizutani/masq", + "homepage": "", + "size": 36, + "stargazers_count": 48, + "watchers_count": 48, + "language": "Go", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 1, + "license": { + "key": "apache-2.0", + "name": "Apache License 2.0", + "spdx_id": "Apache-2.0", + "url": "https://api.github.com/licenses/apache-2.0", + "node_id": "MDc6TGljZW5zZTI=" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 0, + "open_issues": 1, + "watchers": 48, + "default_branch": "main", + "stargazers": 48, + "master_branch": "main" + }, + "pusher": { + "name": "m-mizutani", + "email": "mizutani@hey.com" + }, + "sender": { + "login": "m-mizutani", + "id": 605953, + "node_id": "MDQ6VXNlcjYwNTk1Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/605953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/m-mizutani", + "html_url": "https://github.com/m-mizutani", + "followers_url": "https://api.github.com/users/m-mizutani/followers", + "following_url": "https://api.github.com/users/m-mizutani/following{/other_user}", + "gists_url": "https://api.github.com/users/m-mizutani/gists{/gist_id}", + "starred_url": "https://api.github.com/users/m-mizutani/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/m-mizutani/subscriptions", + "organizations_url": "https://api.github.com/users/m-mizutani/orgs", + "repos_url": "https://api.github.com/users/m-mizutani/repos", + "events_url": "https://api.github.com/users/m-mizutani/events{/privacy}", + "received_events_url": "https://api.github.com/users/m-mizutani/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 41633205, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDE2MzMyMDU=" + }, + "created": true, + "deleted": false, + "forced": false, + "base_ref": null, + "compare": "https://github.com/m-mizutani/masq/commit/aa0378cad00d", + "commits": [ + { + "id": "aa0378cad00d375c1897c1b5b5a4dd125984b511", + "tree_id": "6bfe094e8bee7d87fca34add0b2e3713416adf3c", + "distinct": true, + "message": "Update packages", + "timestamp": "2023-09-18T08:42:57+09:00", + "url": "https://github.com/m-mizutani/masq/commit/aa0378cad00d375c1897c1b5b5a4dd125984b511", + "author": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "committer": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "added": [], + "removed": [], + "modified": ["clone_test.go", "go.mod", "go.sum"] + } + ], + "head_commit": { + "id": "aa0378cad00d375c1897c1b5b5a4dd125984b511", + "tree_id": "6bfe094e8bee7d87fca34add0b2e3713416adf3c", + "distinct": true, + "message": "Update packages", + "timestamp": "2023-09-18T08:42:57+09:00", + "url": "https://github.com/m-mizutani/masq/commit/aa0378cad00d375c1897c1b5b5a4dd125984b511", + "author": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "committer": { + "name": "Masayoshi Mizutani", + "email": "mizutani@hey.com", + "username": "m-mizutani" + }, + "added": [], + "removed": [], + "modified": ["clone_test.go", "go.mod", "go.sum"] + } +} diff --git a/pkg/usecase/mock.go b/pkg/usecase/mock.go new file mode 100644 index 0000000..818ca84 --- /dev/null +++ b/pkg/usecase/mock.go @@ -0,0 +1,15 @@ +package usecase + +import "github.com/m-mizutani/octovy/pkg/domain/model" + +type Mock struct { + MockScanGitHubRepo func(ctx *model.Context, input *ScanGitHubRepoInput) error +} + +func NewMock() UseCase { + return &Mock{} +} + +func (x *Mock) ScanGitHubRepo(ctx *model.Context, input *ScanGitHubRepoInput) error { + return x.MockScanGitHubRepo(ctx, input) +} diff --git a/pkg/usecase/scan_github_repo.go b/pkg/usecase/scan_github_repo.go index 80ec397..1c8b48e 100644 --- a/pkg/usecase/scan_github_repo.go +++ b/pkg/usecase/scan_github_repo.go @@ -29,12 +29,13 @@ type ScanGitHubRepoInput struct { } type GitHubRepoMetadata struct { - Owner string - Repo string - CommitID string - Branch string - BaseCommitID string - PullRequestID int + Owner string + Repo string + CommitID string + Branch string + IsDefaultBranch bool + BaseCommitID string + PullRequestID int } func (x *ScanGitHubRepoInput) Validate() error { @@ -56,7 +57,7 @@ func (x *ScanGitHubRepoInput) Validate() error { // ScanGitHubRepo is a usecase to download a source code from GitHub and scan it with Trivy. Using GitHub App credentials to download a private repository, then the app should be installed to the repository and have read access. // After scanning, the result is stored to the database. The temporary files are removed after the scan. -func (x *UseCase) ScanGitHubRepo(ctx *model.Context, input *ScanGitHubRepoInput) error { +func (x *useCase) ScanGitHubRepo(ctx *model.Context, input *ScanGitHubRepoInput) error { if err := input.Validate(); err != nil { return err } @@ -86,7 +87,7 @@ func (x *UseCase) ScanGitHubRepo(ctx *model.Context, input *ScanGitHubRepoInput) return nil } -func (x *UseCase) downloadGitHubRepo(ctx *model.Context, input *ScanGitHubRepoInput, dstDir string) error { +func (x *useCase) downloadGitHubRepo(ctx *model.Context, input *ScanGitHubRepoInput, dstDir string) error { zipURL, err := x.clients.GitHubApp().GetArchiveURL(ctx, &gh.GetArchiveURLInput{ Owner: input.Owner, Repo: input.Repo, @@ -120,7 +121,7 @@ func (x *UseCase) downloadGitHubRepo(ctx *model.Context, input *ScanGitHubRepoIn return nil } -func (x *UseCase) scanGitHubRepo(ctx *model.Context, codeDir string) (*ttype.Report, error) { +func (x *useCase) scanGitHubRepo(ctx *model.Context, codeDir string) (*ttype.Report, error) { // Scan local directory tmpResult, err := os.CreateTemp("", "octovy_result.*.json") if err != nil { diff --git a/pkg/usecase/usecase.go b/pkg/usecase/usecase.go index cb25b12..bb20633 100644 --- a/pkg/usecase/usecase.go +++ b/pkg/usecase/usecase.go @@ -1,58 +1,20 @@ package usecase import ( + "github.com/m-mizutani/octovy/pkg/domain/model" "github.com/m-mizutani/octovy/pkg/infra" ) -type UseCase struct { - clients *infra.Clients +type UseCase interface { + ScanGitHubRepo(ctx *model.Context, input *ScanGitHubRepoInput) error } -func New(clients *infra.Clients) *UseCase { - return &UseCase{ - clients: clients, - } +type useCase struct { + clients *infra.Clients } -/* -func (x *UseCase) ScanRepository(dir string) error { - tmp, err := os.CreateTemp("", "trivy-scan-*.json") - if err != nil { - return goerr.Wrap(err, "creating trivy tmp output file") - } - if err := tmp.Close(); err != nil { - return goerr.Wrap(err, "closing trivy tmp output file") - } - - trivyOptions := []string{ - "fs", - "--format", "json", - "-o", tmp.Name(), - "--list-all-pkgs", - dir, - } - cmd := exec.Command("trivy", trivyOptions...) - stderr, err := cmd.StderrPipe() - if err != nil { - return goerr.Wrap(err, "retrieving stderr pipe") - } - if err := cmd.Run(); err != nil { - msg, _ := io.ReadAll(stderr) - return goerr.Wrap(err, "executing trivy").With("stderr", msg) - } - - fmt.Println(tmp.Name()) - - fd, err := os.Open(tmp.Name()) - if err != nil { - return goerr.Wrap(err, "opening trivy tmp output file") - } - - var report trivy_types.Report - if err := json.NewDecoder(fd).Decode(&report); err != nil { - return goerr.Wrap(err, "decoding trivy report") +func New(clients *infra.Clients) UseCase { + return &useCase{ + clients: clients, } - - return nil } -*/