forked from vn7n24fzkq/github-profile-summary-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GitHub api retry (vn7n24fzkq#42)
* Add github token updater & error card * Fix missing required module * Fix constant variable * Fix github token updater * Update github updater * Update github token index * Add github token updater log * Update token name * Update web host * Add github button * Update web UI Co-authored-by: profile-summary-cards[bot] <[email protected]>
- Loading branch information
1 parent
3a1f607
commit fec7d89
Showing
9 changed files
with
171 additions
and
22 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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
const { | ||
getCommitsLanguageSVGWithThemeName, | ||
} = require('../../src/cards/most-commit-lauguage-card'); | ||
const { changToNextGitHubToken } = require('../utils/github-token-updater'); | ||
const { getErrorMsgCard } = require('../utils/error-card'); | ||
|
||
module.exports = async (req, res) => { | ||
const { username, theme } = req.query; | ||
const cardSVG = await getCommitsLanguageSVGWithThemeName(username, theme); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
try { | ||
let tokenIndex = 0; | ||
while (true) { | ||
try { | ||
const cardSVG = await getCommitsLanguageSVGWithThemeName( | ||
username, | ||
theme | ||
); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
return; | ||
} catch (err) { | ||
console.log(err.message); | ||
// We update github token and try again, until getNextGitHubToken throw an Error | ||
changToNextGitHubToken(tokenIndex); | ||
tokenIndex += 1; | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
res.send(getErrorMsgCard(err.message, theme)); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
const { | ||
getProductiveTimeSVGWithThemeName, | ||
} = require('../../src/cards/productive-time-card'); | ||
const { changToNextGitHubToken } = require('../utils/github-token-updater'); | ||
const { getErrorMsgCard } = require('../utils/error-card'); | ||
|
||
module.exports = async (req, res) => { | ||
const { username, theme } = req.query; | ||
const cardSVG = await getProductiveTimeSVGWithThemeName(username, theme); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
try { | ||
let tokenIndex = 0; | ||
while (true) { | ||
try { | ||
const cardSVG = await getProductiveTimeSVGWithThemeName( | ||
username, | ||
theme | ||
); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
return; | ||
} catch (err) { | ||
console.log(err.message); | ||
// We update github token and try again, until getNextGitHubToken throw an Error | ||
changToNextGitHubToken(tokenIndex); | ||
tokenIndex += 1; | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
res.send(getErrorMsgCard(err.message, theme)); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
const { | ||
getProfileDetailsSVGWithThemeName, | ||
} = require('../../src/cards/profile-details-card'); | ||
const { changToNextGitHubToken } = require('../utils/github-token-updater'); | ||
const { getErrorMsgCard } = require('../utils/error-card'); | ||
|
||
module.exports = async (req, res) => { | ||
const { username, theme } = req.query; | ||
const cardSVG = await getProfileDetailsSVGWithThemeName(username, theme); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
try { | ||
let tokenIndex = 0; | ||
while (true) { | ||
try { | ||
const cardSVG = await getProfileDetailsSVGWithThemeName( | ||
username, | ||
theme | ||
); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
return; | ||
} catch (err) { | ||
console.log(err.message); | ||
// We update github token and try again, until getNextGitHubToken throw an Error | ||
changToNextGitHubToken(tokenIndex); | ||
tokenIndex += 1; | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
res.send(getErrorMsgCard(err.message, theme)); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
const { | ||
getReposPerLanguageSVGWithThemeName, | ||
} = require('../../src/cards/repos-per-language-card'); | ||
const { changToNextGitHubToken } = require('../utils/github-token-updater'); | ||
const { getErrorMsgCard } = require('../utils/error-card'); | ||
|
||
module.exports = async (req, res) => { | ||
const { username, theme } = req.query; | ||
const cardSVG = await getReposPerLanguageSVGWithThemeName(username, theme); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
try { | ||
let tokenIndex = 0; | ||
while (true) { | ||
try { | ||
const cardSVG = await getReposPerLanguageSVGWithThemeName( | ||
username, | ||
theme | ||
); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
return; | ||
} catch (err) { | ||
console.log(err.message); | ||
// We update github token and try again, until getNextGitHubToken throw an Error | ||
changToNextGitHubToken(tokenIndex); | ||
tokenIndex += 1; | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
res.send(getErrorMsgCard(err.message, theme)); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,8 +1,26 @@ | ||
const { getStatsSVGWithThemeName } = require('../../src/cards/stats-card'); | ||
const { changToNextGitHubToken } = require('../utils/github-token-updater'); | ||
const { getErrorMsgCard } = require('../utils/error-card'); | ||
|
||
module.exports = async (req, res) => { | ||
const { username, theme } = req.query; | ||
const cardSVG = await getStatsSVGWithThemeName(username, theme); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
try { | ||
let tokenIndex = 0; | ||
while (true) { | ||
try { | ||
const cardSVG = await getStatsSVGWithThemeName(username, theme); | ||
res.setHeader('Content-Type', 'image/svg+xml'); | ||
res.send(cardSVG); | ||
return; | ||
} catch (err) { | ||
console.log(err.message); | ||
// We update github token and try again, until getNextGitHubToken throw an Error | ||
changToNextGitHubToken(tokenIndex); | ||
tokenIndex += 1; | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
res.send(getErrorMsgCard(err.message, theme)); | ||
} | ||
}; |
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
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,23 @@ | ||
const Card = require('../../src/templates/card'); | ||
const ThemeMap = require('../../src/const/theme'); | ||
|
||
const getErrorMsgCard = function (msg, themeName) { | ||
const theme = ThemeMap.get(themeName); | ||
theme.title_color = 'red'; | ||
|
||
const card = new Card('ERROR!!!', 340, 200, theme); | ||
const svg = card.getSVG(); | ||
const panel = svg.append('g').attr('transform', `translate(30,20)`); | ||
panel | ||
.append('text') | ||
.attr('y', `${card.yPadding}`) | ||
.style('font-size', `14px`) | ||
.style('fill', 'red') | ||
.text(msg); | ||
|
||
return card.toString(); | ||
}; | ||
|
||
module.exports = { | ||
getErrorMsgCard, | ||
}; |
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,12 @@ | ||
const changToNextGitHubToken = function (currentIndex) { | ||
const tokenName = `GITHUB_TOKEN_${currentIndex + 1}`; | ||
console.log(`Change to ${tokenName}`); | ||
process.env.GITHUB_TOKEN = process.env[tokenName]; | ||
if (!process.env.GITHUB_TOKEN) { | ||
throw new Error('No more GITHUB_TOKEN can be used'); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
changToNextGitHubToken, | ||
}; |
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