fix: use auth requests to fetch GitHub data in website build

To prevent running into rate limit
This commit is contained in:
Pascal Jufer 2023-01-09 21:01:41 +01:00
parent ed64b38a02
commit 9950179545
7 changed files with 194 additions and 44 deletions

View file

@ -51,6 +51,8 @@ jobs:
- name: Build website
run: ./node_modules/.bin/next build
working-directory: iconoir.com
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Export website
run: ./node_modules/.bin/next export

View file

@ -1,5 +1,8 @@
export const REPO = 'iconoir-icons/iconoir';
export const GITHUB = `https://github.com/${REPO}`;
export const REPO = {
owner: 'iconoir-icons',
repo: 'iconoir',
};
export const GITHUB = `https://github.com/${REPO.owner}/${REPO.repo}`;
export const SUGGEST_ICON =
'https://github.com/iconoir-icons/iconoir/issues/new?assignees=lucaburgio&labels=icon+request&template=icon_request.md&title=%5BICON%5D';
export const SUPPORT_LINK = 'https://opencollective.com/iconoir/donate';

View file

@ -0,0 +1,5 @@
import { Octokit } from '@octokit/rest';
export const octokit = new Octokit({
...(process.env.GITHUB_TOKEN && { auth: process.env.GITHUB_TOKEN }),
});

View file

