Skip to content

Instantly share code, notes, and snippets.

@BondAnthony
Last active May 22, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BondAnthony/e6c1a2fa141fb0bb9c2d99acf6de677f to your computer and use it in GitHub Desktop.
Save BondAnthony/e6c1a2fa141fb0bb9c2d99acf6de677f to your computer and use it in GitHub Desktop.
Github GraphQL

Github API

Queries to return issues based on milestone

Variables

{
  "owner": "bondanthony",
  "name": "ansible-plays"
}

Fragments

Issue fragment

fragment issue on Issue {
  number
  title
  url
  state
  updatedAt
  labels(first: 3) {
    nodes {
      name
    }
    totalCount
  }
  milestone {
    title
  }
}

Pull Request fragment

fragment pr on PullRequest {
  number
  title
  state
  url
  headRefName
  headRepositoryOwner {
    login
  }
  isCrossRepository
  isDraft
}

Find all milestones on your repo

query ($owner: String!, $name: String!) {
  repository(owner: $owner, name: $name) {
    milestones (first: 100){
      edges{
        node {
          id,
          title,
          number
        }
      }
    }
  }
}

Return all issues in milestone

query ($owner:String!, $name:String!){
 repository(owner: $owner, name: $name) {
    milestone(number: 3) {
      issues(last:10) {
	nodes {
          ...issue
      	}
      }
    }
  }
}

Return all issues and pull requests within a given milestone

query ($owner: String!, $name: String!) {
  repository(owner: $owner, name: $name) {
    milestone(number: 3) {
      issues(last: 100) {
        nodes {
          ...issue
        }
      }
      pullRequests(last: 100) {
        nodes {
          ...pr
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment