Created
October 29, 2021 05:33
-
-
Save kzkn/10b466cb0ef9708979cc61058b40c22b to your computer and use it in GitHub Desktop.
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
const { searchChangeLogUrl } = require('rubygems-changelog-url') | |
const GITHUB_REPOSITORY_URL_REGEXP = new RegExp('^https://github.com/([^/]+)/([^/]+)/?$') | |
const GITHUB_TREE_URL_REGEXP = new RegExp('^https://github.com/([^/]+)/([^/]+)/tree/[^/]+/(.+)$') | |
function findGithubUrl(gem) { | |
const match = (url) => (url && (!!url.match(GITHUB_REPOSITORY_URL_REGEXP) || !!url.match(GITHUB_TREE_URL_REGEXP))) | |
return [gem['project_uri'], gem['homepage_uri'], gem['source_code_uri']].find(match) | |
} | |
let chunk = '' | |
process.stdin.on('data', data => { | |
chunk = chunk + data | |
}).on('end', async () => { | |
const gems = JSON.parse(chunk) | |
for (const gem of gems.filter(gem => !!gem)) { | |
try { | |
const url = await searchChangeLogUrl({ | |
name: gem['name'], | |
projectUri: gem['project_uri'], | |
homepageUri: gem['homepage_uri'], | |
sourceCodeUri: gem['source_code_uri'], | |
changelogUri: gem['changelog_uri'] | |
}, { | |
token: process.env.GITHUB_APIKEY | |
}) | |
console.log(`${gem['name']},${findGithubUrl(gem)},${url}`) | |
} catch (e) { | |
console.error(`ERROR: gem=${gem['name']}, error=${e}`) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment