Files
RSSHub/lib/routes/github/star.ts
T
dependabot[bot] ae3e646ea9 chore(deps-dev): bump eslint-plugin-unicorn from 59.0.1 to 60.0.0 (#19662)
* chore(deps-dev): bump eslint-plugin-unicorn from 59.0.1 to 60.0.0

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 60.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* refactor: replace reverse() with toReversed() for improved readability

* chore: update packageManager version to pnpm@10.13.1

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-22 20:45:42 +08:00

78 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Route, ViewType } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
import ConfigNotFoundError from '@/errors/types/config-not-found';
export const route: Route = {
path: '/stars/:user/:repo',
categories: ['programming'],
example: '/github/stars/DIYgod/RSSHub',
view: ViewType.Notifications,
parameters: { user: 'GitHub username', repo: 'GitHub repo name' },
features: {
requireConfig: [
{
name: 'GITHUB_ACCESS_TOKEN',
description: 'GitHub Access Token',
},
],
},
radar: [
{
source: ['github.com/:user/:repo/stargazers', 'github.com/:user/:repo'],
},
],
name: 'Repo Stars',
maintainers: ['HenryQW'],
handler,
};
async function handler(ctx) {
if (!config.github || !config.github.access_token) {
throw new ConfigNotFoundError('GitHub star RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}
const user = ctx.req.param('user');
const repo = ctx.req.param('repo');
const host = `https://github.com/${user}/${repo}/stargazers`;
const url = 'https://api.github.com/graphql';
const response = await got({
method: 'post',
url,
headers: {
Authorization: `bearer ${config.github.access_token}`,
},
json: {
query: `
{
repository(owner: "${user}", name: "${repo}") {
stargazers(last: 10) {
edges {
node {
login
avatarUrl
}
}
}
}
}
`,
},
});
const data = response.data.data.repository.stargazers.edges.toReversed();
return {
allowEmpty: true,
title: `${user}/${repo}’s stargazers`,
link: host,
item: data.map((follower) => ({
title: `${follower.node.login} starred ${user}/${repo}`,
author: follower.node.login,
description: `<a href="https://github.com/${follower.node.login}">${follower.node.login}</a> <br> <img sytle="width:50px;" src='${follower.node.avatarUrl}'>`,
link: `https://github.com/${follower.node.login}`,
})),
};
}