diff --git a/docs/programming.md b/docs/programming.md index 83a38ea225..9e1beec06e 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -89,6 +89,8 @@ GitHub 官方也提供了一些 RSS: + + | 排序选项 | sort | diff --git a/lib/router.js b/lib/router.js index 4f7aee8c71..5653a44ba5 100755 --- a/lib/router.js +++ b/lib/router.js @@ -340,6 +340,7 @@ router.get('/github/pull/:user/:repo', require('./routes/github/pulls')); router.get('/github/user/followers/:user', require('./routes/github/follower')); router.get('/github/stars/:user/:repo', require('./routes/github/star')); router.get('/github/search/:query/:sort?/:order?', require('./routes/github/search')); +router.get('/github/branches/:user/:repo', require('./routes/github/branches')); // f-droid router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease')); diff --git a/lib/routes/github/branches.js b/lib/routes/github/branches.js new file mode 100644 index 0000000000..831d001eba --- /dev/null +++ b/lib/routes/github/branches.js @@ -0,0 +1,25 @@ +const axios = require('../../utils/axios'); + +module.exports = async (ctx) => { + const user = ctx.params.user; + const repo = ctx.params.repo; + + const host = `https://github.com/${user}/${repo}`; + const url = `https://api.github.com/repos/${user}/${repo}/branches`; + + const response = await axios({ + method: 'get', + url, + }); + const data = response.data; + + ctx.state.data = { + title: `${user}/${repo} Branches`, + link: `${host}/branches/all`, + item: data.map((item) => ({ + title: item.name, + description: item.name, + link: `${host}/commits/${item.name}`, + })), + }; +};