Skip to content

Instantly share code, notes, and snippets.

@john012343210
Created August 5, 2020 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john012343210/d6c39098ec8fce2fd7531ff5a49b0880 to your computer and use it in GitHub Desktop.
Save john012343210/d6c39098ec8fce2fd7531ff5a49b0880 to your computer and use it in GitHub Desktop.
Getting repositories information of a user using github api v4
QUERY="""
query {
user(login:"AronWater") {
repositories(last:100) { ######### putting 100 here might generate timeout error
totalCount
totalDiskUsage
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
edges{
node{
assignableUsers(last:5) {
edges {
node{
email
}
}
totalCount
}
branchProtectionRules(last:100) {
totalCount
}
collaborators {
totalCount
}
commitComments {
totalCount
}
#dependencyGraphManifests {
# totalCount
#}
deployKeys {
totalCount
}
deployments {
totalCount
}
forks {
totalCount
}
issues{
totalCount
}
labels {
totalCount
}
languages {
totalCount
}
mentionableUsers {
totalCount
}
milestones {
totalCount
}
#packages {
# totalCount
#}
#pinnedIssues {
# totalCount
#}
projects {
totalCount
}
pullRequests {
totalCount
}
#refs {
# totalCount
#}
#registryPackages {
# totalCount
#}
#registryPackagesForQuery {
# totalCount
#}
releases {
totalCount
}
repositoryTopics {
totalCount
}
stargazers {
totalCount
}
submodules {
totalCount
}
vulnerabilityAlerts {
totalCount
}
watchers {
totalCount
}
codeOfConduct {
body
id
key
name
resourcePath
url
}
createdAt
databaseId
#defaultBranchRef
deleteBranchOnMerge
description
descriptionHTML
diskUsage
forkCount
#fundingLinks
hasIssuesEnabled
hasProjectsEnabled
hasWikiEnabled
homepageUrl
id
isArchived
isDisabled
isFork
isLocked
isMirror
isPrivate
isTemplate
#issue
#issueOrPullRequest
#label
licenseInfo {
body
#conditions
description
featured
hidden
id
implementation
key
#limitations
name
nickname
permissions{
description
key
label
}
pseudoLicense
spdxId
url
}
lockReason
mergeCommitAllowed
#milestone
mirrorUrl
name
nameWithOwner
#object
openGraphImageUrl
#owner
parent {
name
}
primaryLanguage {
color
id
name
}
#project
projectsResourcePath
projectsUrl
#pullRequest
pushedAt
rebaseMergeAllowed
#ref
#release
resourcePath
shortDescriptionHTML
squashMergeAllowed
sshUrl
tempCloneToken
templateRepository {
name
}
updatedAt
url
usesCustomOpenGraphImage
viewerCanAdminister
viewerCanCreateProjects
viewerCanSubscribe
viewerCanUpdateTopics
viewerHasStarred
viewerPermission
viewerSubscription
}
}
}
}
}
"""
import requests
YOUR_TOKEN="sometoken"
headers = {"Authorization": "Bearer "+YOUR_TOKEN}
request = requests.post('https://api.github.com/graphql', json={'query': QUERY}, headers=headers)
print(request.text)
############### what is printed
# {
# "data": null,
# "errors":[
# {
# "message":"Something went wrong while executing your query. This may be the result of a timeout, or it could be a GitHub bug. Please include `379D:5DCC:DB30B:241E40:5F2B4082` when reporting this issue."
# }
# ]
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment