Created
February 16, 2021 12:33
-
-
Save lagenorhynque/672b945952f4b5cf324259c00519987d to your computer and use it in GitHub Desktop.
A minimal GitHub GraphQL API client implemented as a Python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import pprint | |
import requests | |
AUTH_TOKEN = os.getenv('AUTH_TOKEN') | |
GRAPHQL_QUERY = ''' | |
query ($query: String!, $last: Int) { | |
search(type: ISSUE, query: $query, last: $last) { | |
nodes { | |
... on Issue { | |
title | |
url | |
repository { | |
name | |
} | |
labels(first: 10) { | |
nodes { | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
''' | |
def run_query(query, variables): | |
return requests.post( | |
'https://api.github.com/graphql', | |
headers={ | |
'Content-Type': 'application/json', | |
'Accept': 'application/json', | |
'Authorization': f'bearer {AUTH_TOKEN}' | |
}, | |
json={ | |
'query': query, | |
'variables': variables | |
}).json() | |
if __name__ == '__main__': | |
res = run_query(GRAPHQL_QUERY, { | |
'query': 'org:my-org is:issue is:open label:"docs" sort:updated', | |
'last': 100 | |
}) | |
pprint.pprint(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment