Skip to content

Instantly share code, notes, and snippets.

@mohankumargupta
Created February 22, 2018 03:24

Revisions

  1. mohankumargupta created this gist Feb 22, 2018.
    35 changes: 35 additions & 0 deletions latestCommit.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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"])