Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically assign PR reviewers #4

Merged
merged 13 commits into from
Aug 7, 2020
Merged

Automatically assign PR reviewers #4

merged 13 commits into from
Aug 7, 2020

Conversation

bartekpacia
Copy link
Contributor

Synopsis

This PR is aiming to add the functionality described here.

Help needed

I'm not yet sure how to get the list of modified files as a simple array of strings from git.

cc @mcornella @larson-carter @awasum

@bartekpacia bartekpacia marked this pull request as draft July 9, 2020 23:26
@gittysachin
Copy link

I'm not yet sure how to get the list of modified files as a simple array of strings from git.

You can use files=$(git ls-files -m) to get the array of modifies files.

@bartekpacia
Copy link
Contributor Author

@gittysachin Thank you! I'll try it out later today.

@mcornella
Copy link
Member

I think we can make this a pure Node solution.

Let's start with getting the CODEOWNERS file: we can use context.github.repos.getContents to get the CODEOWNERS file contents.

To get the list of files modified in the PR, we can use context.github.pulls.listFiles.

Then, for each file, the algorithm should look in the CODEOWNERS file in the same way that GitHub does it, i.e. the last match takes precedence.

The listFiles method is paginated to 30 files per page by default; we could set a hard limit to how many we process, and more than that we just ignore. I've sorted commits in the repository by how many files they changed, and most fit inside one page of the listFiles method (first column: number of changed files, second column: commit ID):

Details
0 bed0344627db7cd2bf2222e8424fde7f06fb088d
1 55a98fc06d9ea9d003683dec5aae6cb6b0130ab0
2 83f61949292b865a7962f1f0a4a8c0fc6350f313
3 8fe48793b525c21580ccfa8ee11af89fbd505bb0
4 7afaee858a4ae5a8d0d8c1f5fe150979842ebefc
5 5ea25e6736430ab5b8439d11b2e9a837a803771b
6 67b5bfaaa316212221a01d4fe2eedcd0fc64c230
7 587b5545803a40bc5dcff81f7fa79d84879b27fd
8 95d795e8cad7d1a754dfad520309d7a41b69275f
9 4d940109e3c2a81ca44df1dd6e807b7a5538fff8
10 993e05da50543b9c2dcc5e4fedb93afd1c8b020c
11 7936bbbd5a3895caa7153e4d03740ac12a333862
12 1ba0af650ac575a7d35b10146d2e7a7b3b2e2ae6
13 2193135ebc4ce0778ff6949b448e4526dbd34284
17 6496acf58bf8531809490b52e34811f74a27cc7c
21 b80b1a1e8b30e5f2a7c4977019cf56e72c434037
24 c249c69065f1216bd83f5bd92e87f560e42675fb
25 e2d157d5895717e983e5cc4e5df792a6a5dbe0ac
28 4c292ea2b023a331dcf1af5644487f2272d24a4d
74 610b2529d2213a70e3d1153a9baf046c22f298b9
102 19b925e741fa46d2222210469a4dffc34a634ebd

We can also get the requested reviewers of a PR via the requested_reviewers field in the payload JSON (see below). After all that is computed, we can request a review to multiple users with context.github.pulls.requestReviewers.

Note: owner and repo should not be hardcoded, but use the appropriate fields of the context.payload object. If it makes things easier, here's the payload for a pull request synchronize event (when modifying the commits of the PR branch):

