Skip to content

Commit

Permalink
Add GitHub branches (DIYgod#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-arnold authored and DIYgod committed Apr 21, 2019
1 parent 697c231 commit fe61f34
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ GitHub 官方也提供了一些 RSS:

<Route name="仓库 Stars" author="HenryQW" example="/github/stars/DIYgod/RSSHub" path="/github/stars/:user/:repo" :paramsDesc="['用户名', '仓库名']"/>

<Route name="仓库 Branches" author="max-arnold" example="/github/branches/DIYgod/RSSHub" path="/github/branches/:user/:repo" :paramsDesc="['用户名', '仓库名']"/>

<Route name="搜索结果" author="LogicJake" example="/github/search/RSSHub/bestmatch/desc" path="/github/search/:query/:sort?/:order?" :paramsDesc="['搜索关键词', '排序选项(默认为bestmatch)','排序顺序,desc和asc(默认desc降序)']"/>

| 排序选项 | sort |
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
25 changes: 25 additions & 0 deletions lib/routes/github/branches.js
Original file line number Diff line number Diff line change
@@ -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}`,
})),
};
};

0 comments on commit fe61f34

Please sign in to comment.