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

后端 未结 3 2031
长发绾君心
长发绾君心 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 <<EOF
    {
     "query": "query { repositoryOwner(login: \"bertrandmartel\") { ... on User { pinnedRepositories(first:6) { edges { node { name } } } } } }"
    }
    EOF
    

    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'
    
    0 讨论(0)
  • 2020-12-29 15:30

    Go to this URL and type your username and hit the "go" button. There you will see your pinned repos as a JSON responce.

    Click here

    Or else, you can replace your username in the below link.

    https://gh-pinned-repos-5l2i19um3.vercel.app/?username={Username}
    

    For more info: Click here or here

    0 讨论(0)
  • 2020-12-29 15:36

    An update to the original answer:

    The changelog for GitHub GraphQL schema (2019-03-30) mentions that the pinnedRepositories will be deprecated or removed by 2019-07-01. GraphQL API users are requested to use ProfileOwner.pinnedItems instead.

    Examples to retrieve pinned repositories using ProfileOwner.pinnedItems:

    Example 1:

    query {
        user(login:"kranthilakum") {
        pinnedItems(first: 5, types: [REPOSITORY, GIST]) {
          totalCount
          edges {
            node {
              ... on Repository {
                name
              }
            }
          }
        }
      }
    }
    

    Try Example 1 in the GraphQL API Explorer

    Example 2:

    query {
      repositoryOwner(login: "kranthilakum") {
        ... on ProfileOwner {
          pinnedItemsRemaining
          itemShowcase {
            items(first: 5) {
              totalCount
              edges {
                node {
                  ... on Repository {
                    name
                  }
                }
              }
            }
            hasPinnedItems
          }
        }
      }
    }
    

    Try Example 2 in GraphQL API Explorer

    0 讨论(0)
提交回复
热议问题