diff --git a/pkg/intoto/provenance_options_test.go b/pkg/intoto/provenance_options_test.go index 099bf38..7329d90 100644 --- a/pkg/intoto/provenance_options_test.go +++ b/pkg/intoto/provenance_options_test.go @@ -152,7 +152,6 @@ func Environment() *vcs.GithubCIEnvironment { Event: &vcs.Event{ EventMetadata: &vcs.EventMetadata{ HeadCommit: &vcs.HeadCommit{ - Id: "yolo", Timestamp: "2022-02-14T09:38:16+01:00", }, }, diff --git a/pkg/intoto/provenance_test.go b/pkg/intoto/provenance_test.go index e818373..664eec9 100644 --- a/pkg/intoto/provenance_test.go +++ b/pkg/intoto/provenance_test.go @@ -78,7 +78,6 @@ func TestGenerateSlsaPredicate(t *testing.T) { // VCS GithubContext assert.Equal(t, test.buildType, slsaPredicate.BuildType) assert.NotEmpty(t, slsaPredicate.Invocation) - assert.Equal(t, "yolo", slsaPredicate.Invocation.Parameters.(*vcs.Event).GetHeadCommitId()) assert.Equal(t, "2022-02-14T09:38:16+01:00", slsaPredicate.Invocation.Parameters.(*vcs.Event).GetHeadCommitTimestamp()) e := slsaPredicate.Invocation.Environment.(*vcs.Metadata) assert.NoError(t, err) diff --git a/pkg/vcs/event.go b/pkg/vcs/event.go index 47b0598..9da21d3 100644 --- a/pkg/vcs/event.go +++ b/pkg/vcs/event.go @@ -10,19 +10,23 @@ type Event struct { } type EventMetadata struct { - WorkFlowRun *WorkFlow `json:"workflow_run"` - HeadCommit *HeadCommit `json:"head_commit"` -} - -type WorkFlow struct { - HeadCommit *HeadCommit `json:"head_commit"` + HeadCommit *HeadCommit `json:"head_commit"` + PullRequest *PullRequest `json:"pull_request"` + WorkFlowRun *WorkFlow `json:"workflow_run"` } type HeadCommit struct { - Id string `json:"id"` Timestamp string `json:"timestamp"` } +type PullRequest struct { + UpdatedAt string `json:"updated_at"` +} + +type WorkFlow struct { + HeadCommit *HeadCommit `json:"head_commit"` +} + func ParseEvent(inputs []byte) (*Event, error) { var event Event err := json.Unmarshal(inputs, &event.EventMetadata) @@ -32,21 +36,17 @@ func ParseEvent(inputs []byte) (*Event, error) { return &event, nil } -func (in *Event) GetHeadCommitId() string { - if in.EventMetadata.WorkFlowRun != nil { - return in.EventMetadata.WorkFlowRun.HeadCommit.Id +func (in *Event) GetHeadCommitTimestamp() string { + if in.EventMetadata.HeadCommit != nil { + return in.EventMetadata.HeadCommit.Timestamp } - return in.EventMetadata.HeadCommit.Id -} - -func (in *Event) GetHeadCommitTimestamp() string { if in.EventMetadata.WorkFlowRun != nil { return in.EventMetadata.WorkFlowRun.HeadCommit.Timestamp } - if in.EventMetadata.HeadCommit != nil { - return in.EventMetadata.HeadCommit.Timestamp + if in.EventMetadata.PullRequest != nil { + return in.EventMetadata.PullRequest.UpdatedAt } return time.Now().UTC().Round(time.Second).Format(time.RFC3339) diff --git a/pkg/vcs/event_test.go b/pkg/vcs/event_test.go index 07b3cec..51b2bb1 100644 --- a/pkg/vcs/event_test.go +++ b/pkg/vcs/event_test.go @@ -7,21 +7,50 @@ import ( "time" ) -func TestEvenHeadCommit(t *testing.T) { - metadata := commitMetadata(t) - context, err := ParseContext(metadata) - assert.NoError(t, err) - parsedEvent, err := ParseEvent(context.Event) - assert.NoError(t, err) - assert.NotNil(t, parsedEvent) - assert.Equal(t, "d4cd018b2fe54d8308b78f2bb88db94ac57173ea", parsedEvent.GetHeadCommitId()) - _, err = time.Parse(time.RFC3339, parsedEvent.GetHeadCommitTimestamp()) - assert.NoError(t, err) - assert.Equal(t, "2022-10-21T11:26:55+02:00", parsedEvent.GetHeadCommitTimestamp()) +func TestEventHeadCommit(t *testing.T) { + for _, test := range []struct { + name string + workFlowMeatData []byte + WantTime string + }{ + { + name: "GitHub Event workflow_run with head_commit", + workFlowMeatData: commitMetadata(t, "testdata/workflowrun-head-commit.json"), + WantTime: "2022-10-21T11:26:55+02:00", + }, + { + name: "GitHub Event pull_request with updated_at", + workFlowMeatData: commitMetadata(t, "testdata/pull-request-event.json"), + WantTime: "2022-11-17T07:46:39Z", + }, + { + name: "GitHub Event workflow_dispatch with head_commit", + workFlowMeatData: commitMetadata(t, "testdata/github-context.json"), + WantTime: "2022-02-14T09:38:16+01:00", + }, + { + name: "No metadata found, should return default start time", + workFlowMeatData: commitMetadata(t, "testdata/unknown-event.json"), + }, + } { + t.Run(test.name, func(t *testing.T) { + context, err := ParseContext(test.workFlowMeatData) + assert.NoError(t, err) + parsedEvent, err := ParseEvent(context.Event) + assert.NoError(t, err) + assert.NotNil(t, parsedEvent) + if test.WantTime != "" { + assert.Equal(t, test.WantTime, parsedEvent.GetHeadCommitTimestamp()) + } else { + _, err := time.Parse(time.RFC3339, parsedEvent.GetHeadCommitTimestamp()) + assert.NoError(t, err) + } + }) + } } -func commitMetadata(t *testing.T) []byte { - metadata, err := os.ReadFile("testdata/event-head-commit.json") +func commitMetadata(t *testing.T, eventFile string) []byte { + metadata, err := os.ReadFile(eventFile) assert.NoError(t, err) return metadata } diff --git a/pkg/vcs/github_ci_test.go b/pkg/vcs/github_ci_test.go index 75ffc55..ceebfb0 100644 --- a/pkg/vcs/github_ci_test.go +++ b/pkg/vcs/github_ci_test.go @@ -15,10 +15,10 @@ func TestCreateCIEnvironment(t *testing.T) { env := envC() ci, err := CreateGithubCIEnvironment(context, &runner, &env) assert.NoError(t, err) - assert.Equal(t, "https://github.com/nais/salsa", ci.RepoUri()) + assert.Equal(t, "https://github.com/bolo/tomato", ci.RepoUri()) assert.Equal(t, "90dc9f2bc4007d1099a941ba3d408d2c896fe8dd", ci.Sha()) - assert.Equal(t, "https://github.com/nais/salsa/Attestations/GitHubHostedActions@v1", ci.BuilderId()) - assert.Equal(t, "https://github.com/nais/salsa/actions/runs/1839977840", ci.BuildInvocationId()) + assert.Equal(t, "https://github.com/bolo/tomato/Attestations/GitHubHostedActions@v1", ci.BuilderId()) + assert.Equal(t, "https://github.com/bolo/tomato/actions/runs/1839977840", ci.BuildInvocationId()) metadata := Metadata{ Arch: "X64", @@ -46,7 +46,7 @@ func TestCreateCIEnvironment(t *testing.T) { result := ci.UserDefinedParameters() assert.NotNil(t, result) assert.NotEmpty(t, "%s", result) - assert.Equal(t, "Salsa CI", ci.Context()) + assert.Equal(t, "tomato CI", ci.Context()) } diff --git a/pkg/vcs/github_test.go b/pkg/vcs/github_test.go index f7c972f..4fa76a4 100644 --- a/pkg/vcs/github_test.go +++ b/pkg/vcs/github_test.go @@ -15,8 +15,8 @@ func TestParseGithubContext(t *testing.T) { assert.Equal(t, "90dc9f2bc4007d1099a941ba3d408d2c896fe8dd", context.SHA) assert.Equal(t, "build", context.Job) assert.Equal(t, "refs/heads/main", context.Ref) - assert.Equal(t, "nais/salsa", context.Repository) - assert.Equal(t, "nais", context.RepositoryOwner) + assert.Equal(t, "bolo/tomato", context.Repository) + assert.Equal(t, "bolo", context.RepositoryOwner) assert.Equal(t, "1839977840", context.RunId) assert.Equal(t, "57", context.RunNumber) assert.Equal(t, "jdoe", context.Actor) diff --git a/pkg/vcs/resolve_context_test.go b/pkg/vcs/resolve_context_test.go index 6dd1a81..136b9a1 100644 --- a/pkg/vcs/resolve_context_test.go +++ b/pkg/vcs/resolve_context_test.go @@ -65,12 +65,12 @@ func TestResolveBuildContext(t *testing.T) { default: assert.NoError(t, err) assert.NotNil(t, resolved) - assert.Equal(t, "Salsa CI", resolved.Context()) + assert.Equal(t, "tomato CI", resolved.Context()) assert.Equal(t, map[string]string{}, resolved.CurrentFilteredEnvironment()) - assert.Equal(t, "https://github.com/nais/salsa/actions/runs/1839977840", resolved.BuildInvocationId()) + assert.Equal(t, "https://github.com/bolo/tomato/actions/runs/1839977840", resolved.BuildInvocationId()) assert.Equal(t, "https://github.com/Attestations/GitHubActionsWorkflow@v1", resolved.BuildType()) - assert.Equal(t, "https://github.com/nais/salsa", resolved.RepoUri()) - assert.Equal(t, "https://github.com/nais/salsa/Attestations/GitHubHostedActions@v1", resolved.BuilderId()) + assert.Equal(t, "https://github.com/bolo/tomato", resolved.RepoUri()) + assert.Equal(t, "https://github.com/bolo/tomato/Attestations/GitHubHostedActions@v1", resolved.BuilderId()) assert.Equal(t, "90dc9f2bc4007d1099a941ba3d408d2c896fe8dd", resolved.Sha()) assert.NotNil(t, resolved.UserDefinedParameters()) assert.NotEmpty(t, resolved.UserDefinedParameters()) diff --git a/pkg/vcs/testdata/github-context.json b/pkg/vcs/testdata/github-context.json index 24e222e..6bb0773 100644 --- a/pkg/vcs/testdata/github-context.json +++ b/pkg/vcs/testdata/github-context.json @@ -3,15 +3,15 @@ "job": "build", "ref": "refs/heads/main", "sha": "90dc9f2bc4007d1099a941ba3d408d2c896fe8dd", - "repository": "nais/salsa", - "repository_owner": "nais", - "repositoryUrl": "git://github.com/nais/salsa.git", + "repository": "bolo/tomato", + "repository_owner": "bolo", + "repositoryUrl": "git://github.com/bolo/tomato.git", "run_id": "1839977840", "run_number": "57", "retention_days": "90", "run_attempt": "1", "actor": "jdoe", - "workflow": "Salsa CI", + "workflow": "tomato CI", "head_ref": "", "base_ref": "", "event_name": "workflow_dispatch", @@ -36,10 +36,10 @@ "message": "test: add som printing in pipline", "timestamp": "2022-02-14T09:38:16+01:00", "tree_id": "2fbcdd01cdbd0367640bd7963a22a346eb6296f9", - "url": "https://github.com/nais/salsa/commit/90dc9f2bc4007d1099a941ba3d408d2c896fe8dd" + "url": "https://github.com/bolo/tomato/commit/90dc9f2bc4007d1099a941ba3d408d2c896fe8dd" } ], - "compare": "https://github.com/nais/salsa/compare/075693a03c7a...90dc9f2bc400", + "compare": "https://github.com/bolo/tomato/compare/075693a03c7a...90dc9f2bc400", "created": false, "deleted": false, "enterprise": { @@ -71,21 +71,21 @@ "message": "test: add som printing in pipline", "timestamp": "2022-02-14T09:38:16+01:00", "tree_id": "2fbcdd01cdbd0367640bd7963a22a346eb6296f9", - "url": "https://github.com/nais/salsa/commit/90dc9f2bc4007d1099a941ba3d408d2c896fe8dd" + "url": "https://github.com/bolo/tomato/commit/90dc9f2bc4007d1099a941ba3d408d2c896fe8dd" }, "organization": { "avatar_url": "https://avatars.githubusercontent.com/u/29488289?v=4", "description": "NAV Application Infrastructure Service", - "events_url": "https://api.github.com/orgs/nais/events", - "hooks_url": "https://api.github.com/orgs/nais/hooks", + "events_url": "https://api.github.com/orgs/bolo/events", + "hooks_url": "https://api.github.com/orgs/bolo/hooks", "id": 29488289, - "issues_url": "https://api.github.com/orgs/nais/issues", - "login": "nais", - "members_url": "https://api.github.com/orgs/nais/members{/member}", + "issues_url": "https://api.github.com/orgs/bolo/issues", + "login": "bolo", + "members_url": "https://api.github.com/orgs/bolo/members{/member}", "node_id": "MDEyOk9yZ2FuaXphdGlvbjI5NDg4Mjg5", - "public_members_url": "https://api.github.com/orgs/nais/public_members{/member}", - "repos_url": "https://api.github.com/orgs/nais/repos", - "url": "https://api.github.com/orgs/nais" + "public_members_url": "https://api.github.com/orgs/bolo/public_members{/member}", + "repos_url": "https://api.github.com/orgs/bolo/repos", + "url": "https://api.github.com/orgs/bolo" }, "pusher": { "email": "38552193+jdoe@users.noreply.github.com", @@ -94,51 +94,51 @@ "ref": "refs/heads/main", "repository": { "allow_forking": true, - "archive_url": "https://api.github.com/repos/nais/salsa/{archive_format}{/ref}", + "archive_url": "https://api.github.com/repos/bolo/tomato/{archive_format}{/ref}", "archived": false, - "assignees_url": "https://api.github.com/repos/nais/salsa/assignees{/user}", - "blobs_url": "https://api.github.com/repos/nais/salsa/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/nais/salsa/branches{/branch}", - "clone_url": "https://github.com/nais/salsa.git", - "collaborators_url": "https://api.github.com/repos/nais/salsa/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/nais/salsa/comments{/number}", - "commits_url": "https://api.github.com/repos/nais/salsa/commits{/sha}", - "compare_url": "https://api.github.com/repos/nais/salsa/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/nais/salsa/contents/{+path}", - "contributors_url": "https://api.github.com/repos/nais/salsa/contributors", + "assignees_url": "https://api.github.com/repos/bolo/tomato/assignees{/user}", + "blobs_url": "https://api.github.com/repos/bolo/tomato/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/bolo/tomato/branches{/branch}", + "clone_url": "https://github.com/bolo/tomato.git", + "collaborators_url": "https://api.github.com/repos/bolo/tomato/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/bolo/tomato/comments{/number}", + "commits_url": "https://api.github.com/repos/bolo/tomato/commits{/sha}", + "compare_url": "https://api.github.com/repos/bolo/tomato/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/bolo/tomato/contents/{+path}", + "contributors_url": "https://api.github.com/repos/bolo/tomato/contributors", "created_at": 1639493570, "default_branch": "main", - "deployments_url": "https://api.github.com/repos/nais/salsa/deployments", + "deployments_url": "https://api.github.com/repos/bolo/tomato/deployments", "description": "in line with the best from abroad", "disabled": false, - "downloads_url": "https://api.github.com/repos/nais/salsa/downloads", - "events_url": "https://api.github.com/repos/nais/salsa/events", + "downloads_url": "https://api.github.com/repos/bolo/tomato/downloads", + "events_url": "https://api.github.com/repos/bolo/tomato/events", "fork": false, "forks": 0, "forks_count": 0, - "forks_url": "https://api.github.com/repos/nais/salsa/forks", - "full_name": "nais/salsa", - "git_commits_url": "https://api.github.com/repos/nais/salsa/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/nais/salsa/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/nais/salsa/git/tags{/sha}", - "git_url": "git://github.com/nais/salsa.git", + "forks_url": "https://api.github.com/repos/bolo/tomato/forks", + "full_name": "bolo/tomato", + "git_commits_url": "https://api.github.com/repos/bolo/tomato/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/bolo/tomato/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/bolo/tomato/git/tags{/sha}", + "git_url": "git://github.com/bolo/tomato.git", "has_downloads": true, "has_issues": true, "has_pages": false, "has_projects": true, "has_wiki": true, "homepage": "", - "hooks_url": "https://api.github.com/repos/nais/salsa/hooks", - "html_url": "https://github.com/nais/salsa", + "hooks_url": "https://api.github.com/repos/bolo/tomato/hooks", + "html_url": "https://github.com/bolo/tomato", "id": 438292024, "is_template": false, - "issue_comment_url": "https://api.github.com/repos/nais/salsa/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/nais/salsa/issues/events{/number}", - "issues_url": "https://api.github.com/repos/nais/salsa/issues{/number}", - "keys_url": "https://api.github.com/repos/nais/salsa/keys{/key_id}", - "labels_url": "https://api.github.com/repos/nais/salsa/labels{/name}", + "issue_comment_url": "https://api.github.com/repos/bolo/tomato/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/bolo/tomato/issues/events{/number}", + "issues_url": "https://api.github.com/repos/bolo/tomato/issues{/number}", + "keys_url": "https://api.github.com/repos/bolo/tomato/keys{/key_id}", + "labels_url": "https://api.github.com/repos/bolo/tomato/labels{/name}", "language": "Go", - "languages_url": "https://api.github.com/repos/nais/salsa/languages", + "languages_url": "https://api.github.com/repos/bolo/tomato/languages", "license": { "key": "mit", "name": "MIT License", @@ -147,52 +147,52 @@ "url": "https://api.github.com/licenses/mit" }, "master_branch": "main", - "merges_url": "https://api.github.com/repos/nais/salsa/merges", - "milestones_url": "https://api.github.com/repos/nais/salsa/milestones{/number}", + "merges_url": "https://api.github.com/repos/bolo/tomato/merges", + "milestones_url": "https://api.github.com/repos/bolo/tomato/milestones{/number}", "mirror_url": null, - "name": "salsa", + "name": "tomato", "node_id": "R_kgDOGh_OOA", - "notifications_url": "https://api.github.com/repos/nais/salsa/notifications{?since,all,participating}", + "notifications_url": "https://api.github.com/repos/bolo/tomato/notifications{?since,all,participating}", "open_issues": 0, "open_issues_count": 0, - "organization": "nais", + "organization": "bolo", "owner": { "avatar_url": "https://avatars.githubusercontent.com/u/29488289?v=4", "email": null, - "events_url": "https://api.github.com/users/nais/events{/privacy}", - "followers_url": "https://api.github.com/users/nais/followers", - "following_url": "https://api.github.com/users/nais/following{/other_user}", - "gists_url": "https://api.github.com/users/nais/gists{/gist_id}", + "events_url": "https://api.github.com/users/bolo/events{/privacy}", + "followers_url": "https://api.github.com/users/bolo/followers", + "following_url": "https://api.github.com/users/bolo/following{/other_user}", + "gists_url": "https://api.github.com/users/bolo/gists{/gist_id}", "gravatar_id": "", - "html_url": "https://github.com/nais", + "html_url": "https://github.com/bolo", "id": 29488289, - "login": "nais", - "name": "nais", + "login": "bolo", + "name": "bolo", "node_id": "MDEyOk9yZ2FuaXphdGlvbjI5NDg4Mjg5", - "organizations_url": "https://api.github.com/users/nais/orgs", - "received_events_url": "https://api.github.com/users/nais/received_events", - "repos_url": "https://api.github.com/users/nais/repos", + "organizations_url": "https://api.github.com/users/bolo/orgs", + "received_events_url": "https://api.github.com/users/bolo/received_events", + "repos_url": "https://api.github.com/users/bolo/repos", "site_admin": false, - "starred_url": "https://api.github.com/users/nais/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/nais/subscriptions", + "starred_url": "https://api.github.com/users/bolo/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bolo/subscriptions", "type": "Organization", - "url": "https://api.github.com/users/nais" + "url": "https://api.github.com/users/bolo" }, "private": false, - "pulls_url": "https://api.github.com/repos/nais/salsa/pulls{/number}", + "pulls_url": "https://api.github.com/repos/bolo/tomato/pulls{/number}", "pushed_at": 1644827905, - "releases_url": "https://api.github.com/repos/nais/salsa/releases{/id}", + "releases_url": "https://api.github.com/repos/bolo/tomato/releases{/id}", "size": 588, - "ssh_url": "git@github.com:nais/salsa.git", + "ssh_url": "git@github.com:bolo/tomato.git", "stargazers": 0, "stargazers_count": 0, - "stargazers_url": "https://api.github.com/repos/nais/salsa/stargazers", - "statuses_url": "https://api.github.com/repos/nais/salsa/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/nais/salsa/subscribers", - "subscription_url": "https://api.github.com/repos/nais/salsa/subscription", - "svn_url": "https://github.com/nais/salsa", - "tags_url": "https://api.github.com/repos/nais/salsa/tags", - "teams_url": "https://api.github.com/repos/nais/salsa/teams", + "stargazers_url": "https://api.github.com/repos/bolo/tomato/stargazers", + "statuses_url": "https://api.github.com/repos/bolo/tomato/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/bolo/tomato/subscribers", + "subscription_url": "https://api.github.com/repos/bolo/tomato/subscription", + "svn_url": "https://github.com/bolo/tomato", + "tags_url": "https://api.github.com/repos/bolo/tomato/tags", + "teams_url": "https://api.github.com/repos/bolo/tomato/teams", "topics": [ "artifact", "integrity", @@ -200,9 +200,9 @@ "slsa", "software-supply-chain" ], - "trees_url": "https://api.github.com/repos/nais/salsa/git/trees{/sha}", + "trees_url": "https://api.github.com/repos/bolo/tomato/git/trees{/sha}", "updated_at": "2022-02-09T13:23:29Z", - "url": "https://github.com/nais/salsa", + "url": "https://github.com/bolo/tomato", "visibility": "public", "watchers": 0, "watchers_count": 0 @@ -235,7 +235,7 @@ "ref_protected": true, "ref_type": "branch", "secret_source": "Actions", - "workspace": "/home/runner/work/salsa/salsa", + "workspace": "/home/runner/work/tomato/tomato", "action": "__run_4", "event_path": "/home/runner/work/_temp/_github_workflow/event.json", "action_repository": "", diff --git a/pkg/vcs/testdata/pull-request-event.json b/pkg/vcs/testdata/pull-request-event.json new file mode 100644 index 0000000..504c102 --- /dev/null +++ b/pkg/vcs/testdata/pull-request-event.json @@ -0,0 +1,410 @@ +{ + "event": { + "action": "synchronize", + "after": "1010", + "before": "1009", + "enterprise": { + "avatar_url": "https://avatars.githubusercontent.com/b/371?v=4", + "created_at": "2019-06-26T11:17:54Z", + "description": "", + "html_url": "https://github.com/enterprises/BOGUS", + "id": 371, + "name": "BOGUS", + "node_id": "11=", + "slug": "BOGUS", + "updated_at": "2022-08-25T17:53:40Z", + "website_url": "https://BOGUS.no" + }, + "number": 3052, + "organization": { + "avatar_url": "https://avatars.githubusercontent.com/u/11848947?v=4", + "description": "BOGUS", + "events_url": "https://api.github.com/orgs/yolo/events", + "hooks_url": "https://api.github.com/orgs/yolo/hooks", + "id": 11848947, + "issues_url": "https://api.github.com/orgs/yolo/issues", + "login": "yolo", + "members_url": "https://api.github.com/orgs/yolo/members***/member}", + "node_id": "11", + "public_members_url": "https://api.github.com/orgs/yolo/public_members}/member***", + "repos_url": "https://api.github.com/orgs/yolo/repos", + "url": "https://api.github.com/orgs/yolo" + }, + "pull_request": { + "_links": { + "comments": { + "href": "https://api.github.com/repos/yolo/repo-name/issues/3052/comments" + }, + "commits": { + "href": "https://api.github.com/repos/yolo/repo-name/pulls/3052/commits" + }, + "html": { + "href": "https://github.com/yolo/repo-name/pull/3052" + }, + "issue": { + "href": "https://api.github.com/repos/yolo/repo-name/issues/3052" + }, + "review_comment": { + "href": "https://api.github.com/repos/yolo/repo-name/pulls/comments***/number***" + }, + "review_comments": { + "href": "https://api.github.com/repos/yolo/repo-name/pulls/3052/comments" + }, + "self": { + "href": "https://api.github.com/repos/yolo/repo-name/pulls/3052" + }, + "statuses": { + "href": "https://api.github.com/repos/yolo/repo-name/statuses/76fc244479bac1d1f4661e49055304eaace6bf32" + } + }, + "active_lock_reason": null, + "additions": 20, + "assignee": null, + "assignees": [], + "author_association": "CONTRIBUTOR", + "auto_merge": null, + "base": { + "label": "yolo:master", + "ref": "master", + "repo": { + "allow_auto_merge": true, + "allow_forking": true, + "allow_merge_commit": false, + "allow_rebase_merge": false, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/yolo/repo-name/***archive_format***/ref***", + "archived": false, + "assignees_url": "https://api.github.com/repos/yolo/repo-name/assignees***/user***", + "blobs_url": "https://api.github.com/repos/yolo/repo-name/git/blobs***/sha***", + "branches_url": "https://api.github.com/repos/yolo/repo-name/branches***/branch***", + "clone_url": "https://github.com/yolo/repo-name.git", + "collaborators_url": "https://api.github.com/repos/yolo/repo-name/collaborators***/collaborator***", + "comments_url": "https://api.github.com/repos/yolo/repo-name/comments***/number***", + "commits_url": "https://api.github.com/repos/yolo/repo-name/commits***/sha***", + "compare_url": "https://api.github.com/repos/yolo/repo-name/compare/***base***...***head***", + "contents_url": "https://api.github.com/repos/yolo/repo-name/contents/***+path***", + "contributors_url": "https://api.github.com/repos/yolo/repo-name/contributors", + "created_at": "2019-11-28T11:37:49Z", + "default_branch": "master", + "delete_branch_on_merge": true, + "deployments_url": "https://api.github.com/repos/yolo/repo-name/deployments", + "description": "Applikasjon for saksbehandling av barnetrygd", + "disabled": false, + "downloads_url": "https://api.github.com/repos/yolo/repo-name/downloads", + "events_url": "https://api.github.com/repos/yolo/repo-name/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/yolo/repo-name/forks", + "full_name": "yolo/repo-name", + "git_commits_url": "https://api.github.com/repos/yolo/repo-name/git/commits***/sha***", + "git_refs_url": "https://api.github.com/repos/yolo/repo-name/git/refs***/sha***", + "git_tags_url": "https://api.github.com/repos/yolo/repo-name/git/tags***/sha***", + "git_url": "git://github.com/yolo/repo-name.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": "", + "hooks_url": "https://api.github.com/repos/yolo/repo-name/hooks", + "html_url": "https://github.com/yolo/repo-name", + "id": 224639942, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/yolo/repo-name/issues/comments***/number***", + "issue_events_url": "https://api.github.com/repos/yolo/repo-name/issues/events***/number***", + "issues_url": "https://api.github.com/repos/yolo/repo-name/issues***/number***", + "keys_url": "https://api.github.com/repos/yolo/repo-name/keys***/key_id***", + "labels_url": "https://api.github.com/repos/yolo/repo-name/labels***/name***", + "language": "Kotlin", + "languages_url": "https://api.github.com/repos/yolo/repo-name/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "11", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/yolo/repo-name/merges", + "milestones_url": "https://api.github.com/repos/yolo/repo-name/milestones***/number***", + "mirror_url": null, + "name": "repo-name", + "node_id": "11=", + "notifications_url": "https://api.github.com/repos/yolo/repo-name/notifications***?since,all,participating***", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/11848947?v=4", + "events_url": "https://api.github.com/users/yolo/events***/privacy***", + "followers_url": "https://api.github.com/users/yolo/followers", + "following_url": "https://api.github.com/users/yolo/following***/other_user***", + "gists_url": "https://api.github.com/users/yolo/gists***/gist_id***", + "gravatar_id": "", + "html_url": "https://github.com/yolo", + "id": 11848947, + "login": "yolo", + "node_id": "11", + "organizations_url": "https://api.github.com/users/yolo/orgs", + "received_events_url": "https://api.github.com/users/yolo/received_events", + "repos_url": "https://api.github.com/users/yolo/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/yolo/starred***/owner***/repo***", + "subscriptions_url": "https://api.github.com/users/yolo/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/yolo" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/yolo/repo-name/pulls***/number***", + "pushed_at": "2022-11-17T07:46:40Z", + "releases_url": "https://api.github.com/repos/yolo/repo-name/releases***/id***", + "size": 15286, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:yolo/repo-name.git", + "stargazers_count": 9, + "stargazers_url": "https://api.github.com/repos/yolo/repo-name/stargazers", + "statuses_url": "https://api.github.com/repos/yolo/repo-name/statuses/***sha***", + "subscribers_url": "https://api.github.com/repos/yolo/repo-name/subscribers", + "subscription_url": "https://api.github.com/repos/yolo/repo-name/subscription", + "svn_url": "https://github.com/yolo/repo-name", + "tags_url": "https://api.github.com/repos/yolo/repo-name/tags", + "teams_url": "https://api.github.com/repos/yolo/repo-name/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/yolo/repo-name/git/trees***/sha***", + "updated_at": "2022-10-31T10:20:18Z", + "url": "https://api.github.com/repos/yolo/repo-name", + "use_squash_pr_title_as_default": false, + "visibility": "public", + "watchers": 9, + "watchers_count": 9, + "web_commit_signoff_required": false + }, + "sha": "1010", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/11848947?v=4", + "events_url": "https://api.github.com/users/yolo/events***/privacy***", + "followers_url": "https://api.github.com/users/yolo/followers", + "following_url": "https://api.github.com/users/yolo/following***/other_user***", + "gists_url": "https://api.github.com/users/yolo/gists***/gist_id***", + "gravatar_id": "", + "html_url": "https://github.com/yolo", + "id": 11848947, + "login": "yolo", + "node_id": "11", + "organizations_url": "https://api.github.com/users/yolo/orgs", + "received_events_url": "https://api.github.com/users/yolo/received_events", + "repos_url": "https://api.github.com/users/yolo/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/yolo/starred***/owner***/repo***", + "subscriptions_url": "https://api.github.com/users/yolo/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/yolo" + } + }, + "body": "### 💰 Hva skal gjøres, og hvorfor?rn[Favro](https://favro.com/organization/98c34fb974ce445eac854de0/1844bbac3b6605eacc8f5543?card=Tea-10405)rnrn### 🔎️ Er det noe spesielt du ønsker tilbakemelding om?rn_Er det noe du er usikker på eller ønsker å diskutere? Beskriv det gjerne her eller kommenter koden det gjelder._rnrn### ✅ Checklistrn_Har du husket alle punktene i listen?_rn- [ ] Jeg har testet mine endringer i henhold til akseptansekriteriene 🕵️rn- [ ] Jeg har config- eller sql-endringer. I så fall, husk manuell deploy til miljø for å verifisere endringene.rn- [ ] Jeg har skrevet tester. Hvis du ikke har skrevet tester, beskriv hvorfor under 👇rnrn_Jeg har ikke skrevet tester fordi:_rnrn### 💬 Ønsker du en muntlig gjennomgang?rn- [ ] Jarn- [ ] Neirn", + "changed_files": 1, + "closed_at": null, + "comments": 0, + "comments_url": "https://api.github.com/repos/yolo/repo-name/issues/3052/comments", + "commits": 17, + "commits_url": "https://api.github.com/repos/yolo/repo-name/pulls/3052/commits", + "created_at": "2022-11-15T09:43:21Z", + "deletions": 0, + "diff_url": "https://github.com/yolo/repo-name/pull/3052.diff", + "draft": true, + "head": { + "label": "yolo:salsa", + "ref": "salsa", + "repo": { + "allow_auto_merge": true, + "allow_forking": true, + "allow_merge_commit": false, + "allow_rebase_merge": false, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/yolo/repo-name/***archive_format***/ref***", + "archived": false, + "assignees_url": "https://api.github.com/repos/yolo/repo-name/assignees***/user***", + "blobs_url": "https://api.github.com/repos/yolo/repo-name/git/blobs***/sha***", + "branches_url": "https://api.github.com/repos/yolo/repo-name/branches***/branch***", + "clone_url": "https://github.com/yolo/repo-name.git", + "collaborators_url": "https://api.github.com/repos/yolo/repo-name/collaborators***/collaborator***", + "comments_url": "https://api.github.com/repos/yolo/repo-name/comments***/number***", + "commits_url": "https://api.github.com/repos/yolo/repo-name/commits***/sha***", + "compare_url": "https://api.github.com/repos/yolo/repo-name/compare/***base***...***head***", + "contents_url": "https://api.github.com/repos/yolo/repo-name/contents/***+path***", + "contributors_url": "https://api.github.com/repos/yolo/repo-name/contributors", + "created_at": "2019-11-28T11:37:49Z", + "default_branch": "master", + "delete_branch_on_merge": true, + "deployments_url": "https://api.github.com/repos/yolo/repo-name/deployments", + "description": "Applikasjon for saksbehandling av barnetrygd", + "disabled": false, + "downloads_url": "https://api.github.com/repos/yolo/repo-name/downloads", + "events_url": "https://api.github.com/repos/yolo/repo-name/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/yolo/repo-name/forks", + "full_name": "yolo/repo-name", + "git_commits_url": "https://api.github.com/repos/yolo/repo-name/git/commits***/sha***", + "git_refs_url": "https://api.github.com/repos/yolo/repo-name/git/refs***/sha***", + "git_tags_url": "https://api.github.com/repos/yolo/repo-name/git/tags***/sha***", + "git_url": "git://github.com/yolo/repo-name.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": "", + "hooks_url": "https://api.github.com/repos/yolo/repo-name/hooks", + "html_url": "https://github.com/yolo/repo-name", + "id": 224639942, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/yolo/repo-name/issues/comments***/number***", + "issue_events_url": "https://api.github.com/repos/yolo/repo-name/issues/events***/number***", + "issues_url": "https://api.github.com/repos/yolo/repo-name/issues***/number***", + "keys_url": "https://api.github.com/repos/yolo/repo-name/keys***/key_id***", + "labels_url": "https://api.github.com/repos/yolo/repo-name/labels***/name***", + "language": "Kotlin", + "languages_url": "https://api.github.com/repos/yolo/repo-name/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "11", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/yolo/repo-name/merges", + "milestones_url": "https://api.github.com/repos/yolo/repo-name/milestones***/number***", + "mirror_url": null, + "name": "repo-name", + "node_id": "11=", + "notifications_url": "https://api.github.com/repos/yolo/repo-name/notifications***?since,all,participating***", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/11848947?v=4", + "events_url": "https://api.github.com/users/yolo/events***/privacy***", + "followers_url": "https://api.github.com/users/yolo/followers", + "following_url": "https://api.github.com/users/yolo/following***/other_user***", + "gists_url": "https://api.github.com/users/yolo/gists***/gist_id***", + "gravatar_id": "", + "html_url": "https://github.com/yolo", + "id": 11848947, + "login": "yolo", + "node_id": "11", + "organizations_url": "https://api.github.com/users/yolo/orgs", + "received_events_url": "https://api.github.com/users/yolo/received_events", + "repos_url": "https://api.github.com/users/yolo/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/yolo/starred***/owner***/repo***", + "subscriptions_url": "https://api.github.com/users/yolo/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/yolo" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/yolo/repo-name/pulls***/number***", + "pushed_at": "2022-11-17T07:46:40Z", + "releases_url": "https://api.github.com/repos/yolo/repo-name/releases***/id***", + "size": 15286, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:yolo/repo-name.git", + "stargazers_count": 9, + "stargazers_url": "https://api.github.com/repos/yolo/repo-name/stargazers", + "statuses_url": "https://api.github.com/repos/yolo/repo-name/statuses/***sha***", + "subscribers_url": "https://api.github.com/repos/yolo/repo-name/subscribers", + "subscription_url": "https://api.github.com/repos/yolo/repo-name/subscription", + "svn_url": "https://github.com/yolo/repo-name", + "tags_url": "https://api.github.com/repos/yolo/repo-name/tags", + "teams_url": "https://api.github.com/repos/yolo/repo-name/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/yolo/repo-name/git/trees***/sha***", + "updated_at": "2022-10-31T10:20:18Z", + "url": "https://api.github.com/repos/yolo/repo-name", + "use_squash_pr_title_as_default": false, + "visibility": "public", + "watchers": 9, + "watchers_count": 9, + "web_commit_signoff_required": false + }, + "sha": "1010", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/11848947?v=4", + "events_url": "https://api.github.com/users/yolo/events***/privacy***", + "followers_url": "https://api.github.com/users/yolo/followers", + "following_url": "https://api.github.com/users/yolo/following***/other_user***", + "gists_url": "https://api.github.com/users/yolo/gists***/gist_id***", + "gravatar_id": "", + "html_url": "https://github.com/yolo", + "id": 11848947, + "login": "yolo", + "node_id": "11", + "organizations_url": "https://api.github.com/users/yolo/orgs", + "received_events_url": "https://api.github.com/users/yolo/received_events", + "repos_url": "https://api.github.com/users/yolo/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/yolo/starred***/owner***/repo***", + "subscriptions_url": "https://api.github.com/users/yolo/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/yolo" + } + }, + "html_url": "https://github.com/yolo/repo-name/pull/3052", + "id": 1122614687, + "issue_url": "https://api.github.com/repos/yolo/repo-name/issues/3052", + "labels": [], + "locked": false, + "maintainer_can_modify": false, + "merge_commit_sha": "1010", + "mergeable": null, + "mergeable_state": "unknown", + "merged": false, + "merged_at": null, + "merged_by": null, + "milestone": null, + "node_id": "11", + "number": 3052, + "patch_url": "https://github.com/yolo/repo-name/pull/3052.patch", + "rebaseable": null, + "requested_reviewers": [], + "requested_teams": [], + "review_comment_url": "https://api.github.com/repos/yolo/repo-name/pulls/comments***/number***", + "review_comments": 0, + "review_comments_url": "https://api.github.com/repos/yolo/repo-name/pulls/3052/comments", + "state": "open", + "statuses_url": "https://api.github.com/repos/yolo/repo-name/statuses/76fc244479bac1d1f4661e49055304eaace6bf32", + "title": "Testing salsa", + "updated_at": "2022-11-17T07:46:39Z", + "url": "https://api.github.com/repos/yolo/repo-name/pulls/3052", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/71336041?v=4", + "events_url": "https://api.github.com/users/bolo/events***/privacy***", + "followers_url": "https://api.github.com/users/bolo/followers", + "following_url": "https://api.github.com/users/bolo/following***/other_user***", + "gists_url": "https://api.github.com/users/bolo/gists***/gist_id***", + "gravatar_id": "", + "html_url": "https://github.com/bolo", + "id": 71336041, + "login": "bolo", + "node_id": "11", + "organizations_url": "https://api.github.com/users/bolo/orgs", + "received_events_url": "https://api.github.com/users/bolo/received_events", + "repos_url": "https://api.github.com/users/bolo/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bolo/starred***/owner***/repo***", + "subscriptions_url": "https://api.github.com/users/bolo/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bolo" + } + } + } +} \ No newline at end of file diff --git a/pkg/vcs/testdata/unknown-event.json b/pkg/vcs/testdata/unknown-event.json new file mode 100644 index 0000000..a2bc500 --- /dev/null +++ b/pkg/vcs/testdata/unknown-event.json @@ -0,0 +1,65 @@ +{ + "actor": "jdoe", + "workflow": "Salsa CI", + "head_ref": "", + "base_ref": "", + "event": { + "after": "d4cd018b2fe54d8308b78f2bb88db94ac57173ea", + "base_ref": null, + "before": "a88fd9ea948a6ea1278ebcfd4b238283a72e12b0", + "commits": [ + { + "author": { + "email": "john.doe@emal.com", + "name": "jDoe", + "username": "jDoe" + }, + "committer": { + "email": "john.doe@emal.com", + "name": "jDoe", + "username": "jDoe" + }, + "distinct": true, + "id": "d4cd018b2fe54d8308b78f2bb88db94ac57173ea", + "message": "master commit", + "timestamp": "2022-10-21T11:26:55+02:00", + "tree_id": "1eb5ac4d731daeb199755932a5a2e126e10c80cc", + "url": "https://github.com/yolo" + } + ], + "compare": "https://github.com/yolo/gandalf/compare/a88fd9ea948a...d4cd018b2fe5", + "created": false, + "deleted": false, + "enterprise": { + "avatar_url": "https://avatars.githubusercontent.com/b/371?v=4", + "created_at": "2019-06-26T11:17:54Z", + "description": "", + "html_url": "https://github.com/enterprises/BOGUS", + "id": 371, + "name": "BOGUS", + "node_id": "MDEwOkVudGVycHJpc2UzNzE=", + "slug": "BOGUS", + "updated_at": "2022-08-25T17:53:40Z", + "website_url": "https://BOGUS.no" + }, + "forced": false, + "other_commit": { + "author": { + "email": "john.doe@emal.com", + "name": "jDoe", + "username": "jDoe" + }, + "committer": { + "email": "john.doe@emal.com", + "name": "jDoe", + "username": "jDoe" + }, + "distinct": true, + "id": "d4cd018b2fe54d8308b78f2bb88db94ac57173ea", + "message": "master commit", + "timestamp": "2022-10-21T11:26:55+02:00", + "tree_id": "1eb5ac4d731daeb199755932a5a2e126e10c80cc", + "url": "https://github.com/yolo" + } + } +} \ No newline at end of file diff --git a/pkg/vcs/testdata/event-head-commit.json b/pkg/vcs/testdata/workflowrun-head-commit.json similarity index 83% rename from pkg/vcs/testdata/event-head-commit.json rename to pkg/vcs/testdata/workflowrun-head-commit.json index 599d2bc..be2ed92 100644 --- a/pkg/vcs/testdata/event-head-commit.json +++ b/pkg/vcs/testdata/workflowrun-head-commit.json @@ -24,23 +24,23 @@ "message": "master commit", "timestamp": "2022-10-21T11:26:55+02:00", "tree_id": "1eb5ac4d731daeb199755932a5a2e126e10c80cc", - "url": "https://github.com/navikt" + "url": "https://github.com/yolo" } ], - "compare": "https://github.com/navikt/gandalf/compare/a88fd9ea948a...d4cd018b2fe5", + "compare": "https://github.com/yolo/gandalf/compare/a88fd9ea948a...d4cd018b2fe5", "created": false, "deleted": false, "enterprise": { "avatar_url": "https://avatars.githubusercontent.com/b/371?v=4", "created_at": "2019-06-26T11:17:54Z", "description": "", - "html_url": "https://github.com/enterprises/nav", + "html_url": "https://github.com/enterprises/BOGUS", "id": 371, - "name": "NAV", + "name": "BOGUS", "node_id": "MDEwOkVudGVycHJpc2UzNzE=", - "slug": "nav", + "slug": "BOGUS", "updated_at": "2022-08-25T17:53:40Z", - "website_url": "https://nav.no" + "website_url": "https://BOGUS.no" }, "forced": false, "head_commit": { @@ -59,7 +59,7 @@ "message": "master commit", "timestamp": "2022-10-21T11:26:55+02:00", "tree_id": "1eb5ac4d731daeb199755932a5a2e126e10c80cc", - "url": "https://github.com/navikt" + "url": "https://github.com/yolo" } } } \ No newline at end of file