1

Once a pull request is approved by any member of a requested team, it disappears from the GitHub dashboard, even if it lingers in an open state. How can we query using the Github v4 GraphQL the open pull requests created by any members of a particular team?

{
  search(query: "type:pr state:open review-requested:StevenACoffman", type: ISSUE, first: 100) {
    issueCount
    pageInfo {
      endCursor
      startCursor
    }
    edges {
      node {
        ... on PullRequest {
          url
        }
      }
    }
  }
}

The query for a team's requested reviews is: team-review-requested:ORG/TEAMNAME where ORG should be replaced with the organization, and TEAMNAME replaced with the team name. Neither of these queries show open pull requests that were created by a teammate if they were approved by any other teammates.

The query for a team by name is:

{
  organization(login: "khan") {
    teams(first: 100, query: "districts") {
      totalCount
      edges {
        node {
          members {
            edges {
              node {
                name
                login
              }
            }
          }
          name
          description
        }
      }
    }
  }
}
SteveCoffman
  • 983
  • 1
  • 8
  • 22

1 Answers1

0

below code snippet handy finding all pull requests for a organization from last 10 days via graphql-api. refer - graphql_example

import requests
import json
from datetime import timedelta, date
delta_day = 10
from string import Template

ORG_NAME = "ABC_XYZ"
present_day = date.today()
present_day_str = present_day.strftime('%Y-%m-%d')
previous_day = present_day - timedelta(days=delta_day)
previous_day_str = previous_day.strftime('%Y-%m-%d')

headers = {
  'Authorization': 'token ABC_XYZ',
  'Content-Type': 'application/json'
}

url = "https://www.github-ABC_XYZ.com/api/graphql"

queryTemplate = Template(
"""
{
  search(query: "org:$ORG is:pr is:merged merged:>=$PREVIOUS_DAY base:master sort:updated-desc", type: ISSUE, last: 100) {
    edges {
      node {
        ... on PullRequest {
          url
          title
          createdAt
        }
      }
    }
  }
}

"""
)

query = queryTemplate.substitute(ORG=ORG_NAME,PREVIOUS_DAY=previous_day_str)

def run_query(query): # A simple function to use requests.post to make the API call. Note the json= section.
    request = requests.post(url, json={'query': query}, headers=headers)
    if request.status_code == 200:
        return request.json()
    else:
        raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))

result = run_query(query=query)

print(result)
TheFixer
  • 89
  • 1
  • 2