Files
RSSHub/lib/v2/github/repos.js
Fatpandac 03481653fa fix(route): fix GitHub route parameter conflict at trending.js and refactor to V2 (#8923)
* Fix(route): fix route parameter conflict at trending.js and change to V2

* Fix(route): modify the judgment condition of language parameter

* Fix(docs): Update docs/programming.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Fix(docs): Update docs/en/programming.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix(docs/route): add author and sort routes

* Fix(route): Update docs/en/programming.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Fix(route): sort routes

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2022-02-03 00:37:01 +08:00

35 lines
1.0 KiB
JavaScript

const got = require('@/utils/got');
const config = require('@/config').value;
const queryString = require('query-string');
module.exports = async (ctx) => {
const user = ctx.params.user;
const headers = {};
if (config.github && config.github.access_token) {
headers.Authorization = `token ${config.github.access_token}`;
}
const response = await got({
method: 'get',
url: `https://api.github.com/users/${user}/repos`,
searchParams: queryString.stringify({
sort: 'created',
}),
headers,
});
const data = response.data;
ctx.state.data = {
allowEmpty: true,
title: `${user}'s GitHub repositories`,
link: `https://github.com/${user}`,
item:
data &&
data.map((item) => ({
title: item.name,
description: item.description || 'No description',
pubDate: new Date(item.created_at).toUTCString(),
link: item.html_url,
})),
};
};