Skip to content

Instantly share code, notes, and snippets.

@rafaeldelboni
Created November 27, 2024 19:03
Show Gist options
  • Save rafaeldelboni/4f269b696edbe48c310e7edb918df9a7 to your computer and use it in GitHub Desktop.
Save rafaeldelboni/4f269b696edbe48c310e7edb918df9a7 to your computer and use it in GitHub Desktop.
Year on Github

Fetch Your Year of GitHub Contributions

I was struggling to kick off my self-assessment feedback for the year, so I came up with an idea to use the GitHub API to provide relevant data and jumpstart my writing process.

Query

I started with this simple query:

query userInfo($login: String!) {
  user(login: $login) {
    name
    repositoriesContributedTo(
      first: 100
      includeUserRepositories: true
      contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]
    ) {
      totalCount
      pageInfo {
        endCursor
        hasNextPage
      }
    }
    contributionsCollection(from:"2024-01-01T00:00:00.000Z", to:"2024-12-31T00:00:00.000Z") {
        commitContributionsByRepository(maxRepositories: 100) {
        repository {
          nameWithOwner,
          description
        }
        contributions {
          totalCount
        }
      }
      pullRequestContributionsByRepository(maxRepositories: 100) {
        repository {
          nameWithOwner,
          description
        }
        contributions {
          totalCount
        }
      }
      totalCommitContributions
      totalIssueContributions
      totalPullRequestContributions
      totalPullRequestReviewContributions
    }
  }
}

Fetching

Next, I used the official GitHub GraphQL Explorer: https://docs.github.com/en/graphql/overview/explorer

Note: Don’t forget to add the query variables:
{ "login": "your-gh-handle" }

This query provides a JSON output containing your contributions, including commits, pull requests, repository names, and descriptions. It's a great starting point for building a detailed self-assessment based on your activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment