【问题标题】:Github V4 graphql - Cant get organization user contribution infoGithub V4 graphql - 无法获取组织用户贡献信息
【发布时间】:2020-10-18 11:56:10
【问题描述】:

我是 Github API v3(rest)和 v4(graphql)的新手。

我创建了一个 PAT(个人访问令牌)并使用它从 github - 组织私有存储库中获取数据。

虽然能够使用 V3 api (REST) 在我的组织中获取其他用户数据(事件、提交、问题等),

使用 V4 api (Graphql) 时我无法获取信息 - 我仅在查询我自己的用户时获取信息,对于其他用户我获取零。

我使用的 graphql 查询(令牌设置在标题和我的组织中的一些用户):

query {
  user (login: "<user>") {
    contributionsCollection(from: "2020-01-01T00:00:00.000Z", to: "2020-06-25T23:59:59.999Z", organizationID: "<my_org_id>") {
      totalCommitContributions
      totalIssueContributions
      totalPullRequestContributions
      totalPullRequestReviewContributions
      totalRepositoriesWithContributedCommits
      totalRepositoriesWithContributedIssues
      totalRepositoriesWithContributedPullRequestReviews
      totalRepositoriesWithContributedPullRequests
    }
  }
}

和归零的响应(查询自己时我得到非零值):

{
  "data": {
    "user": {
      "contributionsCollection": {
        "totalCommitContributions": 0,
        "totalIssueContributions": 0,
        "totalPullRequestContributions": 0,
        "totalPullRequestReviewContributions": 0,
        "totalRepositoriesWithContributedCommits": 0,
        "totalRepositoriesWithContributedIssues": 0,
        "totalRepositoriesWithContributedPullRequestReviews": 0,
        "totalRepositoriesWithContributedPullRequests": 0
      }
    }
  }
}

在 REST api 中:

curl -H "Authorization: token <TOKEN>" -X GET 'https://api.github.com/users/<user>/events?page=1&per_page=10'

我得到信息(在上面的指定日期)

我错过了什么?

【问题讨论】:

    标签: github github-api github-graphql


    【解决方案1】:

    从这里开始:

    #!/bin/bash
    
    query=" \
     { \
       \"query\": \"query  \
      { \
        repository(owner: \\\"MyOrg\\\", name: \\\"some-repo-name\\\") {\
          issues(last: 50, states: OPEN, labels: \\\"some label\\\") {\
            edges {\
              node {\
                title\
                body\
                url\
                createdAt\
                lastEditedAt\
              }\
            }\
          }\
        }\
      } \" \
     } \
    "
    
    curl -H "Authorization: bearer XX-your-PAT-goes-here-XX" \
      -X POST \
      -d "${query%%$'\n*'}" \
      https://api.github.com/graphql |
      jq --compact-output '.[] | .repository.issues.edges[] | .node' |
      while read -r object; do
        echo "================================"
    
        # determine last edit date and time
        lastEditedAt=$(prettify_date $(echo "$object" | jq '.lastEditedAt'))
        createdAt=$(prettify_date $(echo "$object" | jq '.createdAt'))
    
        echo "${createdAt} -- ${lastEditedAt}"
    
        [[ ${lastEditedAt} == nul ]] &&
          reallyLastEditedAt="${createdAt}" ||
          reallyLastEditedAt="${lastEditedAt}"
    
        title=$(echo "$object" | jq '.title')
        content="$(echo "$object" | jq '.body' | sed -e 's/^"//' -e 's/"$//')"
        
        echo ${content} | sed 's!\\r\\n!\n!g' 
       done
    

    【讨论】:

      猜你喜欢
      • 2018-09-24
      • 2017-11-18
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      相关资源
      最近更新 更多