Details
{
  "action": "synchronize",
  "number": 9102,
  "pull_request": {
    "url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/9102",
    "id": 447750222,
    "node_id": "MDExOlB1bGxSZXF1ZXN0NDQ3NzUwMjIy",
    "html_url": "https://github.com/ohmyzsh/ohmyzsh/pull/9102",
    "diff_url": "https://github.com/ohmyzsh/ohmyzsh/pull/9102.diff",
    "patch_url": "https://github.com/ohmyzsh/ohmyzsh/pull/9102.patch",
    "issue_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/9102",
    "number": 9102,
    "state": "open",
    "locked": false,
    "title": "add never option no confirmation prompt",
    "user": {
      "login": "jakobhellermann",
      "id": 22177966,
      "node_id": "MDQ6VXNlcjIyMTc3OTY2",
      "avatar_url": "https://avatars2.githubusercontent.com/u/22177966?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/jakobhellermann",
      "html_url": "https://github.com/jakobhellermann",
      "followers_url": "https://api.github.com/users/jakobhellermann/followers",
      "following_url": "https://api.github.com/users/jakobhellermann/following{/other_user}",
      "gists_url": "https://api.github.com/users/jakobhellermann/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/jakobhellermann/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/jakobhellermann/subscriptions",
      "organizations_url": "https://api.github.com/users/jakobhellermann/orgs",
      "repos_url": "https://api.github.com/users/jakobhellermann/repos",
      "events_url": "https://api.github.com/users/jakobhellermann/events{/privacy}",
      "received_events_url": "https://api.github.com/users/jakobhellermann/received_events",
      "type": "User",
      "site_admin": false
    },
    "body": "## Standards checklist:\r\n\r\n- [x] The PR title is descriptive.\r\n- [x] The PR doesn't replicate another PR which is already open.\r\n- [x] I have read the contribution guide and followed all the instructions.\r\n- [x] The code follows the code style guide detailed in the wiki.\r\n- [x] The code is mine or it's from somewhere with an MIT-compatible license.\r\n- [x] The code is efficient, to the best of my ability, and does not waste computer resources.\r\n- [x] The code is stable and I have tested it myself, to the best of my abilities.\r\n\r\n## Changes:\r\n\r\n- change prompt from `Source it? ([Y]es/[n]o/[a]lways)` to  `Source it? ([Y]es/[n]o/[a]lways/n[e]ver)` (I couldn't find a synonym to never which doesn't start with **n**, suggestions welcome)\r\n- add parallel to `ZSH_DOTENV_ALLOWED_LIST`: `ZSH_DOTENV_DISALLOWED_LIST`\r\n- write disallowed dirs to that file and skip sourcing if directory is in that file\r\n- update README\r\n\r\n---\r\n\r\nfixes #9101 ",
    "created_at": "2020-07-11T10:21:20Z",
    "updated_at": "2020-07-11T12:02:38Z",
    "closed_at": null,
    "merged_at": null,
    "merge_commit_sha": "951665d553e5f46dbe2a1076cd0f5bd490c9c079",
    "assignee": null,
    "assignees": [

    ],
    "requested_reviewers": [

    ],
    "requested_teams": [

    ],
    "labels": [
      {
        "id": 108094,
        "node_id": "MDU6TGFiZWwxMDgwOTQ=",
        "url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/labels/Area:%20plugin",
        "name": "Area: plugin",
        "color": "0d5b96",
        "default": false,
        "description": "Issue or PR related to a plugin"
      },
      {
        "id": 349611826,
        "node_id": "MDU6TGFiZWwzNDk2MTE4MjY=",
        "url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/labels/Type:%20documentation",
        "name": "Type: documentation",
        "color": "0e8a16",
        "default": false,
        "description": "Documentation issue or Pull Request"
      }
    ],
    "milestone": null,
    "draft": false,
    "commits_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/9102/commits",
    "review_comments_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/9102/comments",
    "review_comment_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/comments{/number}",
    "comments_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/9102/comments",
    "statuses_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/statuses/d771734400f1ffaf7e0bb703cc3df1676241ecc6",
    "head": {
      "label": "jakobhellermann:dotenv-confirmation-never",
      "ref": "dotenv-confirmation-never",
      "sha": "d771734400f1ffaf7e0bb703cc3df1676241ecc6",
      "user": {
        "login": "jakobhellermann",
        "id": 22177966,
        "node_id": "MDQ6VXNlcjIyMTc3OTY2",
        "avatar_url": "https://avatars2.githubusercontent.com/u/22177966?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/jakobhellermann",
        "html_url": "https://github.com/jakobhellermann",
        "followers_url": "https://api.github.com/users/jakobhellermann/followers",
        "following_url": "https://api.github.com/users/jakobhellermann/following{/other_user}",
        "gists_url": "https://api.github.com/users/jakobhellermann/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/jakobhellermann/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/jakobhellermann/subscriptions",
        "organizations_url": "https://api.github.com/users/jakobhellermann/orgs",
        "repos_url": "https://api.github.com/users/jakobhellermann/repos",
        "events_url": "https://api.github.com/users/jakobhellermann/events{/privacy}",
        "received_events_url": "https://api.github.com/users/jakobhellermann/received_events",
        "type": "User",
        "site_admin": false
      },
      "repo": {
        "id": 278834352,
        "node_id": "MDEwOlJlcG9zaXRvcnkyNzg4MzQzNTI=",
        "name": "ohmyzsh",
        "full_name": "jakobhellermann/ohmyzsh",
        "private": false,
        "owner": {
          "login": "jakobhellermann",
          "id": 22177966,
          "node_id": "MDQ6VXNlcjIyMTc3OTY2",
          "avatar_url": "https://avatars2.githubusercontent.com/u/22177966?v=4",
          "gravatar_id": "",
          "url": "https://api.github.com/users/jakobhellermann",
          "html_url": "https://github.com/jakobhellermann",
          "followers_url": "https://api.github.com/users/jakobhellermann/followers",
          "following_url": "https://api.github.com/users/jakobhellermann/following{/other_user}",
          "gists_url": "https://api.github.com/users/jakobhellermann/gists{/gist_id}",
          "starred_url": "https://api.github.com/users/jakobhellermann/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/jakobhellermann/subscriptions",
          "organizations_url": "https://api.github.com/users/jakobhellermann/orgs",
          "repos_url": "https://api.github.com/users/jakobhellermann/repos",
          "events_url": "https://api.github.com/users/jakobhellermann/events{/privacy}",
          "received_events_url": "https://api.github.com/users/jakobhellermann/received_events",
          "type": "User",
          "site_admin": false
        },
        "html_url": "https://github.com/jakobhellermann/ohmyzsh",
        "description": "🙃 A delightful community-driven (with 1700+ contributors) framework for managing your zsh configuration. Includes 200+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, php, python, etc), over 140 themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.",
        "fork": true,
        "url": "https://api.github.com/repos/jakobhellermann/ohmyzsh",
        "forks_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/forks",
        "keys_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/keys{/key_id}",
        "collaborators_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/collaborators{/collaborator}",
        "teams_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/teams",
        "hooks_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/hooks",
        "issue_events_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/issues/events{/number}",
        "events_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/events",
        "assignees_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/assignees{/user}",
        "branches_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/branches{/branch}",
        "tags_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/tags",
        "blobs_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/git/blobs{/sha}",
        "git_tags_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/git/tags{/sha}",
        "git_refs_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/git/refs{/sha}",
        "trees_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/git/trees{/sha}",
        "statuses_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/statuses/{sha}",
        "languages_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/languages",
        "stargazers_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/stargazers",
        "contributors_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/contributors",
        "subscribers_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/subscribers",
        "subscription_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/subscription",
        "commits_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/commits{/sha}",
        "git_commits_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/git/commits{/sha}",
        "comments_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/comments{/number}",
        "issue_comment_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/issues/comments{/number}",
        "contents_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/contents/{+path}",
        "compare_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/compare/{base}...{head}",
        "merges_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/merges",
        "archive_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/{archive_format}{/ref}",
        "downloads_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/downloads",
        "issues_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/issues{/number}",
        "pulls_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/pulls{/number}",
        "milestones_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/milestones{/number}",
        "notifications_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/notifications{?since,all,participating}",
        "labels_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/labels{/name}",
        "releases_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/releases{/id}",
        "deployments_url": "https://api.github.com/repos/jakobhellermann/ohmyzsh/deployments",
        "created_at": "2020-07-11T09:57:44Z",
        "updated_at": "2020-07-11T09:57:48Z",
        "pushed_at": "2020-07-11T12:02:38Z",
        "git_url": "git://github.com/jakobhellermann/ohmyzsh.git",
        "ssh_url": "git@github.com:jakobhellermann/ohmyzsh.git",
        "clone_url": "https://github.com/jakobhellermann/ohmyzsh.git",
        "svn_url": "https://github.com/jakobhellermann/ohmyzsh",
        "homepage": "https://ohmyz.sh",
        "size": 6974,
        "stargazers_count": 0,
        "watchers_count": 0,
        "language": null,
        "has_issues": false,
        "has_projects": true,
        "has_downloads": true,
        "has_wiki": true,
        "has_pages": false,
        "forks_count": 0,
        "mirror_url": null,
        "archived": false,
        "disabled": false,
        "open_issues_count": 0,
        "license": {
          "key": "mit",
          "name": "MIT License",
          "spdx_id": "MIT",
          "url": "https://api.github.com/licenses/mit",
          "node_id": "MDc6TGljZW5zZTEz"
        },
        "forks": 0,
        "open_issues": 0,
        "watchers": 0,
        "default_branch": "master",
        "allow_squash_merge": true,
        "allow_merge_commit": true,
        "allow_rebase_merge": true,
        "delete_branch_on_merge": false
      }
    },
    "base": {
      "label": "ohmyzsh:master",
      "ref": "master",
      "sha": "7deaff71a2be08145d83f0177edbf2dfb3e91262",
      "user": {
        "login": "ohmyzsh",
        "id": 22552083,
        "node_id": "MDEyOk9yZ2FuaXphdGlvbjIyNTUyMDgz",
        "avatar_url": "https://avatars1.githubusercontent.com/u/22552083?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/ohmyzsh",
        "html_url": "https://github.com/ohmyzsh",
        "followers_url": "https://api.github.com/users/ohmyzsh/followers",
        "following_url": "https://api.github.com/users/ohmyzsh/following{/other_user}",
        "gists_url": "https://api.github.com/users/ohmyzsh/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/ohmyzsh/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/ohmyzsh/subscriptions",
        "organizations_url": "https://api.github.com/users/ohmyzsh/orgs",
        "repos_url": "https://api.github.com/users/ohmyzsh/repos",
        "events_url": "https://api.github.com/users/ohmyzsh/events{/privacy}",
        "received_events_url": "https://api.github.com/users/ohmyzsh/received_events",
        "type": "Organization",
        "site_admin": false
      },
      "repo": {
        "id": 291137,
        "node_id": "MDEwOlJlcG9zaXRvcnkyOTExMzc=",
        "name": "ohmyzsh",
        "full_name": "ohmyzsh/ohmyzsh",
        "private": false,
        "owner": {
          "login": "ohmyzsh",
          "id": 22552083,
          "node_id": "MDEyOk9yZ2FuaXphdGlvbjIyNTUyMDgz",
          "avatar_url": "https://avatars1.githubusercontent.com/u/22552083?v=4",
          "gravatar_id": "",
          "url": "https://api.github.com/users/ohmyzsh",
          "html_url": "https://github.com/ohmyzsh",
          "followers_url": "https://api.github.com/users/ohmyzsh/followers",
          "following_url": "https://api.github.com/users/ohmyzsh/following{/other_user}",
          "gists_url": "https://api.github.com/users/ohmyzsh/gists{/gist_id}",
          "starred_url": "https://api.github.com/users/ohmyzsh/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/ohmyzsh/subscriptions",
          "organizations_url": "https://api.github.com/users/ohmyzsh/orgs",
          "repos_url": "https://api.github.com/users/ohmyzsh/repos",
          "events_url": "https://api.github.com/users/ohmyzsh/events{/privacy}",
          "received_events_url": "https://api.github.com/users/ohmyzsh/received_events",
          "type": "Organization",
          "site_admin": false
        },
        "html_url": "https://github.com/ohmyzsh/ohmyzsh",
        "description": "🙃 A delightful community-driven (with 1700+ contributors) framework for managing your zsh configuration. Includes 200+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, php, python, etc), over 140 themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.",
        "fork": false,
        "url": "https://api.github.com/repos/ohmyzsh/ohmyzsh",
        "forks_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/forks",
        "keys_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/keys{/key_id}",
        "collaborators_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/collaborators{/collaborator}",
        "teams_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/teams",
        "hooks_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/hooks",
        "issue_events_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/events{/number}",
        "events_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/events",
        "assignees_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/assignees{/user}",
        "branches_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/branches{/branch}",
        "tags_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/tags",
        "blobs_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/blobs{/sha}",
        "git_tags_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/tags{/sha}",
        "git_refs_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/refs{/sha}",
        "trees_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/trees{/sha}",
        "statuses_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/statuses/{sha}",
        "languages_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/languages",
        "stargazers_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/stargazers",
        "contributors_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/contributors",
        "subscribers_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/subscribers",
        "subscription_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/subscription",
        "commits_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/commits{/sha}",
        "git_commits_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/commits{/sha}",
        "comments_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/comments{/number}",
        "issue_comment_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/comments{/number}",
        "contents_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/contents/{+path}",
        "compare_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/compare/{base}...{head}",
        "merges_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/merges",
        "archive_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/{archive_format}{/ref}",
        "downloads_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/downloads",
        "issues_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues{/number}",
        "pulls_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls{/number}",
        "milestones_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/milestones{/number}",
        "notifications_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/notifications{?since,all,participating}",
        "labels_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/labels{/name}",
        "releases_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/releases{/id}",
        "deployments_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/deployments",
        "created_at": "2009-08-28T18:15:37Z",
        "updated_at": "2020-07-11T11:24:22Z",
        "pushed_at": "2020-07-11T12:00:53Z",
        "git_url": "git://github.com/ohmyzsh/ohmyzsh.git",
        "ssh_url": "git@github.com:ohmyzsh/ohmyzsh.git",
        "clone_url": "https://github.com/ohmyzsh/ohmyzsh.git",
        "svn_url": "https://github.com/ohmyzsh/ohmyzsh",
        "homepage": "https://ohmyz.sh",
        "size": 6973,
        "stargazers_count": 113091,
        "watchers_count": 113091,
        "language": "Shell",
        "has_issues": true,
        "has_projects": true,
        "has_downloads": true,
        "has_wiki": true,
        "has_pages": false,
        "forks_count": 20126,
        "mirror_url": null,
        "archived": false,
        "disabled": false,
        "open_issues_count": 718,
        "license": {
          "key": "mit",
          "name": "MIT License",
          "spdx_id": "MIT",
          "url": "https://api.github.com/licenses/mit",
          "node_id": "MDc6TGljZW5zZTEz"
        },
        "forks": 20126,
        "open_issues": 718,
        "watchers": 113091,
        "default_branch": "master",
        "allow_squash_merge": true,
        "allow_merge_commit": true,
        "allow_rebase_merge": true,
        "delete_branch_on_merge": false
      }
    },
    "_links": {
      "self": {
        "href": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/9102"
      },
      "html": {
        "href": "https://github.com/ohmyzsh/ohmyzsh/pull/9102"
      },
      "issue": {
        "href": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/9102"
      },
      "comments": {
        "href": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/9102/comments"
      },
      "review_comments": {
        "href": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/9102/comments"
      },
      "review_comment": {
        "href": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/comments{/number}"
      },
      "commits": {
        "href": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/9102/commits"
      },
      "statuses": {
        "href": "https://api.github.com/repos/ohmyzsh/ohmyzsh/statuses/d771734400f1ffaf7e0bb703cc3df1676241ecc6"
      }
    },
    "author_association": "NONE",
    "active_lock_reason": null,
    "merged": false,
    "mergeable": null,
    "rebaseable": null,
    "mergeable_state": "unknown",
    "merged_by": null,
    "comments": 3,
    "review_comments": 0,
    "maintainer_can_modify": true,
    "commits": 3,
    "additions": 25,
    "deletions": 11,
    "changed_files": 2
  },
  "before": "d5161b9f72be5fea07b30ccca7df2c3caa1ad5c4",
  "after": "d771734400f1ffaf7e0bb703cc3df1676241ecc6",
  "repository": {
    "id": 291137,
    "node_id": "MDEwOlJlcG9zaXRvcnkyOTExMzc=",
    "name": "ohmyzsh",
    "full_name": "ohmyzsh/ohmyzsh",
    "private": false,
    "owner": {
      "login": "ohmyzsh",
      "id": 22552083,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjIyNTUyMDgz",
      "avatar_url": "https://avatars1.githubusercontent.com/u/22552083?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/ohmyzsh",
      "html_url": "https://github.com/ohmyzsh",
      "followers_url": "https://api.github.com/users/ohmyzsh/followers",
      "following_url": "https://api.github.com/users/ohmyzsh/following{/other_user}",
      "gists_url": "https://api.github.com/users/ohmyzsh/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/ohmyzsh/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/ohmyzsh/subscriptions",
      "organizations_url": "https://api.github.com/users/ohmyzsh/orgs",
      "repos_url": "https://api.github.com/users/ohmyzsh/repos",
      "events_url": "https://api.github.com/users/ohmyzsh/events{/privacy}",
      "received_events_url": "https://api.github.com/users/ohmyzsh/received_events",
      "type": "Organization",
      "site_admin": false
    },
    "html_url": "https://github.com/ohmyzsh/ohmyzsh",
    "description": "🙃 A delightful community-driven (with 1700+ contributors) framework for managing your zsh configuration. Includes 200+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, php, python, etc), over 140 themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.",
    "fork": false,
    "url": "https://api.github.com/repos/ohmyzsh/ohmyzsh",
    "forks_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/forks",
    "keys_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/keys{/key_id}",
    "collaborators_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/collaborators{/collaborator}",
    "teams_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/teams",
    "hooks_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/hooks",
    "issue_events_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/events{/number}",
    "events_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/events",
    "assignees_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/assignees{/user}",
    "branches_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/branches{/branch}",
    "tags_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/tags",
    "blobs_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/blobs{/sha}",
    "git_tags_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/tags{/sha}",
    "git_refs_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/refs{/sha}",
    "trees_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/trees{/sha}",
    "statuses_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/statuses/{sha}",
    "languages_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/languages",
    "stargazers_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/stargazers",
    "contributors_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/contributors",
    "subscribers_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/subscribers",
    "subscription_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/subscription",
    "commits_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/commits{/sha}",
    "git_commits_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/git/commits{/sha}",
    "comments_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/comments{/number}",
    "issue_comment_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues/comments{/number}",
    "contents_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/contents/{+path}",
    "compare_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/compare/{base}...{head}",
    "merges_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/merges",
    "archive_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/{archive_format}{/ref}",
    "downloads_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/downloads",
    "issues_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/issues{/number}",
    "pulls_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls{/number}",
    "milestones_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/milestones{/number}",
    "notifications_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/notifications{?since,all,participating}",
    "labels_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/labels{/name}",
    "releases_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/releases{/id}",
    "deployments_url": "https://api.github.com/repos/ohmyzsh/ohmyzsh/deployments",
    "created_at": "2009-08-28T18:15:37Z",
    "updated_at": "2020-07-11T11:24:22Z",
    "pushed_at": "2020-07-11T12:00:53Z",
    "git_url": "git://github.com/ohmyzsh/ohmyzsh.git",
    "ssh_url": "git@github.com:ohmyzsh/ohmyzsh.git",
    "clone_url": "https://github.com/ohmyzsh/ohmyzsh.git",
    "svn_url": "https://github.com/ohmyzsh/ohmyzsh",
    "homepage": "https://ohmyz.sh",
    "size": 6973,
    "stargazers_count": 113091,
    "watchers_count": 113091,
    "language": "Shell",
    "has_issues": true,
    "has_projects": true,
    "has_downloads": true,
    "has_wiki": true,
    "has_pages": false,
    "forks_count": 20126,
    "mirror_url": null,
    "archived": false,
    "disabled": false,
    "open_issues_count": 718,
    "license": {
      "key": "mit",
      "name": "MIT License",
      "spdx_id": "MIT",
      "url": "https://api.github.com/licenses/mit",
      "node_id": "MDc6TGljZW5zZTEz"
    },
    "forks": 20126,
    "open_issues": 718,
    "watchers": 113091,
    "default_branch": "master"
  },
  "organization": {
    "login": "ohmyzsh",
    "id": 22552083,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjIyNTUyMDgz",
    "url": "https://api.github.com/orgs/ohmyzsh",
    "repos_url": "https://api.github.com/orgs/ohmyzsh/repos",
    "events_url": "https://api.github.com/orgs/ohmyzsh/events",
    "hooks_url": "https://api.github.com/orgs/ohmyzsh/hooks",
    "issues_url": "https://api.github.com/orgs/ohmyzsh/issues",
    "members_url": "https://api.github.com/orgs/ohmyzsh/members{/member}",
    "public_members_url": "https://api.github.com/orgs/ohmyzsh/public_members{/member}",
    "avatar_url": "https://avatars1.githubusercontent.com/u/22552083?v=4",
    "description": "A delightful community-driven framework for managing your zsh configuration."
  },
  "sender": {
    "login": "mcornella",
    "id": 1441704,
    "node_id": "MDQ6VXNlcjE0NDE3MDQ=",
    "avatar_url": "https://avatars1.githubusercontent.com/u/1441704?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/mcornella",
    "html_url": "https://github.com/mcornella",
    "followers_url": "https://api.github.com/users/mcornella/followers",
    "following_url": "https://api.github.com/users/mcornella/following{/other_user}",
    "gists_url": "https://api.github.com/users/mcornella/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/mcornella/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/mcornella/subscriptions",
    "organizations_url": "https://api.github.com/users/mcornella/orgs",
    "repos_url": "https://api.github.com/users/mcornella/repos",
    "events_url": "https://api.github.com/users/mcornella/events{/privacy}",
    "received_events_url": "https://api.github.com/users/mcornella/received_events",
    "type": "User",
    "site_admin": false
  },
  "installation": {
    "id": 5790348,
    "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNTc5MDM0OA=="
  }
}

