Skip to content

Add GraphQL blame endpoint

Gavin Hinfey requested to merge 393764-graphql-git-blame-endpoint into master

Parse span from Gitaly blame result (!128101 - merged) needs to be merged first.

This MR was previously approved but merged incorrectly: !128103 (merged)

What does this MR do and why?

Add a Graphql blame end point.

Expose git blame data via a GraphQL endpoint.
Relies on !128101 (merged) to get blame span value as per this discussion. That MR needs to be merged first

Contributes to #393764 (closed)
Feature flag: #419808 (closed)

How to set up and validate locally

  1. Make sure to enable the feature flag graphql_git_blame - Feature.enable(:graphql_git_blame)

  2. Create as root create a project called blame-test. Add a file 'test file' and add some text across multiple lines.

  3. Perform the following query against either the API; http://127.0.0.1:3000/api/graphql, or the GrapiQL UI; http://127.0.0.1:3000/-/graphql-explorer:

    query TestQuery($fullPath: ID!) {
      project(fullPath: $fullPath) {
        repository {
          blobs(paths: ["test file"]) {
            nodes {
              blame(fromLine: 2, toLine: 6 ){
                firstLine
                groups {
                  lineno
                  lines
                  span
                  commit {
                    sha
                  }
                  commitData {
                    authorAvatar
                    ageMapClass
                    commitLink
                    commitAuthorLink
                    projectBlameLink
                    timeAgoTooltip
                  }
                }
              }
            }
          }
        }
      }
    }

    With query Variables:

    {
      "fullPath": "root/blame-test"
    }
  4. You should see the following returned:

Screenshot_2023-08-14_at_13.11.31

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #393764 (closed)

Edited by Ash McKenzie

Merge request reports