Getting Github individual file contributors

后端 未结 4 647
后悔当初
后悔当初 2020-12-31 11:23

I am planning to build a plug-in for Sphinx documentation system plug-in which shows the names and Github profile links of the persons who have contributed to the documentat

4条回答
  •  失恋的感觉
    2020-12-31 11:49

    Using GraphQL API v4, you can use :

    {
      repository(owner: "torvalds", name: "linux") {
        object(expression: "master") {
          ... on Commit {
            history(first: 100, path: "MAINTAINERS") {
              nodes {
                author {
                  email
                  name
                  user {
                    email
                    name
                    avatarUrl
                    login
                    url
                  }
                }
              }
            }
          }
        }
      }
    }
    

    Try it in the explorer

    Using curl & jq to have a list of the first 100 contributors of this file without duplicates :

    TOKEN=
    OWNER=torvalds
    REPO=linux
    BRANCH=master
    FILEPATH=MAINTAINERS
    curl -s -H "Authorization: token $TOKEN" \
         -H  "Content-Type:application/json" \
         -d '{ 
              "query": "{repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") {object(expression: \"'"$BRANCH"'\") { ... on Commit { history(first: 100, path: \"'"$FILEPATH"'\") { nodes { author { email name user { email name avatarUrl login url}}}}}}}}"
          }' https://api.github.com/graphql | \
          jq '[.data.repository.object.history.nodes[].author| {name,email}]|unique'
    

提交回复
热议问题