mattermost / mattermost/mattermost-plugin-github

Use GitHub's GraphQL service to fetch PR details

Open
#325 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Difficulty/2:Medium Hacktoberfest Help Wanted Tech/Go Tech/ReactJS Type/Enhancement Up For Grabs
Dominant language
Go
Stars
179
Forks
180
Avg merge
1d 16h
Merged PRs (30d)
13

Description

As noted in https://github.com/mattermost/mattermost-plugin-github/pull/170#issuecomment-568304624 , we are making 3 API calls to GitHub's REST API for each PR when we want to display detailed info about each PR in the RHS. Using GitHub's GraphQL API, we can ideally fetch all information in one request.

We can use GitHub's GraphQL explorer to test queries:
https://developer.github.com/v4/explorer

Here is an example query that fetches some of the required data:

query { 
	your_prs: search(first: 100, query: "author:mickmister is:pr is:open archived:false", type: ISSUE) {
        issueCount
        nodes {
            ... on PullRequest {
                id
                title
                body
                mergeable
                reviewDecision
                state
                repository {
                    name
                    nameWithOwner
                }
            
                reviewRequests(first:10) {
                    totalCount 
                }

                reviews(first:10) {
                    totalCount
                    edges {
                        node {
                            state
                        }
                    }
                }
            }
        }
    }

   # your_review_requests: search(first: 100, query: "...", type: ISSUE) { {
   #    ...
   # }
}

One strategy would be to:

  • on page load, fetch all details for all relevant RHS tabs/categories in one GraphQL request
  • do the same when the page "wakes up" or when the user clicks the GitHub refresh button
  • when the user navigates to a specific category, have the backend fetch all up-to-date PRs and details about this category

This is the same basic logic as it currently works, but I think if the backend takes care of the "PR details" logic, the frontend can just say "give me all data I need for this category", the backend can use one GraphQL query without worrying about which specific PR IDs need the details etc. That's taken care of by GitHub in the query.

We can compose queries using https://github.com/shurcooL/githubv4 , which is a Go driver for GitHub's GraphQL service. Much of the querying logic has overlap between the categories, so there should be an opportunity to reuse the querying logic with the structures we create with this library. This is useful for performing the "all-in-one" query versus the "one category" query.

A couple things to note:

  • the org will need to be injected into the query if the config value for the org-scope is set
  • the Unread Messages will still need to be fetched via GitHub's REST API, as they are not supported in their GraphQL implementation

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the backend logic that fetches detailed pull-request data for the RHS and the frontend category and refresh flows. Use GitHub's GraphQL explorer and the githubv4 driver to compare the required fields, while keeping Unread Messages on the REST API. Done means the relevant categories can receive their PR details through the planned GraphQL requests without changing the separate unread-message path.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, go, graphql
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.