How do I make an API call to GitHub for a user's pinned repositories?

后端 未结 3 2030
长发绾君心
长发绾君心 2020-12-29 14:31

On GitHub, a user can have pinned repositories.

There\'s also the Repositories section of the API describing how to make requests that involve repos. You can also ge

3条回答
  •  情话喂你
    2020-12-29 15:26

    You can get pinned repository using Github GraphQL API :

    {
      repositoryOwner(login: "bertrandmartel") {
        ... on User {
          pinnedRepositories(first:6) {
            edges {
              node {
                name
              }
            }
          }
        }
      }
    }
    

    Try it in the explorer

    You can request it with curl with :

    curl -H "Authorization: bearer TOKEN" --data-binary @- https://api.github.com/graphql <

    You can parse the JSON output with jq JSON parser :

    username=bertrandmartel
    curl -s -H "Authorization: bearer TOKEN" \
         -d '{ "query": "query { repositoryOwner(login: \"'"$username"'\") { ... on User { pinnedRepositories(first:6) { edges { node { name } } } } } }" }' \
         https://api.github.com/graphql | \
         jq -r '.data.repositoryOwner.pinnedRepositories.edges[].node.name'
    

提交回复
热议问题