import { IssueCommentState } from "../on-issue-comment" ; import * as prettier from "../prettier/config" ; import * as github from "." ; import * as graphql from "./graphql-generated" ; /** fields unique to push contexts */ interface CommentContextUnique { readonly prettierIgnore : string ; readonly prettifierConfig : string ; } /** the payload of loading additional push data via the GraphQL API */ export type CommentContextData = CommentContextUnique & prettier . ConfigResult ; const query = `
  query OnIssueComment($org: String!, $repo: String!) {
    # config file contents
    repository(owner: $org, name: $repo) {
      package_json: object(expression: "{{branch}}:package.json") {
        __typename
        ... on Blob {
          text
        }
      }
      prettifierConfig: object(expression: "{{branch}}:.github/prettifier.yml") {
        __typename
        ... on Blob {
          text
        }
      }
      prettierrc: object(expression: "{{branch}}:.prettierrc") {
        __typename
        ... on Blob {
          text
        }
      }
      prettierrc_json: object(expression: "{{branch}}:.prettierrc.json") {
        __typename
        ... on Blob {
          text
        }
      }
      prettierrc_json5: object(expression: "{{branch}}:.prettierrc.json5") {
        __typename
        ... on Blob {
          text
        }
      }
      prettierrc_toml: object(expression: "{{branch}}:.prettierrc.toml") {
        __typename
        ... on Blob {
          text
        }
      }
      prettierrc_yml: object(expression: "{{branch}}:.prettierrc.yml") {
        __typename
        ... on Blob {
          text
        }
      }
      prettierrc_yaml: object(expression: "{{branch}}:.prettierrc.yaml") {
        __typename
        ... on Blob {
          text
        }
      }
      prettierIgnore: object(expression: "{{branch}}:.prettierignore") {
        __typename
        ... on Blob {
          text
        }
      }
    }
  }
` ; export async function loadIssueCommentContextData ( state ) { const fullQuery = query . replace ( /\{\{branch\}\}/g , state . defaultBranchName ) ; const callResult = await state . octokit . graphql ( fullQuery , { org : state . org , repo : state . repo , } as graphql . OnPullRequestQueryVariables ) ; return { package_json : github . blobText ( callResult . repository ?. package_json ) , prettifierConfig : github . blobText ( callResult . repository ?. prettifierConfig ) , prettierrc : github . blobText ( callResult . repository ?. prettierrc ) , prettierrc_json : github . blobText ( callResult . repository ?. prettierrc_json ) , prettierrc_json5 : github . blobText ( callResult . repository ?. prettierrc_json5 ) , prettierrc_toml : github . blobText ( callResult . repository ?. prettierrc_toml ) , prettierrc_yml : github . blobText ( callResult . repository ?. prettierrc_yml ) , prettierrc_yaml : github . blobText ( callResult . repository ?. prettierrc_yaml ) , prettierIgnore : github . blobText ( callResult . repository ?. prettierIgnore ) , } ; }