Reputation: 2741
I have used the below GitHub api and i'am able to get the files details of the path.
The result of this API call is :
[
{
"name": ".DS_Store",
"path": "Compile/Tables/test",
"sha": "1cef8efa8694678e3b7ab230a6a891afa1a1996d",
"size": 8196,
"url": "***",
"html_url": "***",
"git_url": "***",
"download_url": "***",
"type": "file",
"_links": {
"self": "***",
"git": "***",
"html": "***"
}
}]
I need to get the commit date details for the sha in this response.
"sha": "1cef8efa8694678e3b7ab230a6a891afa1a1996d"
I have tried using another API ,which is :
but the response of this API for this sha is:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/enterprise/2.14/v3/repos/commits/#get-a-single-commit"}
How can we get commit date details along with GitHub content details by using API calls?
Upvotes: 0
Views: 719
Reputation: 2741
finally got the expected result by using Graphql.here is the complete code
def run_query(query): # A simple function to use requests.post to make the API call. Note the json= section.
try:
request = requests.post('https://api.github.***.com/graphql', json={'query': query}, headers=headers)
return request.json()
except e:
returnVal = '404'
query = """
{
repository(owner: \""""+ownerVal+"""\", name: \""""+repoVal+"""\") {
object(expression: \""""+branchVal+"""\") {
... on Commit {
blame(path: \""""+folderVal+"/"+data['name']+"""\") {
ranges {
commit {
committedDate
}
}
}
}
}
}
}
"""
headers = {"Authorization": "Bearer "+access_token}
result = run_query(query)
commit_date = result["data"]["repository"]["object"]["blame"]["ranges"][0]["commit"]["committedDate"]
Upvotes: 0