@ -33,6 +33,7 @@
},
"devDependencies": {
"@internationalized/number": "^3.1.1",
"@octokit/rest": "^19.0.5",
"@react-types/slider": "^3.1.1",
"@types/animejs": "^3.1.5",
"@types/lodash": "^4.14.182",
@ -41,7 +42,6 @@
"@types/react-dom": "^18.0.6",
"@types/react-window": "^1.8.5",
"@types/styled-components": "^5.1.25",
"axios": "^0.27.2",
"csvtojson": "^2.0.10",
"download-stats": "^0.3.4",
"eslint": "^8.0.0",

View file

@ -1,4 +1,4 @@
import axios from 'axios';
import { octokit } from '../../lib/octokit';
import React from 'react';
import {
ChangelogEntry,
@ -59,15 +59,15 @@ export default function Changelog({
}
export async function getStaticProps() {
const apiResult = await axios.get(
`https://api.github.com/repos/${REPO}/releases`
);
const entryData = apiResult.data || [];
const { data: releases } = await octokit.rest.repos.listReleases({
...REPO,
});
const entries: ChangelogEntryProps[] = [];
for (const entry of entryData) {
for (const release of releases) {
entries.push({
...entry,
body: await serialize(entry.body, {
name: release.name || release.tag_name,
created_at: release.created_at,
body: await serialize(release.body || '', {
mdxOptions: {
remarkPlugins: [require('remark-prism'), remarkGfm],
},

View file

@ -12,7 +12,7 @@ import { SEO } from '../components/SEO';
import { Stat, StatsContainer } from '../components/Stats';
import { Text18 } from '../components/Typography';
import { getAllIcons } from '../lib/getIcons';
import axios from 'axios';
import { octokit } from '../lib/octokit';
import numbro from 'numbro';
// @ts-ignore no types
import * as downloadStats from 'download-stats';
@ -154,8 +154,10 @@ export default Home;
export async function getStaticProps() {
const headerProps = getHeaderProps();
const apiResult = await axios.get(`https://api.github.com/repos/${REPO}`);
const stars = apiResult.data?.stargazers_count;
const { data: repo } = await octokit.rest.repos.get({
...REPO,
});
const stars = repo.stargazers_count;
if (!stars) throw new Error('Could not find GitHub stars');
const numDownloads = await new Promise<number>((resolve, reject) => {
downloadStats.get.lastMonth('iconoir-react', (err: any, results: any) => {

View file

@ -32,6 +32,7 @@ importers:
iconoir.com:
specifiers:
'@internationalized/number': ^3.1.1
'@octokit/rest': ^19.0.5
'@react-aria/focus': ^3.6.1
'@react-aria/i18n': ^3.4.1
'@react-aria/slider': ^3.1.1
@ -47,7 +48,6 @@ importers:
'@types/react-window': ^1.8.5
'@types/styled-components': ^5.1.25
animejs: ^3.2.1
axios: ^0.27.2
case: ^1.6.3
csvtojson: ^2.0.10
download-stats: ^0.3.4
@ -91,6 +91,7 @@ importers:
use-resize-observer: 9.0.2_biqbaboplfbrettd7655fr4n2y
devDependencies:
'@internationalized/number': 3.1.1
'@octokit/rest': 19.0.5
'@react-types/slider': 3.1.1_react@18.2.0
'@types/animejs': 3.1.5
'@types/lodash': 4.14.182
@ -99,7 +100,6 @@ importers:
'@types/react-dom': 18.0.6
'@types/react-window': 1.8.5
'@types/styled-components': 5.1.25
axios: 0.27.2
csvtojson: 2.0.10
download-stats: 0.3.4
eslint: 8.9.0
@ -695,6 +695,122 @@ packages:
fastq: 1.13.0
dev: true
/@octokit/auth-token/3.0.2:
resolution: {integrity: sha512-pq7CwIMV1kmzkFTimdwjAINCXKTajZErLB4wMLYapR2nuB/Jpr66+05wOTZMSCBXP6n4DdDWT2W19Bm17vU69Q==}
engines: {node: '>= 14'}
dependencies:
'@octokit/types': 8.0.0
dev: true
/@octokit/core/4.1.0:
resolution: {integrity: sha512-Czz/59VefU+kKDy+ZfDwtOIYIkFjExOKf+HA92aiTZJ6EfWpFzYQWw0l54ji8bVmyhc+mGaLUbSUmXazG7z5OQ==}
engines: {node: '>= 14'}
dependencies:
'@octokit/auth-token': 3.0.2
'@octokit/graphql': 5.0.4
'@octokit/request': 6.2.2
'@octokit/request-error': 3.0.2
'@octokit/types': 8.0.0
before-after-hook: 2.2.3
universal-user-agent: 6.0.0
transitivePeerDependencies:
- encoding
dev: true
/@octokit/endpoint/7.0.3:
resolution: {integrity: sha512-57gRlb28bwTsdNXq+O3JTQ7ERmBTuik9+LelgcLIVfYwf235VHbN9QNo4kXExtp/h8T423cR5iJThKtFYxC7Lw==}
engines: {node: '>= 14'}
dependencies:
'@octokit/types': 8.0.0
is-plain-object: 5.0.0
universal-user-agent: 6.0.0
dev: true
/@octokit/graphql/5.0.4:
resolution: {integrity: sha512-amO1M5QUQgYQo09aStR/XO7KAl13xpigcy/kI8/N1PnZYSS69fgte+xA4+c2DISKqUZfsh0wwjc2FaCt99L41A==}
engines: {node: '>= 14'}
dependencies:
'@octokit/request': 6.2.2
'@octokit/types': 8.0.0
universal-user-agent: 6.0.0
transitivePeerDependencies:
- encoding
dev: true
/@octokit/openapi-types/14.0.0:
resolution: {integrity: sha512-HNWisMYlR8VCnNurDU6os2ikx0s0VyEjDYHNS/h4cgb8DeOxQ0n72HyinUtdDVxJhFy3FWLGl0DJhfEWk3P5Iw==}
dev: true
/@octokit/plugin-paginate-rest/5.0.1_@octokit+core@4.1.0:
resolution: {integrity: sha512-7A+rEkS70pH36Z6JivSlR7Zqepz3KVucEFVDnSrgHXzG7WLAzYwcHZbKdfTXHwuTHbkT1vKvz7dHl1+HNf6Qyw==}
engines: {node: '>= 14'}
peerDependencies:
'@octokit/core': '>=4'
dependencies:
'@octokit/core': 4.1.0
'@octokit/types': 8.0.0
dev: true
/@octokit/plugin-request-log/1.0.4_@octokit+core@4.1.0:
resolution: {integrity: sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA==}
peerDependencies:
'@octokit/core': '>=3'
dependencies:
'@octokit/core': 4.1.0
dev: true
/@octokit/plugin-rest-endpoint-methods/6.7.0_@octokit+core@4.1.0:
resolution: {integrity: sha512-orxQ0fAHA7IpYhG2flD2AygztPlGYNAdlzYz8yrD8NDgelPfOYoRPROfEyIe035PlxvbYrgkfUZIhSBKju/Cvw==}
engines: {node: '>= 14'}
peerDependencies:
'@octokit/core': '>=3'
dependencies:
'@octokit/core': 4.1.0
'@octokit/types': 8.0.0
deprecation: 2.3.1
dev: true
/@octokit/request-error/3.0.2:
resolution: {integrity: sha512-WMNOFYrSaX8zXWoJg9u/pKgWPo94JXilMLb2VManNOby9EZxrQaBe/QSC4a1TzpAlpxofg2X/jMnCyZgL6y7eg==}
engines: {node: '>= 14'}
dependencies:
'@octokit/types': 8.0.0
deprecation: 2.3.1
once: 1.4.0
dev: true
/@octokit/request/6.2.2:
resolution: {integrity: sha512-6VDqgj0HMc2FUX2awIs+sM6OwLgwHvAi4KCK3mT2H2IKRt6oH9d0fej5LluF5mck1lRR/rFWN0YIDSYXYSylbw==}
engines: {node: '>= 14'}
dependencies:
'@octokit/endpoint': 7.0.3
'@octokit/request-error': 3.0.2
'@octokit/types': 8.0.0
is-plain-object: 5.0.0
node-fetch: 2.6.7
universal-user-agent: 6.0.0
transitivePeerDependencies:
- encoding
dev: true
/@octokit/rest/19.0.5:
resolution: {integrity: sha512-+4qdrUFq2lk7Va+Qff3ofREQWGBeoTKNqlJO+FGjFP35ZahP+nBenhZiGdu8USSgmq4Ky3IJ/i4u0xbLqHaeow==}
engines: {node: '>= 14'}
dependencies:
'@octokit/core': 4.1.0
'@octokit/plugin-paginate-rest': 5.0.1_@octokit+core@4.1.0
'@octokit/plugin-request-log': 1.0.4_@octokit+core@4.1.0
'@octokit/plugin-rest-endpoint-methods': 6.7.0_@octokit+core@4.1.0
transitivePeerDependencies:
- encoding
dev: true
/@octokit/types/8.0.0:
resolution: {integrity: sha512-65/TPpOJP1i3K4lBJMnWqPUJ6zuOtzhtagDvydAWbEXpbFYA0oMKKyLb95NFZZP0lSh/4b6K+DQlzvYQJQQePg==}
dependencies:
'@octokit/openapi-types': 14.0.0
dev: true
/@react-aria/focus/3.6.1_react@18.2.0:
resolution: {integrity: sha512-4IHAu+826jC3SjWwuaYhCr0qhWg4XwmJIUEhcL1wbw3fq2dsjIBwEJ5HoayhluiVCfjGbcQcJNf1L4Vj3VTp4w==}
peerDependencies:
@ -1402,21 +1518,13 @@ packages:
/asynckit/0.4.0:
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
dev: false
/axe-core/4.4.3:
resolution: {integrity: sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w==}
engines: {node: '>=4'}
dev: true
/axios/0.27.2:
resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==}
dependencies:
follow-redirects: 1.15.1
form-data: 4.0.0
transitivePeerDependencies:
- debug
dev: true
/axobject-query/2.2.0:
resolution: {integrity: sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA==}
dev: true
@ -1446,6 +1554,10 @@ packages:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: true
/before-after-hook/2.2.3:
resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==}
dev: true
/bignumber.js/8.1.1:
resolution: {integrity: sha512-QD46ppGintwPGuL1KqmwhR0O+N2cZUg8JG/VzwI2e28sM9TqHjQB10lI4QAaMHVbLzwVLLAwEglpKPViWX+5NQ==}
dev: false
@ -1632,6 +1744,7 @@ packages:
engines: {node: '>= 0.8'}
dependencies:
delayed-stream: 1.0.0
dev: false
/comma-separated-tokens/2.0.2:
resolution: {integrity: sha512-G5yTt3KQN4Yn7Yk4ed73hlZ1evrFKXeUW3086p3PRFNp7m2vIjI6Pg+Kgb+oyzhd9F2qdcoj67+y3SdxL5XWsg==}
@ -1903,6 +2016,11 @@ packages:
/delayed-stream/1.0.0:
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
engines: {node: '>=0.4.0'}
dev: false
/deprecation/2.3.1:
resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==}
dev: true
/dequal/2.0.3:
resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==}
@ -2570,16 +2688,6 @@ packages:
resolution: {integrity: sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==}
dev: true
/follow-redirects/1.15.1:
resolution: {integrity: sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==}
engines: {node: '>=4.0'}
peerDependencies:
debug: '*'
peerDependenciesMeta:
debug:
optional: true
dev: true
/form-data/3.0.1:
resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==}
engines: {node: '>= 6'}
@ -2589,15 +2697,6 @@ packages:
mime-types: 2.1.35
dev: false
/form-data/4.0.0:
resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
engines: {node: '>= 6'}
dependencies:
asynckit: 0.4.0
combined-stream: 1.0.8
mime-types: 2.1.35
dev: true
/fs.realpath/1.0.0:
resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==}
dev: true
@ -3038,6 +3137,11 @@ packages:
engines: {node: '>=12'}
dev: false
/is-plain-object/5.0.0:
resolution: {integrity: sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==}
engines: {node: '>=0.10.0'}
dev: true
/is-potential-custom-element-name/1.0.1:
resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==}
dev: false
@ -3876,12 +3980,14 @@ packages:
/mime-db/1.52.0:
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
engines: {node: '>= 0.6'}
dev: false
/mime-types/2.1.35:
resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
engines: {node: '>= 0.6'}
dependencies:
mime-db: 1.52.0
dev: false
/mimic-fn/2.1.0:
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
@ -3996,6 +4102,18 @@ packages:
- babel-plugin-macros
dev: false
/node-fetch/2.6.7:
resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
engines: {node: 4.x || >=6.0.0}
peerDependencies:
encoding: ^0.1.0
peerDependenciesMeta:
encoding:
optional: true
dependencies:
whatwg-url: 5.0.0
dev: true
/node-releases/2.0.2:
resolution: {integrity: sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg==}
dev: true
@ -4705,6 +4823,7 @@ packages:
/source-map/0.6.1:
resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==}
engines: {node: '>=0.10.0'}
requiresBuild: true
/space-separated-tokens/2.0.1:
resolution: {integrity: sha512-ekwEbFp5aqSPKaqeY1PGrlGQxPNaq+Cnx4+bE2D8sciBQrHpbwoBbawqTN2+6jPs9IdWxxiUcN0K2pkczD3zmw==}
@ -4946,6 +5065,10 @@ packages:
universalify: 0.1.2
dev: false
/tr46/0.0.3:
resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
dev: true
/tr46/2.1.0:
resolution: {integrity: sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==}
engines: {node: '>=8'}
@ -5113,6 +5236,10 @@ packages:
unist-util-visit-parents: 5.1.0
dev: false
/universal-user-agent/6.0.0:
resolution: {integrity: sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==}
dev: true
/universalify/0.1.2:
resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==}
engines: {node: '>= 4.0.0'}
@ -5219,6 +5346,10 @@ packages:
xml-name-validator: 3.0.0
dev: false
/webidl-conversions/3.0.1:
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
dev: true
/webidl-conversions/5.0.0:
resolution: {integrity: sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==}
engines: {node: '>=8'}
@ -5239,6 +5370,13 @@ packages:
resolution: {integrity: sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==}
dev: false
/whatwg-url/5.0.0:
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
dependencies:
tr46: 0.0.3
webidl-conversions: 3.0.1
dev: true
/whatwg-url/8.7.0:
resolution: {integrity: sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==}
engines: {node: '>=10'}