Let me know if I can be of more help, setting up the bot for development can be tricky. Cheers!

@bartekpacia
Copy link
Contributor Author

bartekpacia commented Jul 12, 2020

Thank you @mcornella, this is very helpful. Going full-node instead of getting output from some .zsh the script will be easier to do and to read, imo.
I have a question regarding the development process: what's the best, most effective way to test the bot? I wrote a simple shell script that:

  • creates a new_branch in ohmyzsh
  • modifies some file
  • pushed that branch to my forked bartekpacia/ohmyzsh on GitHub

Meanwhile, I run ohmyzsh-bot locally.

Then I create a PR from new_branch against master.
It kind of works, but I'm sure there's a faster and more pleasant way to do it. I did some research and found this tool, but idk if using it makes sense in this situation.
I'd appreciate if you explained how you test the bot when you develop it.

EDIT:
I found this guide, added an example API response to text/fixtures, and run it using npm run build && node_modules/.bin/probot receive -e pull_request -p test/fixtures/pulls.opened.json ./lib/index.js

- added fetching CODEOWNERS file contents and logging them to the console
- added an example GitHub API response to test/fixtures
- removed assign.zsh, we're going full-node
@bartekpacia bartekpacia marked this pull request as ready for review July 14, 2020 08:12
- implemented simple logic to match CODEOWNERS to modifies files
- refactored to make testing possbile
- added 2 tests for parseCodeOwners() and parseModifiedFiles()
@larson-carter
Copy link
Member

@mcornella @bartekpacia stated internally that he is ready for the final review!

@mcornella
Copy link
Member

Hey sorry I'm unavailable the next 2 days but afterwards I'll review this. Looks great so far, thanks!

Copy link
Member

@mcornella mcornella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few comments that require changes but the main structure is correct. Also, we can delete test/fixtures/issues.opened.json and test/index.test.ts files to get a passing test (npm run test). Finally, pass the whole thing through the standardjs linter with npm run lint.

src/actions/assign.ts Outdated Show resolved Hide resolved
src/actions/assign.ts Outdated Show resolved Hide resolved
src/actions/assign.ts Outdated Show resolved Hide resolved
src/actions/assign.ts Outdated Show resolved Hide resolved
src/actions/assign.ts Outdated Show resolved Hide resolved
@bartekpacia
Copy link
Contributor Author

Thank you very much for the review @mcornella🎉. I added your suggestions and ran npm run lint on everything. I also changed test/assign.test.ts because it was failing.

Also, StandardJS spits out the following error:

standard: Use JavaScript Standard Style (https://standardjs.com)
  ~/dev/node/ohmyzsh-bot/test/assign.test.ts:2:47: 'CodeOwner' is defined but never used.
npm ERR! Test failed.  See above for more details.

But CodeOwner is used as type annotation for expectedCodeOwners const at line 14

@mcornella
Copy link
Member

Hmm yeah I encountered the same thing. You can disable linting of that particular line by adding the comment // eslint-disable-line no-unused-vars (the same way as is done in src/index.ts).

Copy link
Member

@mcornella mcornella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments, I think I didn't leave anything out.

src/actions/assign.ts Outdated Show resolved Hide resolved
src/actions/assign.ts Show resolved Hide resolved
src/actions/assign.ts Outdated Show resolved Hide resolved
src/actions/assign.ts Outdated Show resolved Hide resolved
src/actions/assign.ts Outdated Show resolved Hide resolved
Co-authored-by: Marc Cornellà <marc.cornella@live.com>
@bartekpacia
Copy link
Contributor Author

Sorry, I must've overlooked the notification saying you responded. Thanks for the review, I applied your suggestions and they work fine (all tests pass).

@mcornella mcornella self-requested a review August 7, 2020 18:42
Copy link
Member

@mcornella mcornella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made minor tweaks, this is ready to go. Thanks! :shipit:

@mcornella mcornella merged commit f170313 into ohmyzsh:master Aug 7, 2020
@bartekpacia bartekpacia deleted the codeowners_pr branch August 7, 2020 21:01
@mcornella
Copy link
Member

Ok, first trial test and it didn't pass it. It looks like we can only request a review from people inside the org. The algorithm is solid though:

2020-08-20T07:44:25.347520+00:00 app[web.1]: 07:44:25.347Z  INFO event: PR number: 9189 , owner: ohmyzsh , repo: ohmyzsh (id=f4f86200-e2b8-11ea-9e7b-12abc036e3ac)
2020-08-20T07:44:25.648855+00:00 app[web.1]: 07:44:25.648Z  INFO event: plugins/gitfast/update was modified. felipec owns plugins/gitfast/ (id=f4f86200-e2b8-11ea-9e7b-12abc036e3ac)
2020-08-20T07:44:25.649106+00:00 app[web.1]: 07:44:25.648Z  INFO event: Old reviewers: [] (id=f4f86200-e2b8-11ea-9e7b-12abc036e3ac)
2020-08-20T07:44:25.649346+00:00 app[web.1]: 07:44:25.649Z  INFO event: New reviewers: [ 'felipec' ] (id=f4f86200-e2b8-11ea-9e7b-12abc036e3ac)
2020-08-20T07:44:25.846938+00:00 app[web.1]: Deprecation: [@octokit/request-error] `error.code` is deprecated, use `error.status`.
2020-08-20T07:44:25.846946+00:00 app[web.1]: at RequestError.get (/app/node_modules/@octokit/request-error/dist-node/index.js:29:17)
2020-08-20T07:44:25.846947+00:00 app[web.1]: at Object.Logger.stdSerializers.err (/app/node_modules/bunyan/lib/bunyan.js:1148:19)
2020-08-20T07:44:25.846948+00:00 app[web.1]: at /app/node_modules/bunyan/lib/bunyan.js:873:50
2020-08-20T07:44:25.846948+00:00 app[web.1]: at Array.forEach ()
2020-08-20T07:44:25.846949+00:00 app[web.1]: at Logger._applySerializers (/app/node_modules/bunyan/lib/bunyan.js:865:35)
2020-08-20T07:44:25.846949+00:00 app[web.1]: at mkRecord (/app/node_modules/bunyan/lib/bunyan.js:978:17)
2020-08-20T07:44:25.846950+00:00 app[web.1]: at Logger.error (/app/node_modules/bunyan/lib/bunyan.js:1044:19)
2020-08-20T07:44:25.846950+00:00 app[web.1]: at Application. (/app/node_modules/probot/lib/application.js:163:33)
2020-08-20T07:44:25.846951+00:00 app[web.1]: at step (/app/node_modules/probot/lib/application.js:44:23)
2020-08-20T07:44:25.846951+00:00 app[web.1]: at Object.throw (/app/node_modules/probot/lib/application.js:25:53)
2020-08-20T07:44:25.846952+00:00 app[web.1]: at rejected (/app/node_modules/probot/lib/application.js:17:65)
2020-08-20T07:44:25.847507+00:00 app[web.1]: 07:44:25.847Z ERROR event: Reviews may only be requested from collaborators. One or more of the users or teams you specified is not a collaborator of the ohmyzsh/ohmyzsh repository. (id=f4f86200-e2b8-11ea-9e7b-12abc036e3ac)
2020-08-20T07:44:25.847508+00:00 app[web.1]: HttpError: Reviews may only be requested from collaborators. One or more of the users or teams you specified is not a collaborator of the ohmyzsh/ohmyzsh repository.
2020-08-20T07:44:25.847509+00:00 app[web.1]: at /app/node_modules/@octokit/request/dist-node/index.js:66:23
2020-08-20T07:44:25.847509+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:93:5)
2020-08-20T07:44:25.847510+00:00 app[web.1]: at async Job.doExecute (/app/node_modules/bottleneck/light.js:405:18)

So it seems that we'll have to use @mentions, which means not having the ability to know which users we have mentioned previously. This means we can only make the mention when the PR is opened, otherwise we risk repeating a mention everytime there's a code change or even a force-push.

Another option would be to look at the list of subscribers of the PR and only mention owners which aren't subscribed, but I can see it being obnoxious when someone unsubscribes from the PR and the bot mentions them again.

@bartekpacia
Copy link
Contributor Author

bartekpacia commented Aug 20, 2020

Oh, that's not good :/ how did it came that we're only now finding about this limitation
I'm very busy right now, so I won't be able to work on this (at least in the upcoming weeks)

@mcornella
Copy link
Member

I'm very busy right now, so I won't be able to work on this

Don't worry, I made the changes myself. See 8e0ebd7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants