From 32d3d6ba392ae8dbd4ae223518a5746e5659ccf9 Mon Sep 17 00:00:00 2001 From: naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Fri, 4 Feb 2022 21:54:49 +0000 Subject: [PATCH] :sparkles: Porting the shellscript to go Porting the shellscript to go Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> --- .github/workflows/tests.yaml | 56 ++++++++++ go.mod | 3 + main.go | 157 ++++++++++++++++++++++++++++ main_test.go | 197 +++++++++++++++++++++++++++++++++++ testdata/fork.json | 174 +++++++++++++++++++++++++++++++ testdata/incorrect.json | 174 +++++++++++++++++++++++++++++++ testdata/non-fork.json | 173 ++++++++++++++++++++++++++++++ 7 files changed, 934 insertions(+) create mode 100644 .github/workflows/tests.yaml create mode 100644 go.mod create mode 100644 main.go create mode 100644 main_test.go create mode 100644 testdata/fork.json create mode 100644 testdata/incorrect.json create mode 100644 testdata/non-fork.json diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..fc19dd9f --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,56 @@ +// Copyright 2022 Security Scorecard Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +name: CI-Tests +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: read-all + +jobs: + unit-tests: + name: Run unit tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest ] + + steps: + - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 #v2.4.0 + # https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds + - uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed #v2.1.7 + with: + # In order: + # * Module download cache + # * Build cache (Linux) + # * Build cache (Mac) + # * Build cache (Windows) + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 #v2.1.5 + with: + go-version: '1.17.x' + - name: Run Go tests + run: go test ./... + - name: Run Go tests w/ `-race` + run: go test -race ./... diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..bc012426 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/ossf/scorecard-action + +go 1.17 diff --git a/main.go b/main.go new file mode 100644 index 00000000..de603086 --- /dev/null +++ b/main.go @@ -0,0 +1,157 @@ +// Copyright 2022 Security Scorecard Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" +) + +// main is the entrypoint for the action. +func main() { + // TODO - This is a port of the entrypoint.sh script. + // This is still a work in progress. + if err := initalizeENVVariables(); err != nil { + panic(err) + } +} + +// initalizeENVVariables is a function to initialize the environment variables required for the action. +//nolint +func initalizeENVVariables() error { + /* + https://docs.github.com/en/actions/learn-github-actions/environment-variables + GITHUB_EVENT_PATH contains the json file for the event. + GITHUB_SHA contains the commit hash. + GITHUB_WORKSPACE contains the repo folder. + GITHUB_EVENT_NAME contains the event name. + GITHUB_ACTIONS is true in GitHub env. + */ + if err := os.Setenv("ENABLE_SARIF", "1"); err != nil { + return err + } + + if err := os.Setenv("ENABLE_LICENSE", "1"); err != nil { + return err + } + + if err := os.Setenv("ENABLE_DANGEROUS_WORKFLOW", "1"); err != nil { + return err + } + + if err := os.Setenv("SCORECARD_POLICY_FILE", "/policy.yml"); err != nil { + return err + } + + if result, exists := os.LookupEnv("INPUT_RESULTS_FILE"); !exists { + return fmt.Errorf("INPUT_RESULTS_FILE is not set") + } else { + if result == "" { + return fmt.Errorf("INPUT_RESULTS_FILE is empty") + } + if err := os.Setenv("SCORECARD_RESULTS_FILE", result); err != nil { + return err + } + } + + if result, exists := os.LookupEnv("INPUT_RESULTS_FORMAT"); !exists { + return fmt.Errorf("INPUT_RESULTS_FORMAT is not set") + } else { + if result == "" { + return fmt.Errorf("INPUT_RESULTS_FORMAT is empty") + } + if err := os.Setenv("SCORECARD_RESULTS_FORMAT", result); err != nil { + return err + } + } + + if result, exists := os.LookupEnv("INPUT_PUBLISH_RESULTS"); !exists { + return fmt.Errorf("INPUT_PUBLISH_RESULTS is not set") + } else { + if result == "" { + return fmt.Errorf("INPUT_PUBLISH_RESULTS is empty") + } + if err := os.Setenv("SCORECARD_PUBLISH_RESULTS", result); err != nil { + return err + } + } + + if err := os.Setenv("SCORECARD_BIN", "/scorecard"); err != nil { + return err + } + + if err := os.Setenv("ENABLED_CHECKS", ""); err != nil { + return err + } + return gitHubEventPath() +} + +// gitHubEventPath is a function to get the path to the GitHub event +// and sets the SCORECARD_IS_FORK environment variable. +func gitHubEventPath() error { + if result, exists := os.LookupEnv("GITHUB_EVENT_PATH"); !exists { + return fmt.Errorf("GITHUB_EVENT_PATH is not set") + } else { + if result == "" { + return fmt.Errorf("GITHUB_EVENT_PATH is empty") + } + if err := os.Setenv("GITHUB_EVENT_PATH", result); err != nil { + return err + } + + data, err := ioutil.ReadFile(result) + if err != nil { + return err + } + + if isFork, err := scorecardIsFork(string(data)); err != nil { + return err + } else { + if isFork { + if err := os.Setenv("SCORECARD_IS_FORK", "true"); err != nil { + return err + } + } else { + if err := os.Setenv("SCORECARD_IS_FORK", "false"); err != nil { + return err + } + } + } + } + return nil +} + +// scorecardIsFork is a function to check if the current repo is a fork. +func scorecardIsFork(ghEventPath string) (bool, error) { + if ghEventPath == "" { + return false, fmt.Errorf("ghEventPath is empty") + } + /* + https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#github_repository_is_fork + GITHUB_REPOSITORY_IS_FORK is true if the repository is a fork. + */ + type repo struct { + Repository struct { + Fork bool `json:"fork"` + } `json:"repository"` + } + var r repo + if err := json.Unmarshal([]byte(ghEventPath), &r); err != nil { + return false, err + } + + return r.Repository.Fork, nil +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 00000000..79b753b0 --- /dev/null +++ b/main_test.go @@ -0,0 +1,197 @@ +// Copyright 2022 Security Scorecard Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package main + +import ( + "io/ioutil" + "os" + "testing" +) + +func Test_scorecardIsFork(t *testing.T) { + type args struct { + ghEventPath string + } + tests := []struct { + name string + args args + want bool + wantErr bool + }{ + { + name: "No event data", + want: false, + wantErr: true, + }, + { + name: "Fork event", + args: args{ + ghEventPath: "./testdata/fork.json", + }, + want: true, + wantErr: false, + }, + { + name: "Non fork event", + args: args{ + ghEventPath: "./testdata/non-fork.json", + }, + want: false, + wantErr: false, + }, + { + name: "incorrect event", + args: args{ + ghEventPath: "./testdata/incorrect.json", + }, + want: false, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var data []byte + var err error + if tt.args.ghEventPath != "" { + data, err = ioutil.ReadFile(tt.args.ghEventPath) + if err != nil { + t.Errorf("Failed to open test data: %v", err) + } + } + + got, err := scorecardIsFork(string(data)) + if (err != nil) != tt.wantErr { + t.Errorf("%v", err) + t.Errorf("scorecardIsFork() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("scorecardIsFork() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_initalizeENVVariables(t *testing.T) { + tests := []struct { + name string + wantErr bool + inputresultsfileSet bool + inputresultsfile string + inputresultsFormatSet bool + inputresultsFormat string + inputPublishResultsSet bool + inputPublishResults string + githubEventPathSet bool + githubEventPath string + }{ + { + name: "Success", + wantErr: false, + inputresultsfileSet: true, + inputresultsfile: "./testdata/results.json", + inputresultsFormatSet: true, + inputresultsFormat: "json", + inputPublishResultsSet: true, + inputPublishResults: "true", + githubEventPathSet: true, + githubEventPath: "./testdata/fork.json", + }, + { + name: "Success - no results file", + wantErr: true, + inputresultsfileSet: false, + inputresultsfile: "", + inputresultsFormatSet: true, + inputresultsFormat: "json", + inputPublishResultsSet: true, + inputPublishResults: "true", + githubEventPathSet: true, + githubEventPath: "./testdata/fork.json", + }, + { + name: "Success - no results format", + wantErr: true, + inputresultsfileSet: true, + inputresultsfile: "./testdata/results.json", + inputresultsFormatSet: false, + inputresultsFormat: "", + inputPublishResultsSet: true, + inputPublishResults: "true", + githubEventPathSet: true, + githubEventPath: "./testdata/fork.json", + }, + { + name: "Success - no publish results", + wantErr: true, + inputresultsfileSet: true, + inputresultsfile: "./testdata/results.json", + inputresultsFormatSet: true, + inputresultsFormat: "json", + inputPublishResultsSet: false, + inputPublishResults: "", + githubEventPathSet: true, + githubEventPath: "./testdata/fork.json", + }, + { + name: "Success - no github event path", + wantErr: true, + inputresultsfileSet: true, + inputresultsfile: "./testdata/results.json", + inputresultsFormatSet: true, + inputresultsFormat: "json", + inputPublishResultsSet: true, + inputPublishResults: "true", + githubEventPathSet: false, + githubEventPath: "./testdata/fork.json", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.inputresultsfileSet { + os.Setenv("INPUT_RESULTS_FILE", tt.inputresultsfile) + } else { + os.Unsetenv("INPUT_RESULTS_FILE") + } + if tt.inputresultsFormatSet { + os.Setenv("INPUT_RESULTS_FORMAT", tt.inputresultsFormat) + } else { + os.Unsetenv("INPUT_RESULTS_FORMAT") + } + if tt.inputPublishResultsSet { + os.Setenv("INPUT_PUBLISH_RESULTS", tt.inputPublishResults) + } else { + os.Unsetenv("INPUT_PUBLISH_RESULTS") + } + if tt.githubEventPathSet { + os.Setenv("GITHUB_EVENT_PATH", tt.githubEventPath) + } else { + os.Unsetenv("GITHUB_EVENT_PATH") + } + if err := initalizeENVVariables(); (err != nil) != tt.wantErr { + t.Errorf("initalizeENVVariables() error = %v, wantErr %v", err, tt.wantErr) + } + + if os.Getenv("ENABLE_SARIF") == "" && os.Getenv("ENABLE_SARIF") != "1" { + t.Errorf("ENABLE_SARIF is not set") + } + if os.Getenv("ENABLE_LICENSE") == "" && os.Getenv("ENABLE_LICENSE") != "1" { + t.Errorf("ENABLE_LICENSE is not set") + } + if os.Getenv("ENABLE_DANGEROUS_WORKFLOW") == "" && os.Getenv("ENABLE_DANGEROUS_WORKFLOW") != "1" { + t.Errorf("ENABLE_DANGEROUS_WORKFLOW is not set") + } + }) + } +} diff --git a/testdata/fork.json b/testdata/fork.json new file mode 100644 index 00000000..d9cec7c4 --- /dev/null +++ b/testdata/fork.json @@ -0,0 +1,174 @@ +{ + "after": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "base_ref": null, + "before": "3d471fd36d7f1147843c69d68de35d321d36fe43", + "commits": [ + { + "author": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon", + "username": "laurentsimon" + }, + "committer": { + "email": "noreply@github.com", + "name": "GitHub", + "username": "web-flow" + }, + "distinct": true, + "id": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "message": "Update dummy", + "timestamp": "2022-01-10T14:24:44-08:00", + "tree_id": "91673de3f7984d11277da340d24b0187523bd283", + "url": "https://github.com/laurentsimon/scorecard-action-test-2/commit/aa0496aa6ed5102642f352a5c4ad3cf090017c76" + } + ], + "compare": "https://github.com/laurentsimon/scorecard-action-test-2/compare/3d471fd36d7f...aa0496aa6ed5", + "created": false, + "deleted": false, + "forced": false, + "head_commit": { + "author": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon", + "username": "laurentsimon" + }, + "committer": { + "email": "noreply@github.com", + "name": "GitHub", + "username": "web-flow" + }, + "distinct": true, + "id": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "message": "Update dummy", + "timestamp": "2022-01-10T14:24:44-08:00", + "tree_id": "91673de3f7984d11277da340d24b0187523bd283", + "url": "https://github.com/laurentsimon/scorecard-action-test-2/commit/aa0496aa6ed5102642f352a5c4ad3cf090017c76" + }, + "pusher": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon" + }, + "ref": "refs/heads/main", + "repository": { + "allow_forking": true, + "archive_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/assignees{/user}", + "blobs_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/branches{/branch}", + "clone_url": "https://github.com/laurentsimon/scorecard-action-test-2.git", + "collaborators_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/comments{/number}", + "commits_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/commits{/sha}", + "compare_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/contents/{+path}", + "contributors_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/contributors", + "created_at": 1636137447, + "default_branch": "main", + "deployments_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/downloads", + "events_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/events", + "fork": true, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/forks", + "full_name": "laurentsimon/scorecard-action-test-2", + "git_commits_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/tags{/sha}", + "git_url": "git://github.com/laurentsimon/scorecard-action-test-2.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/hooks", + "html_url": "https://github.com/laurentsimon/scorecard-action-test-2", + "id": 425049966, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues/events{/number}", + "issues_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues{/number}", + "keys_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/keys{/key_id}", + "labels_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/labels{/name}", + "language": null, + "languages_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/languages", + "license": null, + "master_branch": "main", + "merges_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/merges", + "milestones_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/milestones{/number}", + "mirror_url": null, + "name": "scorecard-action-test-2", + "node_id": "R_kgDOGVW_bg", + "notifications_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/notifications{?since,all,participating}", + "open_issues": 0, + "open_issues_count": 0, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/64505099?v=4", + "email": "64505099+laurentsimon@users.noreply.github.com", + "events_url": "https://api.github.com/users/laurentsimon/events{/privacy}", + "followers_url": "https://api.github.com/users/laurentsimon/followers", + "following_url": "https://api.github.com/users/laurentsimon/following{/other_user}", + "gists_url": "https://api.github.com/users/laurentsimon/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/laurentsimon", + "id": 64505099, + "login": "laurentsimon", + "name": "laurentsimon", + "node_id": "MDQ6VXNlcjY0NTA1MDk5", + "organizations_url": "https://api.github.com/users/laurentsimon/orgs", + "received_events_url": "https://api.github.com/users/laurentsimon/received_events", + "repos_url": "https://api.github.com/users/laurentsimon/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/laurentsimon/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/laurentsimon/subscriptions", + "type": "User", + "url": "https://api.github.com/users/laurentsimon" + }, + "private": true, + "pulls_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/pulls{/number}", + "pushed_at": 1641853484, + "releases_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/releases{/id}", + "size": 315, + "ssh_url": "git@github.com:laurentsimon/scorecard-action-test-2.git", + "stargazers": 0, + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/stargazers", + "statuses_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/subscribers", + "subscription_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/subscription", + "svn_url": "https://github.com/laurentsimon/scorecard-action-test-2", + "tags_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/tags", + "teams_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/trees{/sha}", + "updated_at": "2022-01-10T22:16:01Z", + "url": "https://github.com/laurentsimon/scorecard-action-test-2", + "visibility": "private", + "watchers": 0, + "watchers_count": 0 + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/64505099?v=4", + "events_url": "https://api.github.com/users/laurentsimon/events{/privacy}", + "followers_url": "https://api.github.com/users/laurentsimon/followers", + "following_url": "https://api.github.com/users/laurentsimon/following{/other_user}", + "gists_url": "https://api.github.com/users/laurentsimon/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/laurentsimon", + "id": 64505099, + "login": "laurentsimon", + "node_id": "MDQ6VXNlcjY0NTA1MDk5", + "organizations_url": "https://api.github.com/users/laurentsimon/orgs", + "received_events_url": "https://api.github.com/users/laurentsimon/received_events", + "repos_url": "https://api.github.com/users/laurentsimon/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/laurentsimon/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/laurentsimon/subscriptions", + "type": "User", + "url": "https://api.github.com/users/laurentsimon" + } +} diff --git a/testdata/incorrect.json b/testdata/incorrect.json new file mode 100644 index 00000000..ebb333ea --- /dev/null +++ b/testdata/incorrect.json @@ -0,0 +1,174 @@ +{ + "after": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "base_ref": null, + "before": "3d471fd36d7f1147843c69d68de35d321d36fe43", + "commits": [ + { + "author": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon", + "username": "laurentsimon" + }, + "committer": { + "email": "noreply@github.com", + "name": "GitHub", + "username": "web-flow" + }, + "distinct": true, + "id": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "message": "Update dummy", + "timestamp": "2022-01-10T14:24:44-08:00", + "tree_id": "91673de3f7984d11277da340d24b0187523bd283", + "url": "https://github.com/laurentsimon/scorecard-action-test-2/commit/aa0496aa6ed5102642f352a5c4ad3cf090017c76" + } + ], + "compare": "https://github.com/laurentsimon/scorecard-action-test-2/compare/3d471fd36d7f...aa0496aa6ed5", + "created": false, + "deleted": false, + "forced": false, + "head_commit": { + "author": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon", + "username": "laurentsimon" + }, + "committer": { + "email": "noreply@github.com", + "name": "GitHub", + "username": "web-flow" + }, + "distinct": true, + "id": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "message": "Update dummy", + "timestamp": "2022-01-10T14:24:44-08:00", + "tree_id": "91673de3f7984d11277da340d24b0187523bd283", + "url": "https://github.com/laurentsimon/scorecard-action-test-2/commit/aa0496aa6ed5102642f352a5c4ad3cf090017c76" + }, + "pusher": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon" + }, + "ref": "refs/heads/main", + "repository": { + "allow_forking": true, + "archive_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/assignees{/user}", + "blobs_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/branches{/branch}", + "clone_url": "https://github.com/laurentsimon/scorecard-action-test-2.git", + "collaborators_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/comments{/number}", + "commits_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/commits{/sha}", + "compare_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/contents/{+path}", + "contributors_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/contributors", + "created_at": 1636137447, + "default_branch": "main", + "deployments_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/downloads", + "events_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/events", + "fork": true, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/forks", + "full_name": "laurentsimon/scorecard-action-test-2", + "git_commits_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/tags{/sha}", + "git_url": "git://github.com/laurentsimon/scorecard-action-test-2.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/hooks", + "html_url": "https://github.com/laurentsimon/scorecard-action-test-2", + "id": 425049966, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues/events{/number}", + "issues_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues{/number}", + "keys_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/keys{/key_id}", + "labels_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/labels{/name}", + "language": null, + "languages_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/languages", + "license": null, + "master_branch": "main", + "merges_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/merges", + "milestones_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/milestones{/number}", + "mirror_url": null, + "name": "scorecard-action-test-2", + "node_id": "R_kgDOGVW_bg", + "notifications_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/notifications{?since,all,participating}", + "open_issues": 0, + "open_issues_count": 0, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/64505099?v=4", + "email": "64505099+laurentsimon@users.noreply.github.com", + "events_url": "https://api.github.com/users/laurentsimon/events{/privacy}", + "followers_url": "https://api.github.com/users/laurentsimon/followers", + "following_url": "https://api.github.com/users/laurentsimon/following{/other_user}", + "gists_url": "https://api.github.com/users/laurentsimon/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/laurentsimon", + "id": 64505099, + "login": "laurentsimon", + "name": "laurentsimon", + "node_id": "MDQ6VXNlcjY0NTA1MDk5", + "organizations_url": "https://api.github.com/users/laurentsimon/orgs", + "received_events_url": "https://api.github.com/users/laurentsimon/received_events", + "repos_url": "https://api.github.com/users/laurentsimon/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/laurentsimon/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/laurentsimon/subscriptions", + "type": "User", + "url": "https://api.github.com/users/laurentsimon" + }, + "private": true, + "pulls_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/pulls{/number}", + "pushed_at": 1641853484, + "releases_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/releases{/id}", + "size": 315, + "ssh_url": "git@github.com:laurentsimon/scorecard-action-test-2.git", + "stargazers": 0, + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/stargazers", + "statuses_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/subscribers", + "subscription_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/subscription", + "svn_url": "https://github.com/laurentsimon/scorecard-action-test-2", + "tags_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/tags", + "teams_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/trees{/sha}", + "updated_at": "2022-01-10T22:16:01Z", + "url": "https://github.com/laurentsimon/scorecard-action-test-2", + "visibility": "private", + "watchers": 0, + "watchers_count": 0 + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/64505099?v=4", + "events_url": "https://api.github.com/users/laurentsimon/events{/privacy}", + "followers_url": "https://api.github.com/users/laurentsimon/followers", + "following_url": "https://api.github.com/users/laurentsimon/following{/other_user}", + "gists_url": "https://api.github.com/users/laurentsimon/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/laurentsimon", + "id": 64505099, + "login": "laurentsimon", + "node_id": "MDQ6VXNlcjY0NTA1MDk5", + "organizations_url": "https://api.github.com/users/laurentsimon/orgs", + "received_events_url": "https://api.github.com/users/laurentsimon/received_events", + "repos_url": "https://api.github.com/users/laurentsimon/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/laurentsimon/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/laurentsimon/subscriptions", + "type": "User", + "url": "https://api.github.com/users/laurentsimon" + } + diff --git a/testdata/non-fork.json b/testdata/non-fork.json new file mode 100644 index 00000000..e036752d --- /dev/null +++ b/testdata/non-fork.json @@ -0,0 +1,173 @@ +{ + "after": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "base_ref": null, + "before": "3d471fd36d7f1147843c69d68de35d321d36fe43", + "commits": [ + { + "author": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon", + "username": "laurentsimon" + }, + "committer": { + "email": "noreply@github.com", + "name": "GitHub", + "username": "web-flow" + }, + "distinct": true, + "id": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "message": "Update dummy", + "timestamp": "2022-01-10T14:24:44-08:00", + "tree_id": "91673de3f7984d11277da340d24b0187523bd283", + "url": "https://github.com/laurentsimon/scorecard-action-test-2/commit/aa0496aa6ed5102642f352a5c4ad3cf090017c76" + } + ], + "compare": "https://github.com/laurentsimon/scorecard-action-test-2/compare/3d471fd36d7f...aa0496aa6ed5", + "created": false, + "deleted": false, + "forced": false, + "head_commit": { + "author": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon", + "username": "laurentsimon" + }, + "committer": { + "email": "noreply@github.com", + "name": "GitHub", + "username": "web-flow" + }, + "distinct": true, + "id": "aa0496aa6ed5102642f352a5c4ad3cf090017c76", + "message": "Update dummy", + "timestamp": "2022-01-10T14:24:44-08:00", + "tree_id": "91673de3f7984d11277da340d24b0187523bd283", + "url": "https://github.com/laurentsimon/scorecard-action-test-2/commit/aa0496aa6ed5102642f352a5c4ad3cf090017c76" + }, + "pusher": { + "email": "64505099+laurentsimon@users.noreply.github.com", + "name": "laurentsimon" + }, + "ref": "refs/heads/main", + "repository": { + "allow_forking": true, + "archive_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/assignees{/user}", + "blobs_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/branches{/branch}", + "clone_url": "https://github.com/laurentsimon/scorecard-action-test-2.git", + "collaborators_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/comments{/number}", + "commits_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/commits{/sha}", + "compare_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/contents/{+path}", + "contributors_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/contributors", + "created_at": 1636137447, + "default_branch": "main", + "deployments_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/downloads", + "events_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/events", + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/forks", + "full_name": "laurentsimon/scorecard-action-test-2", + "git_commits_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/tags{/sha}", + "git_url": "git://github.com/laurentsimon/scorecard-action-test-2.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/hooks", + "html_url": "https://github.com/laurentsimon/scorecard-action-test-2", + "id": 425049966, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues/events{/number}", + "issues_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/issues{/number}", + "keys_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/keys{/key_id}", + "labels_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/labels{/name}", + "language": null, + "languages_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/languages", + "license": null, + "master_branch": "main", + "merges_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/merges", + "milestones_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/milestones{/number}", + "mirror_url": null, + "name": "scorecard-action-test-2", + "node_id": "R_kgDOGVW_bg", + "notifications_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/notifications{?since,all,participating}", + "open_issues": 0, + "open_issues_count": 0, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/64505099?v=4", + "email": "64505099+laurentsimon@users.noreply.github.com", + "events_url": "https://api.github.com/users/laurentsimon/events{/privacy}", + "followers_url": "https://api.github.com/users/laurentsimon/followers", + "following_url": "https://api.github.com/users/laurentsimon/following{/other_user}", + "gists_url": "https://api.github.com/users/laurentsimon/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/laurentsimon", + "id": 64505099, + "login": "laurentsimon", + "name": "laurentsimon", + "node_id": "MDQ6VXNlcjY0NTA1MDk5", + "organizations_url": "https://api.github.com/users/laurentsimon/orgs", + "received_events_url": "https://api.github.com/users/laurentsimon/received_events", + "repos_url": "https://api.github.com/users/laurentsimon/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/laurentsimon/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/laurentsimon/subscriptions", + "type": "User", + "url": "https://api.github.com/users/laurentsimon" + }, + "private": true, + "pulls_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/pulls{/number}", + "pushed_at": 1641853484, + "releases_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/releases{/id}", + "size": 315, + "ssh_url": "git@github.com:laurentsimon/scorecard-action-test-2.git", + "stargazers": 0, + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/stargazers", + "statuses_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/subscribers", + "subscription_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/subscription", + "svn_url": "https://github.com/laurentsimon/scorecard-action-test-2", + "tags_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/tags", + "teams_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/laurentsimon/scorecard-action-test-2/git/trees{/sha}", + "updated_at": "2022-01-10T22:16:01Z", + "url": "https://github.com/laurentsimon/scorecard-action-test-2", + "visibility": "private", + "watchers": 0, + "watchers_count": 0 + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/64505099?v=4", + "events_url": "https://api.github.com/users/laurentsimon/events{/privacy}", + "followers_url": "https://api.github.com/users/laurentsimon/followers", + "following_url": "https://api.github.com/users/laurentsimon/following{/other_user}", + "gists_url": "https://api.github.com/users/laurentsimon/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/laurentsimon", + "id": 64505099, + "login": "laurentsimon", + "node_id": "MDQ6VXNlcjY0NTA1MDk5", + "organizations_url": "https://api.github.com/users/laurentsimon/orgs", + "received_events_url": "https://api.github.com/users/laurentsimon/received_events", + "repos_url": "https://api.github.com/users/laurentsimon/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/laurentsimon/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/laurentsimon/subscriptions", + "type": "User", + "url": "https://api.github.com/users/laurentsimon" + } +}