Package: github3api
github3apiAn advanced REST client for the GitHub API. It is a subclass ofrest3clienttailored for the GitHub API with special optional directives for GET requests that can return all pages from an endpoint or return a generator that can be iterated over (for paged requests). By default all requests will be retried if ratelimit request limit is reached.Support for executing Graphql queries including paging; Graphql queries are also retried if Graphql rate limiting occurs.Installationpipinstallgithub3apiExample Usage>>>fromgithub3apiimportGitHubAPIGitHubAPIinstantiation# instantiate using no-auth>>>client=GitHubAPI()# instantiate using a token>>>client=GitHubAPI(bearer_token='****************')GETrequest# GET request - return JSON response>>>client.get('/rate_limit')['resources']['core']{'limit':60,'remaining':37,'reset':1588898701}# GET request - return raw resonse>>>client.get('/rate_limit',raw_response=True)<Response[200]>POSTrequest>>>client.post('/user/repos',json={'name':'test-repo1'})['full_name']'soda480/test-repo1'>>>client.post('/repos/soda480/test-repo1/labels',json={'name':'label1'})['url']'https://api.github.com/repos/soda480/test-repo1/labels/label1'PATCHrequest>>>client.patch('/repos/soda480/test-repo1/labels/label1',json={'description':'my label'})['url']'https://api.github.com/repos/soda480/test-repo1/labels/label1'DELETErequest>>>client.delete('/repos/soda480/test-repo1')GET alldirective - Get all pages from an endpoint and return list containing only matching attributesforrepoinclient.get('/orgs/edgexfoundry/repos',_get='all',_attributes=['full_name']):print(repo['full_name'])GET pagedirective - Yield a page from endpointforpageinclient.get('/user/repos',_get='page'):forrepoinpage:print(repo['full_name'])total- Get total number of resources at given endpointprint(client.total('/user/repos'))graphql- execute graphql queryquery="""query($query:String!, $page_size:Int!) {search(query: $query, type: REPOSITORY, first: $page_size) {repositoryCountedges {node {... on Repository {nameWithOwner}}}}}"""variables={"query":"org:edgexfoundry","page_size":100}client.graphql(query,variables)graphql paging- execute paged graphql queryquery="""query ($query: String!, $page_size: Int!, $cursor: String!) {search(query: $query, type: REPOSITORY, first: $page_size, after: $cursor) {repositoryCountpageInfo {endCursorhasNextPage}edges {cursornode {... on Repository {nameWithOwner}}}}}"""variables={"query":"org:edgexfoundry","page_size":100}forpageinclient.graphql(query,variables,page=True,keys='data.search'):forrepoinpage:print(repo['node']['nameWithOwner'])For Graphql paged queries:the query should include the necessary pageInfo and cursor attributesthe keys method argument is a dot annotated string that is used to access the resulting dictionary response objectthe query is retried every 60 seconds (for up to an hour) if a ratelimit occurProjects usinggithub3apiedgexfoundry/sync-github-labelsA script that synchronizes GitHub labels and milestonesedgexfoundry/prune-github-tagsA script that prunes GitHub pre-release tagsedgexfoundry/create-github-releaseA script to facilitate creation of GitHub releasessoda480/prepbadgeA script that creates multiple pull request workflows to update a target organization repos with badgessoda480/github-contributionsA script to get contribution metrics for all members of a GitHub organization using the GitHub GraphQL APIedgexfoundry/edgex-dev-badgeRules based GitHub badge scannerDevelopmentEnsure the latest version of Docker is installed on your development server. Fork and clone the repository.Build the Docker image:dockerimagebuild\--targetbuild-image\--build-arghttp_proxy\--build-arghttps_proxy\-t\github3api:latest.Run the Docker container:dockercontainerrun\--rm\-it\-ehttp_proxy\-ehttps_proxy\-v$PWD:/code\github3api:latest\bashExecute the build:pyb-XNOTE: commands above assume working behind a proxy, if not then the proxy arguments to both the docker build and run commands can be removed.