Skip to content

Use GraphQL API to differentiate bot vs. human PR authors #50

@choldgraf

Description

@choldgraf

I was poking around the GraphQL structure in thinking about #49 and curious if @yuvipanda considered this option for differentiating bots:

Rather than hard-coding bot names, could we use the __typename field on the PullRequest.author object using the GitHub GraphQL API?

I think that this will roughly happen:

  • If the author is a standard user, __typename will be User.
  • If the author is a bot account, __typename will be Bot.

Here's the link where I saw this mentioned, maybe that's a more robust way to detect bots?

https://stackoverflow.com/questions/79791527/assigning-github-issue-to-copilot-fails-using-graphql

they had language like this:

repository(owner: $owner, name: $name) {
            suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
                nodes {
                    login
                    __typename
                    ... on Bot {
                        id
                    }
                    ... on User {
                        id
                    }
                }
            }
        }
    }

Here's an example I just ran:

gh api graphql -f query='
  {
    search(type: ISSUE, first: 10, query: "org:jupyter-book is:pr is:open") {
      nodes {
        ... on PullRequest {
          number
          title
          url
          repository {
            name
            owner {
              login
            }
          }
          author {
            __typename
            login
          }
        }
      }
    }
  }'

And the result:

{
  "data": {
    "search": {
      "nodes": [
        {
          "number": 2546,
          "title": "⏪ Support reverse toc order on patterns",
          "url": "https://github.com/jupyter-book/mystmd/pull/2546",
          "repository": {
            "name": "mystmd",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "rowanc1"
          }
        },
        {
          "number": 2543,
          "title": "🐛 Catch error states of chokidar",
          "url": "https://github.com/jupyter-book/mystmd/pull/2543",
          "repository": {
            "name": "mystmd",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "rowanc1"
          }
        },
        {
          "number": 2542,
          "title": "💰 Dollarmath settings for markdown parsing",
          "url": "https://github.com/jupyter-book/mystmd/pull/2542",
          "repository": {
            "name": "mystmd",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "rowanc1"
          }
        },
        {
          "number": 2499,
          "title": "DOC: there are more emojis in the calculation",
          "url": "https://github.com/jupyter-book/jupyter-book/pull/2499",
          "repository": {
            "name": "jupyter-book",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "bsipocz"
          }
        },
        {
          "number": 723,
          "title": "Document location of tailwind CSS classes",
          "url": "https://github.com/jupyter-book/myst-theme/pull/723",
          "repository": {
            "name": "myst-theme",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "choldgraf"
          }
        },
        {
          "number": 1,
          "title": "DOC: Adding jupyter-book and jupyterlab-myst to the README list",
          "url": "https://github.com/jupyter-book/.github/pull/1",
          "repository": {
            "name": ".github",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "bsipocz"
          }
        },
        {
          "number": 2537,
          "title": "🚀 Release",
          "url": "https://github.com/jupyter-book/mystmd/pull/2537",
          "repository": {
            "name": "mystmd",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "Bot",
            "login": "github-actions"
          }
        },
        {
          "number": 2489,
          "title": "Bump the npm group across 1 directory with 9 updates",
          "url": "https://github.com/jupyter-book/jupyter-book/pull/2489",
          "repository": {
            "name": "jupyter-book",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "Bot",
            "login": "dependabot"
          }
        },
        {
          "number": 2529,
          "title": "🛑 Kill process trees on Linux",
          "url": "https://github.com/jupyter-book/mystmd/pull/2529",
          "repository": {
            "name": "mystmd",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "rowanc1"
          }
        },
        {
          "number": 2522,
          "title": "revisited doc on table of contents",
          "url": "https://github.com/jupyter-book/mystmd/pull/2522",
          "repository": {
            "name": "mystmd",
            "owner": {
              "login": "jupyter-book"
            }
          },
          "author": {
            "__typename": "User",
            "login": "parmentelat"
          }
        }
      ]
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions