Skip to content

Instantly share code, notes, and snippets.

@mohankumargupta
Created February 22, 2018 03:24
Show Gist options
  • Save mohankumargupta/061fa50ce6c8ac8b620bf69a084ffcfa to your computer and use it in GitHub Desktop.
Save mohankumargupta/061fa50ce6c8ac8b620bf69a084ffcfa to your computer and use it in GitHub Desktop.
import requests
import json
headers = {'Authorization': 'Bearer 49beba867bca3b08df1252f837197b27ab529166'}
query_graphql = '''
query {
repository(owner: "mohankumargupta", name: "raspberrypi-ansible") {
ref(qualifiedName: "master") {
target {
... on Commit {
history(first: 1) {
edges {
node {
oid
}
}
}
}
}
}
}
}
'''
query = 'query { viewer { name }}'
query_json = json.dumps({"query": query_graphql.replace('\n', '')})
print(query_json)
response = requests.post(
'https://api.github.com/graphql',
query_json,
headers=headers)
response_json = response.json()
ref = response_json["data"]["repository"]["ref"]
print(ref["target"]["history"]["edges"][0]["node"]["oid"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment