Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 7

GraphQL Github V4 Api - Get last activity for a user in an organisation

Hello,

 

I am finding a way to get the date of users's organisation last activity.  

Someone can help me ?

 

Thank you for your answers.

6 Replies
Community Manager
Message 2 of 7

Re: GraphQL Github V4 Api - Get last activity for a user in an organisation

That's a really hard question to answer. It depends on what you mean by "activity". Do you mean only commits in repositories? Do you mean opening issues or PRs? Do you mean commenting on an issue or PR? All of the above?

 

If you only mean activity on issues or PRs, you could perhaps use the search connection and order by latest. But if you mean all of the above, you're going to have to look through a bunch of different data types and figure out the "last" one across all of them. There isn't going to be a single query to give you the answer.

 

Let us know if you have more questions.

Copilot Lvl 3
Message 3 of 7

Re: GraphQL Github V4 Api - Get last activity for a user in an organisation

By "activity" I want to find the same data like in the graph in user details page.

 

I have found Contributions Collection object in the api v4, and I tried to do something in this way.

However with this route, I found only the contributing datas of outside the organization.

Example of query :

query {
  organization(login: "my-organization") {
    samlIdentityProvider {
      externalIdentities(first: 50) {
        nodes {
          samlIdentity {
            nameId
          }
          user {
            contributionsCollection(from: "2019-05-04T00:00:00"  to: "2019-11-05T00:00:00" ) {
              startedAt
              endedAt
              hasAnyContributions
              hasActivityInThePast
            }
          }
        }
      }
    }
  }
}

 

I would like to find a way with an unique query because if I do 2 or 3 query for each users the time of request will be so big.

 

Someone has already use Contributions Collection to get graph user details datas ?

Community Manager
Message 4 of 7

Re: GraphQL Github V4 Api - Get last activity for a user in an organisation

You'll notice that the `contributionsCollection` connection has an `organizationID` parameter that allows you to filter contributions. You can get an organization's ID with the following query:

 

{
  organization(login: "my-organization") {
    id
  }
}

That should allow you to filter the contributions the way you're describing.

Copilot Lvl 3
Message 5 of 7

Re: GraphQL Github V4 Api - Get last activity for a user in an organisation

Thank you for your quick reply.

 

Unfortunately, I have already try this solution :

contributionsCollection(organizationID:"MyOrganisationId" from: "2019-05-04T00:00:00"  to: "2019-11-05T00:00:00" ) {
              startedAt
              endedAt
              hasAnyContributions
              hasActivityInThePast
              totalRepositoryContributions
              totalIssueContributions
              totalCommitContributions
              totalPullRequestContributions
            }

And I got :

"user": {
                "contributionsCollection": {
                  "startedAt": "2019-05-04T07:00:00Z",
                  "endedAt": "2019-11-05T08:00:00Z",
                  "hasAnyContributions": false,
                  "hasActivityInThePast": true,
                  "totalRepositoryContributions": 0,
                  "totalIssueContributions": 0,
                  "totalCommitContributions": 0,
                  "totalPullRequestContributions": 0
                }

For an active user:

Capture.PNG

 

Do you have any other idea ?

Community Manager
Message 6 of 7

Re: GraphQL Github V4 Api - Get last activity for a user in an organisation

To my understanding, private contributions can't currently be queried via the API. So if the contribution graph data you're looking at is from private contributions, then it won't show up in the `contributionsCollection`.

Copilot Lvl 3
Message 7 of 7

Re: GraphQL Github V4 Api - Get last activity for a user in an organisation

Thank you for your answer.

 

It's right, I am looking for private contributions inside an organisation.

 

I will try to find another solution.