1

I'm new to Github API v3 (rest) & v4 (graphql).

I have created a PAT (personal access token) and using it to fetch data from github - organization private repositories.

While able to get other users data (event, commits, issues etc.) in my organization with V3 api (REST),

I can't get information when using V4 api (Graphql) - I get info only when querying my own user, for other users I get zeros.

The graphql query I use (token is set in the header and some user in my org):

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
    }
  }
}

and the zeroed response (when querying myself I get non-zero values):

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

While in REST api:

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

I get information (on the specified dates above)

What am I missing?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AsafG
  • 136
  • 1
  • 9

1 Answers1

0

Start with this:

#!/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
Markus W.
  • 307
  • 3
  • 10