11"use strict" ;
2- exports . id = 317 ;
3- exports . ids = [ 317 ] ;
2+ exports . id = 407 ;
3+ exports . ids = [ 407 ] ;
44exports . modules = {
55
6- /***/ 5317 :
6+ /***/ 407 :
77/***/ ( ( __unused_webpack_module , __webpack_exports__ , __webpack_require__ ) => {
88
99// ESM COMPAT FLAG
@@ -17,37 +17,8 @@ __webpack_require__.d(__webpack_exports__, {
1717// EXTERNAL MODULE: ../../node_modules/node-fetch/lib/index.js
1818var lib = __webpack_require__ ( 2197 ) ;
1919var lib_default = /*#__PURE__*/ __webpack_require__ . n ( lib ) ;
20- ; // CONCATENATED MODULE: ../github-user-contribution/formatParams.ts
21- const formatParams = ( options = { } ) => {
22- const sp = new URLSearchParams ( ) ;
23- const o = { ...options } ;
24- if ( "year" in options ) {
25- o . from = `${ options . year } -01-01` ;
26- o . to = `${ options . year } -12-31` ;
27- }
28- for ( const s of [ "from" , "to" ] )
29- if ( o [ s ] ) {
30- const value = o [ s ] ;
31- if ( value >= formatDate ( new Date ( ) ) )
32- throw new Error ( "Cannot get contribution for a date in the future.\nPlease limit your range to the current UTC day." ) ;
33- sp . set ( s , value ) ;
34- }
35- return sp . toString ( ) ;
36- } ;
37- const formatDate = ( d ) => {
38- const year = d . getUTCFullYear ( ) ;
39- const month = d . getUTCMonth ( ) + 1 ;
40- const date = d . getUTCDate ( ) ;
41- return [
42- year ,
43- month . toString ( ) . padStart ( 2 , "0" ) ,
44- date . toString ( ) . padStart ( 2 , "0" ) ,
45- ] . join ( "-" ) ;
46- } ;
47-
4820; // CONCATENATED MODULE: ../github-user-contribution/index.ts
4921
50-
5122/**
5223 * get the contribution grid from a github user page
5324 *
@@ -64,43 +35,50 @@ const formatDate = (d) => {
6435 * getGithubUserContribution("platane", { year: 2019 })
6536 *
6637 */
67- const getGithubUserContribution = async ( userName , options = { } ) => {
68- // either use github.com/users/xxxx/contributions for previous years
69- // or github.com/xxxx ( which gives the latest update to today result )
70- const url = "year" in options || "from" in options || "to" in options
71- ? `https://github.com/users/${ userName } /contributions?` +
72- formatParams ( options )
73- : `https://github.com/${ userName } ` ;
74- const res = await lib_default ( ) ( url ) ;
38+ const getGithubUserContribution = async ( userName , o ) => {
39+ const query = /* GraphQL */ `
40+ query ($login: String!) {
41+ user(login: $login) {
42+ contributionsCollection {
43+ contributionCalendar {
44+ weeks {
45+ contributionDays {
46+ contributionCount
47+ contributionLevel
48+ weekday
49+ date
50+ }
51+ }
52+ }
53+ }
54+ }
55+ }
56+ ` ;
57+ const variables = { login : userName } ;
58+ const res = await lib_default ( ) ( "https://api.github.com/graphql" , {
59+ headers : {
60+ Authorization : `bearer ${ o . githubToken } ` ,
61+ "Content-Type" : "application/json" ,
62+ } ,
63+ method : "POST" ,
64+ body : JSON . stringify ( { variables, query } ) ,
65+ } ) ;
7566 if ( ! res . ok )
7667 throw new Error ( res . statusText ) ;
77- const resText = await res . text ( ) ;
78- return parseUserPage ( resText ) ;
79- } ;
80- const parseUserPage = ( content ) => {
81- // take roughly the table block
82- const block = content
83- . split ( `aria-describedby="contribution-graph-description"` ) [ 1 ]
84- . split ( "<tbody>" ) [ 1 ]
85- . split ( "</tbody>" ) [ 0 ] ;
86- const cells = block . split ( "</tr>" ) . flatMap ( ( inside , y ) => inside . split ( "</td>" ) . flatMap ( ( m ) => {
87- const date = m . match ( / d a t a - d a t e = " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
88- const literalLevel = m . match ( / d a t a - l e v e l = " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
89- const literalX = m . match ( / d a t a - i x = " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
90- const literalCount = m . match ( / ( N o | \d + ) c o n t r i b u t i o n s ? o n / ) ?. [ 1 ] ;
91- if ( date && literalLevel && literalX && literalCount )
92- return [
93- {
94- x : + literalX ,
95- y,
96- date,
97- count : + literalCount ,
98- level : + literalLevel ,
99- } ,
100- ] ;
101- return [ ] ;
102- } ) ) ;
103- return cells ;
68+ const { data, errors } = ( await res . json ( ) ) ;
69+ if ( errors ?. [ 0 ] )
70+ throw errors [ 0 ] ;
71+ return data . user . contributionsCollection . contributionCalendar . weeks . flatMap ( ( { contributionDays } , x ) => contributionDays . map ( ( d ) => ( {
72+ x,
73+ y : d . weekday ,
74+ date : d . date ,
75+ count : d . contributionCount ,
76+ level : ( d . contributionLevel === "FOURTH_QUARTILE" && 4 ) ||
77+ ( d . contributionLevel === "THIRD_QUARTILE" && 3 ) ||
78+ ( d . contributionLevel === "SECOND_QUARTILE" && 2 ) ||
79+ ( d . contributionLevel === "FIRST_QUARTILE" && 1 ) ||
80+ 0 ,
81+ } ) ) ) ;
10482} ;
10583
10684// EXTERNAL MODULE: ../types/grid.ts
@@ -655,9 +633,9 @@ const getPathToPose = (snake0, target, grid) => {
655633
656634
657635
658- const generateContributionSnake = async ( userName , outputs ) => {
636+ const generateContributionSnake = async ( userName , outputs , options ) => {
659637 console . log ( "🎣 fetching github user contribution" ) ;
660- const cells = await getGithubUserContribution ( userName ) ;
638+ const cells = await getGithubUserContribution ( userName , options ) ;
661639 const grid = userContributionToGrid ( cells ) ;
662640 const snake = snake4 ;
663641 console . log ( "📡 computing best route" ) ;
0 commit comments