From 122ec1372bc90e4dc4410e2304989ef2cecb6857 Mon Sep 17 00:00:00 2001 From: realmarv Date: Mon, 17 Apr 2023 17:24:45 +0330 Subject: [PATCH] scripts/detectNotUsingGitPush1by1: improve Improve the detectNotUsingGitPush1by1.fsx script to detect wrong CI status of commits. If commit msg contains text "failing test" then it would be allowed to have broken CI, else CI should be green. Fixes https://github.com/nblockchain/conventions/issues/95 --- scripts/detectNotUsingGitPush1by1.fsx | 415 ++++++++++++++++++++++++++ 1 file changed, 415 insertions(+) diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index 5a8a983ac..ffb056ee5 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -566,6 +566,8 @@ let gitForkUser = parsedJsonObj.PullRequest.Head.User.Login let gitForkRepo = parsedJsonObj.PullRequest.Head.Repo.Name let gitRepo = $"{gitForkUser}/{gitForkRepo}" +Console.WriteLine $"Fork repository is: {gitRepo}" + type PRCommitsType = JsonProvider<""" [ @@ -879,6 +881,9 @@ let prCommits = let parsedPrCommitsJsonObj = PRCommitsType.Parse prCommitsJsonString parsedPrCommitsJsonObj |> Seq.map(fun commit -> commit.Sha) +Console.WriteLine + $"Pull request commits are: {Environment.NewLine}{String.concat Environment.NewLine prCommits}" + let hasCiStatus = prCommits |> Seq.map(fun commit -> @@ -919,3 +924,413 @@ if notUsedGitPush1by1 then Console.Error.WriteLine errMsg Environment.Exit 2 + +type CheckSuitesType = + JsonProvider<""" +{ + "total_count": 2, + "check_suites": [ + { + "id": 11157990057, + "node_id": "CS_kwDOIMpMhM8AAAACmRFqqQ", + "head_branch": "fSharpScriptsWithoutShebang-squashed2", + "head_sha": "86140764e7f95649a70f117067146d4a6b7c8201", + "status": "completed", + "conclusion": "success", + "url": "https://api.github.com/repos/realmarv/conventions/check-suites/11157990057", + "before": "b0d38475ff2e95f8f424c98a85efd39658d5ff15", + "after": "86140764e7f95649a70f117067146d4a6b7c8201", + "pull_requests": [ + ], + "app": { + "id": 15368, + "slug": "github-actions", + "node_id": "MDM6QXBwMTUzNjg=", + "owner": { + "login": "github", + "id": 9919, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", + "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github", + "html_url": "https://github.com/github", + "followers_url": "https://api.github.com/users/github/followers", + "following_url": "https://api.github.com/users/github/following{/other_user}", + "gists_url": "https://api.github.com/users/github/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github/subscriptions", + "organizations_url": "https://api.github.com/users/github/orgs", + "repos_url": "https://api.github.com/users/github/repos", + "events_url": "https://api.github.com/users/github/events{/privacy}", + "received_events_url": "https://api.github.com/users/github/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "GitHub Actions", + "description": "Automate your workflow from idea to production", + "external_url": "https://help.github.com/en/actions", + "html_url": "https://github.com/apps/github-actions", + "created_at": "2018-07-30T09:30:17Z", + "updated_at": "2019-12-10T19:04:12Z", + "permissions": { + "actions": "write", + "administration": "read", + "checks": "write", + "contents": "write", + "deployments": "write", + "discussions": "write", + "issues": "write", + "merge_queues": "write", + "metadata": "read", + "packages": "write", + "pages": "write", + "pull_requests": "write", + "repository_hooks": "write", + "repository_projects": "write", + "security_events": "write", + "statuses": "write", + "vulnerability_alerts": "read" + }, + "events": [ + "branch_protection_rule", + "check_run", + "check_suite", + "create", + "delete", + "deployment", + "deployment_status", + "discussion", + "discussion_comment", + "fork", + "gollum", + "issues", + "issue_comment", + "label", + "merge_group", + "milestone", + "page_build", + "project", + "project_card", + "project_column", + "public", + "pull_request", + "pull_request_review", + "pull_request_review_comment", + "push", + "registry_package", + "release", + "repository", + "repository_dispatch", + "status", + "watch", + "workflow_dispatch", + "workflow_run" + ] + }, + "created_at": "2023-02-23T12:10:48Z", + "updated_at": "2023-02-23T12:16:40Z", + "rerequestable": true, + "runs_rerequestable": false, + "latest_check_runs_count": 3, + "check_runs_url": "https://api.github.com/repos/realmarv/conventions/check-suites/11157990057/check-runs", + "head_commit": { + "id": "86140764e7f95649a70f117067146d4a6b7c8201", + "tree_id": "381222317743d7ccb6ae59ca9d4079c9f7ef882c", + "message": "FileConventions: add HasCorrectShebang function", + "timestamp": "2023-02-23T12:02:15Z", + "author": { + "name": "realmarv", + "email": "zahratehraninasab@gmail.com" + }, + "committer": { + "name": "realmarv", + "email": "zahratehraninasab@gmail.com" + } + }, + "repository": { + "id": 550128772, + "node_id": "R_kgDOIMpMhA", + "name": "conventions", + "full_name": "realmarv/conventions", + "private": false, + "owner": { + "login": "realmarv", + "id": 50144546, + "node_id": "MDQ6VXNlcjUwMTQ0NTQ2", + "avatar_url": "https://avatars.githubusercontent.com/u/50144546?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/realmarv", + "html_url": "https://github.com/realmarv", + "followers_url": "https://api.github.com/users/realmarv/followers", + "following_url": "https://api.github.com/users/realmarv/following{/other_user}", + "gists_url": "https://api.github.com/users/realmarv/gists{/gist_id}", + "starred_url": "https://api.github.com/users/realmarv/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/realmarv/subscriptions", + "organizations_url": "https://api.github.com/users/realmarv/orgs", + "repos_url": "https://api.github.com/users/realmarv/repos", + "events_url": "https://api.github.com/users/realmarv/events{/privacy}", + "received_events_url": "https://api.github.com/users/realmarv/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/realmarv/conventions", + "description": null, + "fork": true, + "url": "https://api.github.com/repos/realmarv/conventions", + "forks_url": "https://api.github.com/repos/realmarv/conventions/forks", + "keys_url": "https://api.github.com/repos/realmarv/conventions/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/realmarv/conventions/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/realmarv/conventions/teams", + "hooks_url": "https://api.github.com/repos/realmarv/conventions/hooks", + "issue_events_url": "https://api.github.com/repos/realmarv/conventions/issues/events{/number}", + "events_url": "https://api.github.com/repos/realmarv/conventions/events", + "assignees_url": "https://api.github.com/repos/realmarv/conventions/assignees{/user}", + "branches_url": "https://api.github.com/repos/realmarv/conventions/branches{/branch}", + "tags_url": "https://api.github.com/repos/realmarv/conventions/tags", + "blobs_url": "https://api.github.com/repos/realmarv/conventions/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/realmarv/conventions/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/realmarv/conventions/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/realmarv/conventions/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/realmarv/conventions/statuses/{sha}", + "languages_url": "https://api.github.com/repos/realmarv/conventions/languages", + "stargazers_url": "https://api.github.com/repos/realmarv/conventions/stargazers", + "contributors_url": "https://api.github.com/repos/realmarv/conventions/contributors", + "subscribers_url": "https://api.github.com/repos/realmarv/conventions/subscribers", + "subscription_url": "https://api.github.com/repos/realmarv/conventions/subscription", + "commits_url": "https://api.github.com/repos/realmarv/conventions/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/realmarv/conventions/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/realmarv/conventions/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/realmarv/conventions/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/realmarv/conventions/contents/{+path}", + "compare_url": "https://api.github.com/repos/realmarv/conventions/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/realmarv/conventions/merges", + "archive_url": "https://api.github.com/repos/realmarv/conventions/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/realmarv/conventions/downloads", + "issues_url": "https://api.github.com/repos/realmarv/conventions/issues{/number}", + "pulls_url": "https://api.github.com/repos/realmarv/conventions/pulls{/number}", + "milestones_url": "https://api.github.com/repos/realmarv/conventions/milestones{/number}", + "notifications_url": "https://api.github.com/repos/realmarv/conventions/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/realmarv/conventions/labels{/name}", + "releases_url": "https://api.github.com/repos/realmarv/conventions/releases{/id}", + "deployments_url": "https://api.github.com/repos/realmarv/conventions/deployments" + } + }, + { + "id": 11158210887, + "node_id": "CS_kwDOIMpMhM8AAAACmRTJRw", + "head_branch": "fSharpScriptsWithoutShebang-squashed2", + "head_sha": "86140764e7f95649a70f117067146d4a6b7c8201", + "status": "completed", + "conclusion": "success", + "url": "https://api.github.com/repos/realmarv/conventions/check-suites/11158210887", + "before": "b0d38475ff2e95f8f424c98a85efd39658d5ff15", + "after": "86140764e7f95649a70f117067146d4a6b7c8201", + "pull_requests": [ + ], + "app": { + "id": 15368, + "slug": "github-actions", + "node_id": "MDM6QXBwMTUzNjg=", + "owner": { + "login": "github", + "id": 9919, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", + "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github", + "html_url": "https://github.com/github", + "followers_url": "https://api.github.com/users/github/followers", + "following_url": "https://api.github.com/users/github/following{/other_user}", + "gists_url": "https://api.github.com/users/github/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github/subscriptions", + "organizations_url": "https://api.github.com/users/github/orgs", + "repos_url": "https://api.github.com/users/github/repos", + "events_url": "https://api.github.com/users/github/events{/privacy}", + "received_events_url": "https://api.github.com/users/github/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "GitHub Actions", + "description": "Automate your workflow from idea to production", + "external_url": "https://help.github.com/en/actions", + "html_url": "https://github.com/apps/github-actions", + "created_at": "2018-07-30T09:30:17Z", + "updated_at": "2019-12-10T19:04:12Z", + "permissions": { + "actions": "write", + "administration": "read", + "checks": "write", + "contents": "write", + "deployments": "write", + "discussions": "write", + "issues": "write", + "merge_queues": "write", + "metadata": "read", + "packages": "write", + "pages": "write", + "pull_requests": "write", + "repository_hooks": "write", + "repository_projects": "write", + "security_events": "write", + "statuses": "write", + "vulnerability_alerts": "read" + }, + "events": [ + "branch_protection_rule", + "check_run", + "check_suite", + "create", + "delete", + "deployment", + "deployment_status", + "discussion", + "discussion_comment", + "fork", + "gollum", + "issues", + "issue_comment", + "label", + "merge_group", + "milestone", + "page_build", + "project", + "project_card", + "project_column", + "public", + "pull_request", + "pull_request_review", + "pull_request_review_comment", + "push", + "registry_package", + "release", + "repository", + "repository_dispatch", + "status", + "watch", + "workflow_dispatch", + "workflow_run" + ] + }, + "created_at": "2023-02-23T12:21:33Z", + "updated_at": "2023-02-23T12:26:13Z", + "rerequestable": true, + "runs_rerequestable": false, + "latest_check_runs_count": 3, + "check_runs_url": "https://api.github.com/repos/realmarv/conventions/check-suites/11158210887/check-runs", + "head_commit": { + "id": "86140764e7f95649a70f117067146d4a6b7c8201", + "tree_id": "381222317743d7ccb6ae59ca9d4079c9f7ef882c", + "message": "FileConventions: add HasCorrectShebang function", + "timestamp": "2023-02-23T12:02:15Z", + "author": { + "name": "realmarv", + "email": "zahratehraninasab@gmail.com" + }, + "committer": { + "name": "realmarv", + "email": "zahratehraninasab@gmail.com" + } + }, + "repository": { + "id": 550128772, + "node_id": "R_kgDOIMpMhA", + "name": "conventions", + "full_name": "realmarv/conventions", + "private": false, + "owner": { + "login": "realmarv", + "id": 50144546, + "node_id": "MDQ6VXNlcjUwMTQ0NTQ2", + "avatar_url": "https://avatars.githubusercontent.com/u/50144546?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/realmarv", + "html_url": "https://github.com/realmarv", + "followers_url": "https://api.github.com/users/realmarv/followers", + "following_url": "https://api.github.com/users/realmarv/following{/other_user}", + "gists_url": "https://api.github.com/users/realmarv/gists{/gist_id}", + "starred_url": "https://api.github.com/users/realmarv/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/realmarv/subscriptions", + "organizations_url": "https://api.github.com/users/realmarv/orgs", + "repos_url": "https://api.github.com/users/realmarv/repos", + "events_url": "https://api.github.com/users/realmarv/events{/privacy}", + "received_events_url": "https://api.github.com/users/realmarv/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/realmarv/conventions", + "description": null, + "fork": true, + "url": "https://api.github.com/repos/realmarv/conventions", + "forks_url": "https://api.github.com/repos/realmarv/conventions/forks", + "keys_url": "https://api.github.com/repos/realmarv/conventions/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/realmarv/conventions/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/realmarv/conventions/teams", + "hooks_url": "https://api.github.com/repos/realmarv/conventions/hooks", + "issue_events_url": "https://api.github.com/repos/realmarv/conventions/issues/events{/number}", + "events_url": "https://api.github.com/repos/realmarv/conventions/events", + "assignees_url": "https://api.github.com/repos/realmarv/conventions/assignees{/user}", + "branches_url": "https://api.github.com/repos/realmarv/conventions/branches{/branch}", + "tags_url": "https://api.github.com/repos/realmarv/conventions/tags", + "blobs_url": "https://api.github.com/repos/realmarv/conventions/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/realmarv/conventions/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/realmarv/conventions/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/realmarv/conventions/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/realmarv/conventions/statuses/{sha}", + "languages_url": "https://api.github.com/repos/realmarv/conventions/languages", + "stargazers_url": "https://api.github.com/repos/realmarv/conventions/stargazers", + "contributors_url": "https://api.github.com/repos/realmarv/conventions/contributors", + "subscribers_url": "https://api.github.com/repos/realmarv/conventions/subscribers", + "subscription_url": "https://api.github.com/repos/realmarv/conventions/subscription", + "commits_url": "https://api.github.com/repos/realmarv/conventions/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/realmarv/conventions/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/realmarv/conventions/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/realmarv/conventions/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/realmarv/conventions/contents/{+path}", + "compare_url": "https://api.github.com/repos/realmarv/conventions/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/realmarv/conventions/merges", + "archive_url": "https://api.github.com/repos/realmarv/conventions/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/realmarv/conventions/downloads", + "issues_url": "https://api.github.com/repos/realmarv/conventions/issues{/number}", + "pulls_url": "https://api.github.com/repos/realmarv/conventions/pulls{/number}", + "milestones_url": "https://api.github.com/repos/realmarv/conventions/milestones{/number}", + "notifications_url": "https://api.github.com/repos/realmarv/conventions/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/realmarv/conventions/labels{/name}", + "releases_url": "https://api.github.com/repos/realmarv/conventions/releases{/id}", + "deployments_url": "https://api.github.com/repos/realmarv/conventions/deployments" + } + } + ] +} +"""> + +prCommits +|> Seq.iter(fun commit -> + + let url = + sprintf + "https://api.github.com/repos/%s/commits/%s/check-suites" + gitRepo + commit + + let checkSuitesJsonString = GitHubApiCall url accessToken + + let checkSuitesParsedJson = CheckSuitesType.Parse checkSuitesJsonString + + let commitMessage = + checkSuitesParsedJson.CheckSuites.[0] + .HeadCommit + .Message + + let status = checkSuitesParsedJson.CheckSuites.[0].Status + let conclusion = checkSuitesParsedJson.CheckSuites.[0].Conclusion + + if + status = "completed" && conclusion = "failure" + && not(commitMessage.Contains "failing test") + then + Console.Error.WriteLine + "Thanks for pushing commits 1 by 1, however, it has been detected that some of them to not be successful (or not be red when they add a failing test)" + + Environment.Exit 3 +)