@@ -58,3 +58,65 @@ export const getGitHubContributions = async (
5858 contributionsPerYear
5959 } ;
6060} ;
61+
62+
63+ type PerTypeYearContributions = {
64+ year : number ;
65+ commits : number ;
66+ pullRequests : number ;
67+ reviews : number ;
68+ issues : number ;
69+ } ;
70+
71+ export const getGitHubContributionTypesPerYear = async (
72+ username : string ,
73+ startYear : number ,
74+ token ?: string
75+ ) : Promise < PerTypeYearContributions [ ] > => {
76+ const contributionsPerYear : PerTypeYearContributions [ ] = [ ] ;
77+ const currentYear = new Date ( ) . getFullYear ( ) ;
78+
79+ const yearQuery = `
80+ query ($login: String!, $from: DateTime!, $to: DateTime!) {
81+ user(login: $login) {
82+ contributionsCollection(from: $from, to: $to) {
83+ totalCommitContributions
84+ totalPullRequestContributions
85+ totalPullRequestReviewContributions
86+ totalIssueContributions
87+ }
88+ }
89+ }
90+ ` ;
91+
92+ for ( let year = startYear ; year <= currentYear ; year ++ ) {
93+ const from = `${ year } -01-01T00:00:00Z` ;
94+ const to =
95+ year === currentYear
96+ ? new Date ( ) . toISOString ( )
97+ : `${ year } -12-31T23:59:59Z` ;
98+
99+ const yearData = await githubGraphQL < {
100+ user : {
101+ contributionsCollection : {
102+ totalCommitContributions : number ;
103+ totalPullRequestContributions : number ;
104+ totalPullRequestReviewContributions : number ;
105+ totalIssueContributions : number ;
106+ } ;
107+ } ;
108+ } > ( yearQuery , { login : username , from, to } , token ) ;
109+
110+ const cc = yearData . user . contributionsCollection ;
111+
112+ contributionsPerYear . push ( {
113+ year,
114+ commits : cc . totalCommitContributions ,
115+ pullRequests : cc . totalPullRequestContributions ,
116+ reviews : cc . totalPullRequestReviewContributions ,
117+ issues : cc . totalIssueContributions
118+ } ) ;
119+ }
120+
121+ return contributionsPerYear ;
122+ } ;
0 commit comments