-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface Contributor { | ||
login: string; | ||
id: number; | ||
node_id: string; | ||
avatar_url: string; | ||
gravatar_id: string; | ||
url: string; | ||
html_url: string; | ||
followers_url: string; | ||
following_url: string; | ||
gists_url: string; | ||
starred_url: string; | ||
subscriptions_url: string; | ||
organizations_url: string; | ||
repos_url: string; | ||
events_url: string; | ||
received_events_url: string; | ||
type: string; | ||
site_admin: boolean; | ||
contributions: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ul { | ||
list-style: none; | ||
} | ||
|
||
li { | ||
width: 50px; | ||
height: 50px; | ||
float: left; | ||
} | ||
|
||
img { | ||
width: 100%; | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<!DOCTYPE html><link rel="stylesheet" href="contributors.css"><ul><li title="PKief"><img src="https://avatars2.githubusercontent.com/u/12248527?v=4" alt="PKief"/></li> | ||
<li title="AdrieanKhisbe"><img src="https://avatars1.githubusercontent.com/u/2601132?v=4" alt="AdrieanKhisbe"/></li> | ||
<li title="dudeofawesome"><img src="https://avatars0.githubusercontent.com/u/1683595?v=4" alt="dudeofawesome"/></li> | ||
<li title="wopian"><img src="https://avatars0.githubusercontent.com/u/3440094?v=4" alt="wopian"/></li> | ||
<li title="Bakosa666"><img src="https://avatars3.githubusercontent.com/u/38684615?v=4" alt="Bakosa666"/></li> | ||
<li title="diego3g"><img src="https://avatars2.githubusercontent.com/u/2254731?v=4" alt="diego3g"/></li> | ||
<li title="felipe-fg"><img src="https://avatars2.githubusercontent.com/u/32036831?v=4" alt="felipe-fg"/></li> | ||
<li title="jBugman"><img src="https://avatars1.githubusercontent.com/u/891785?v=4" alt="jBugman"/></li> | ||
<li title="iFaxity"><img src="https://avatars3.githubusercontent.com/u/9090703?v=4" alt="iFaxity"/></li> | ||
<li title="melMass"><img src="https://avatars3.githubusercontent.com/u/7041726?v=4" alt="melMass"/></li> | ||
<li title="Mrgove10"><img src="https://avatars0.githubusercontent.com/u/25491408?v=4" alt="Mrgove10"/></li> | ||
<li title="cezarsa"><img src="https://avatars1.githubusercontent.com/u/11041?v=4" alt="cezarsa"/></li> | ||
<li title="KristophUK"><img src="https://avatars2.githubusercontent.com/u/6653181?v=4" alt="KristophUK"/></li> | ||
<li title="jediyozh"><img src="https://avatars2.githubusercontent.com/u/31045769?v=4" alt="jediyozh"/></li> | ||
<li title="fahmiirsyadk"><img src="https://avatars0.githubusercontent.com/u/17546686?v=4" alt="fahmiirsyadk"/></li> | ||
<li title="iDaN5x"><img src="https://avatars3.githubusercontent.com/u/3427523?v=4" alt="iDaN5x"/></li> | ||
<li title="jtiala"><img src="https://avatars2.githubusercontent.com/u/1576782?v=4" alt="jtiala"/></li> | ||
<li title="mvochoa"><img src="https://avatars2.githubusercontent.com/u/7919838?v=4" alt="mvochoa"/></li> | ||
<li title="teototaro"><img src="https://avatars3.githubusercontent.com/u/6552833?v=4" alt="teototaro"/></li> | ||
<li title="niksudan"><img src="https://avatars1.githubusercontent.com/u/6004491?v=4" alt="niksudan"/></li> | ||
<li title="yuric18"><img src="https://avatars3.githubusercontent.com/u/18277197?v=4" alt="yuric18"/></li> | ||
<li title="denisbalyko"><img src="https://avatars0.githubusercontent.com/u/638190?v=4" alt="denisbalyko"/></li> | ||
<li title="dotiful"><img src="https://avatars1.githubusercontent.com/u/25269527?v=4" alt="dotiful"/></li> | ||
<li title="ycrepeau"><img src="https://avatars2.githubusercontent.com/u/6821466?v=4" alt="ycrepeau"/></li> | ||
<li title="aashutoshrathi"><img src="https://avatars2.githubusercontent.com/u/21199234?v=4" alt="aashutoshrathi"/></li> | ||
<li title="dabrowski-adam"><img src="https://avatars0.githubusercontent.com/u/6993966?v=4" alt="dabrowski-adam"/></li> | ||
<li title="alefesouza"><img src="https://avatars2.githubusercontent.com/u/1693223?v=4" alt="alefesouza"/></li> | ||
<li title="baraalex"><img src="https://avatars2.githubusercontent.com/u/6618800?v=4" alt="baraalex"/></li> | ||
<li title="tothandras"><img src="https://avatars0.githubusercontent.com/u/4157749?v=4" alt="tothandras"/></li> | ||
<li title="arpadbarta"><img src="https://avatars3.githubusercontent.com/u/6329203?v=4" alt="arpadbarta"/></li> | ||
<li title="frederick036"><img src="https://avatars2.githubusercontent.com/u/1129770?v=4" alt="frederick036"/></li> | ||
<li title="bernardop"><img src="https://avatars1.githubusercontent.com/u/28455?v=4" alt="bernardop"/></li> | ||
<li title="bcanseco"><img src="https://avatars3.githubusercontent.com/u/18430599?v=4" alt="bcanseco"/></li> | ||
<li title="bradlc"><img src="https://avatars0.githubusercontent.com/u/2615508?v=4" alt="bradlc"/></li> | ||
<li title="brennongs"><img src="https://avatars3.githubusercontent.com/u/24623425?v=4" alt="brennongs"/></li> | ||
<li title="chrsmutti"><img src="https://avatars1.githubusercontent.com/u/34144667?v=4" alt="chrsmutti"/></li> | ||
<li title="TheCloudSaver"><img src="https://avatars3.githubusercontent.com/u/39653530?v=4" alt="TheCloudSaver"/></li> | ||
<li title="danielbankhead"><img src="https://avatars3.githubusercontent.com/u/10792787?v=4" alt="danielbankhead"/></li> | ||
<li title="oodavid"><img src="https://avatars3.githubusercontent.com/u/46879?v=4" alt="oodavid"/></li> | ||
<li title="erikphansen"><img src="https://avatars1.githubusercontent.com/u/20728956?v=4" alt="erikphansen"/></li> | ||
<li title="etiennetalbot"><img src="https://avatars3.githubusercontent.com/u/2954511?v=4" alt="etiennetalbot"/></li> | ||
<li title="ExE-Boss"><img src="https://avatars0.githubusercontent.com/u/3889017?v=4" alt="ExE-Boss"/></li> | ||
<li title="justalemon"><img src="https://avatars1.githubusercontent.com/u/11861253?v=4" alt="justalemon"/></li> | ||
<li title="JakubKoralewski"><img src="https://avatars0.githubusercontent.com/u/43069023?v=4" alt="JakubKoralewski"/></li> | ||
<li title="wersimmon"><img src="https://avatars1.githubusercontent.com/u/185822?v=4" alt="wersimmon"/></li> | ||
<li title="JotaroS"><img src="https://avatars2.githubusercontent.com/u/9479730?v=4" alt="JotaroS"/></li> | ||
<li title="RunningCoderLee"><img src="https://avatars3.githubusercontent.com/u/13218863?v=4" alt="RunningCoderLee"/></li> | ||
<li title="Krzysztof-Cieslak"><img src="https://avatars1.githubusercontent.com/u/5427083?v=4" alt="Krzysztof-Cieslak"/></li> | ||
<li title="kkemple"><img src="https://avatars3.githubusercontent.com/u/3629876?v=4" alt="kkemple"/></li> | ||
<li title="leohxj"><img src="https://avatars3.githubusercontent.com/u/1506900?v=4" alt="leohxj"/></li> | ||
<li title="LukasPolak"><img src="https://avatars3.githubusercontent.com/u/17145302?v=4" alt="LukasPolak"/></li> | ||
<li title="mjbvz"><img src="https://avatars2.githubusercontent.com/u/12821956?v=4" alt="mjbvz"/></li> | ||
<li title="MeirionHughes"><img src="https://avatars2.githubusercontent.com/u/3584509?v=4" alt="MeirionHughes"/></li> | ||
<li title="melkarm"><img src="https://avatars2.githubusercontent.com/u/32730892?v=4" alt="melkarm"/></li> | ||
<li title="epitaphmike"><img src="https://avatars1.githubusercontent.com/u/677832?v=4" alt="epitaphmike"/></li> | ||
<li title="olehreznichenko"><img src="https://avatars0.githubusercontent.com/u/11960153?v=4" alt="olehreznichenko"/></li> | ||
<li title="TheDutchCoder"><img src="https://avatars2.githubusercontent.com/u/1668207?v=4" alt="TheDutchCoder"/></li> | ||
<li title="rhysforyou"><img src="https://avatars0.githubusercontent.com/u/320910?v=4" alt="rhysforyou"/></li> | ||
<li title="rfgamaral"><img src="https://avatars1.githubusercontent.com/u/96476?v=4" alt="rfgamaral"/></li> | ||
<li title="kukiric"><img src="https://avatars2.githubusercontent.com/u/6194377?v=4" alt="kukiric"/></li> | ||
<li title="richardmillen94"><img src="https://avatars2.githubusercontent.com/u/22445885?v=4" alt="richardmillen94"/></li> | ||
<li title="richiksc"><img src="https://avatars1.githubusercontent.com/u/8939680?v=4" alt="richiksc"/></li> | ||
<li title="Faultless"><img src="https://avatars1.githubusercontent.com/u/7265811?v=4" alt="Faultless"/></li> | ||
<li title="sbekrin"><img src="https://avatars0.githubusercontent.com/u/9248479?v=4" alt="sbekrin"/></li> | ||
<li title="leggsimon"><img src="https://avatars2.githubusercontent.com/u/11544418?v=4" alt="leggsimon"/></li> | ||
<li title="ffrinds"><img src="https://avatars3.githubusercontent.com/u/26288489?v=4" alt="ffrinds"/></li> | ||
<li title="ThomasGeek"><img src="https://avatars1.githubusercontent.com/u/10091122?v=4" alt="ThomasGeek"/></li> | ||
<li title="timsneath"><img src="https://avatars3.githubusercontent.com/u/2319867?v=4" alt="timsneath"/></li> | ||
<li title="titouancreach"><img src="https://avatars1.githubusercontent.com/u/3995719?v=4" alt="titouancreach"/></li> | ||
<li title="Happycoil"><img src="https://avatars2.githubusercontent.com/u/12999248?v=4" alt="Happycoil"/></li> | ||
<li title="william-lohan"><img src="https://avatars3.githubusercontent.com/u/8146733?v=4" alt="william-lohan"/></li> | ||
<li title="dmay"><img src="https://avatars0.githubusercontent.com/u/1068398?v=4" alt="dmay"/></li> | ||
<li title="eyal0803"><img src="https://avatars1.githubusercontent.com/u/5116133?v=4" alt="eyal0803"/></li> | ||
<li title="mintapp"><img src="https://avatars0.githubusercontent.com/u/37894041?v=4" alt="mintapp"/></li> | ||
<li title="natemoo-re"><img src="https://avatars0.githubusercontent.com/u/7118177?v=4" alt="natemoo-re"/></li> | ||
<li title="suazithustra"><img src="https://avatars3.githubusercontent.com/u/33040041?v=4" alt="suazithustra"/></li> | ||
<li title="khrystuk"><img src="https://avatars2.githubusercontent.com/u/22624868?v=4" alt="khrystuk"/></li></ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import * as https from 'https'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as painter from '../helpers/painter'; | ||
import { Contributor } from '../../models/scripts/contributors/contributor'; | ||
|
||
/** | ||
* Parse link header | ||
* @param linkHeader Link header as string | ||
* @returns Object that contains the page numbers of `prev`, `next` and `last`. | ||
*/ | ||
const parseLinkHeader = (linkHeader: string) => { | ||
const nextPagePattern = new RegExp(/\bpage=(\d)[^>]*>;\srel="next"/); | ||
const lastPagePattern = new RegExp(/\bpage=(\d)[^>]*>;\srel="last"/); | ||
const prevPagePattern = new RegExp(/\bpage=(\d)[^>]*>;\srel="prev"/); | ||
|
||
const nextPage = nextPagePattern.exec(linkHeader); | ||
const lastPage = lastPagePattern.exec(linkHeader); | ||
const prevPage = prevPagePattern.exec(linkHeader); | ||
|
||
return { nextPage, lastPage, prevPage }; | ||
}; | ||
|
||
/** | ||
* Get all contributors from GitHub API. | ||
*/ | ||
const fetchContributors = (page: string): Promise<{ contributorsOfPage: Contributor[], nextPage: string }> => { | ||
return new Promise((resolve, reject) => { | ||
const requestOptions: https.RequestOptions = { | ||
method: 'GET', | ||
hostname: 'api.github.com', | ||
path: `/repos/pkief/vscode-material-icon-theme/contributors?page=${page}`, | ||
port: 443, | ||
headers: { | ||
'link': 'next', | ||
'accept': 'application/json', | ||
'User-Agent': 'Contributors script', | ||
}, | ||
}; | ||
|
||
const req = https.request(requestOptions, (res) => { | ||
const { nextPage, lastPage, prevPage } = parseLinkHeader(res.headers.link.toString()); | ||
console.log('> Material Icon Theme:', painter.yellow(`[${page}/${lastPage ? lastPage[1] : +prevPage[1] + 1}] Loading contributors from GitHub...`)); | ||
const result = []; | ||
res.on('data', (data: Buffer) => { | ||
result.push(data); | ||
}); | ||
|
||
res.on('end', () => { | ||
try { | ||
const buffer = Buffer.concat(result); | ||
const bufferAsString = buffer.toString('utf8'); | ||
const contributorsOfPage = JSON.parse(bufferAsString); | ||
resolve({ contributorsOfPage, nextPage: nextPage ? nextPage[1] : undefined }); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}); | ||
|
||
req.on('error', (error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
|
||
req.end(); | ||
}); | ||
}; | ||
|
||
const createContributorsList = (contributors: Contributor[]) => { | ||
const list = contributors.map(c => { | ||
return `<li title="${c.login}"><img src="${c.avatar_url}" alt="${c.login}"/></li>`; | ||
}).join('\n'); | ||
|
||
const htmlDoctype = `<!DOCTYPE html>`; | ||
const styling = `<link rel="stylesheet" href="contributors.css">`; | ||
const generatedHtml = `${htmlDoctype}${styling}<ul>${list}</ul>`; | ||
|
||
const outputPath = path.join(__dirname, 'contributors.html'); | ||
fs.writeFileSync(outputPath, generatedHtml); | ||
}; | ||
|
||
const init = async () => { | ||
const contributorsList: Contributor[] = []; | ||
let page = '1'; | ||
|
||
// iterate over the pages of GitHub API | ||
while (page !== undefined) { | ||
const result = await fetchContributors(page); | ||
contributorsList.push(...result.contributorsOfPage); | ||
page = result.nextPage; | ||
} | ||
|
||
if (contributorsList.length > 0) { | ||
console.log('> Material Icon Theme:', painter.green(`Successfully fetched all contributors from GitHub!`)); | ||
} else { | ||
console.log('> Material Icon Theme:', painter.red(`Error: Could not fetch contributors from GitHub!`)); | ||
throw Error(); | ||
} | ||
createContributorsList(contributorsList); | ||
}; | ||
|
||
init(); |