mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-16 07:44:44 +08:00
feat(route): add GitHub repo, user and org event routes (#20330)
* feat(route): add GitHub repository event route Co-authored-by: LiangddBUG <113956019+LiangddCoder@users.noreply.github.com> Signed-off-by: mslxl <i@mslxl.com> * feat(route): add GitHub user and org event routes Signed-off-by: mslxl <i@mslxl.com> --------- Signed-off-by: mslxl <i@mslxl.com> Co-authored-by: LiangddBUG <113956019+LiangddCoder@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const eventTypeMapping: Record<string, string> = {
|
||||
create: 'CreateEvent',
|
||||
delete: 'DeleteEvent',
|
||||
issuecomm: 'IssueCommentEvent',
|
||||
fork: 'ForkEvent',
|
||||
member: 'MemberEvent',
|
||||
public: 'PublicEvent',
|
||||
push: 'PushEvent',
|
||||
pr: 'PullRequestEvent',
|
||||
prcomm: 'PullRequestReviewCommentEvent',
|
||||
release: 'ReleaseEvent',
|
||||
star: 'WatchEvent',
|
||||
issue: 'IssuesEvent',
|
||||
prrev: 'PullRequestReviewEvent',
|
||||
discussion: 'DiscussionEvent',
|
||||
wiki: 'GollumEvent',
|
||||
cmcomm: 'CommitCommentEvent',
|
||||
};
|
||||
|
||||
function formatEventItem(event: any) {
|
||||
const { id, type, actor, repo, payload, created_at } = event;
|
||||
|
||||
let title = '';
|
||||
let description = '';
|
||||
let link = '';
|
||||
|
||||
switch (type) {
|
||||
case 'PushEvent': {
|
||||
title = `${actor.login} pushed to ${repo.name}`;
|
||||
const branch = payload.ref ? payload.ref.replace('refs/heads/', '') : 'unknown';
|
||||
const commitCount = payload.size ? `${payload.size} commit(s) ` : '';
|
||||
description = `Pushed ${commitCount}to ${branch} in ${repo.name}`;
|
||||
|
||||
if (payload.commits) {
|
||||
link = payload.commits.at(-1).url.replace('api.github.com/repos/', 'github.com/').replace('/commits/', '/commit/');
|
||||
description += `<br><strong>Latest commit:</strong> ${payload.commits.at(-1).message}`;
|
||||
} else {
|
||||
link = `https://github.com/${repo.name}/commit/${payload.head}`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'PullRequestEvent':
|
||||
title = `${actor.login} ${payload.action} a pull request in ${repo.name}`;
|
||||
description = `PR: ${payload.pull_request?.url || 'Unknown'}`;
|
||||
link = payload.pull_request?.url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'PullRequestReviewCommentEvent':
|
||||
title = `${actor.login} commented on a pull request review in ${repo.name}`;
|
||||
description = `Comment: ${payload.comment?.body || 'No comment'}`;
|
||||
link = payload.comment?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'PullRequestReviewEvent':
|
||||
title = `${actor.login} reviewed a pull request in ${repo.name}`;
|
||||
description = `${actor.login} ${payload.review?.state ?? "operated"} the PR` + (payload.review?.body ? `: ${payload.review.body}` : '');
|
||||
link = payload.review?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'IssueCommentEvent':
|
||||
title = `${actor.login} commented on an issue in ${repo.name}`;
|
||||
description = `Comment: ${payload.comment?.body || 'No comment'}`;
|
||||
link = payload.comment?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'IssuesEvent':
|
||||
title = `${actor.login} ${payload.action} an issue in ${repo.name}`;
|
||||
description = `Issue: ${payload.issue?.title || 'Unknown'}`;
|
||||
link = payload.issue?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'CommitCommentEvent':
|
||||
title = `${actor.login} commented on a commit in ${repo.name}`;
|
||||
description = `Comment: ${payload.comment?.body || 'No comment'}`;
|
||||
link = payload.comment?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'WatchEvent':
|
||||
title = `${actor.login} starred ${repo.name}`;
|
||||
description = `Starred repository ${repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'ForkEvent':
|
||||
title = `${actor.login} forked ${repo.name}`;
|
||||
description = `Forked repository ${repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'CreateEvent':
|
||||
title = `${actor.login} created ${payload.ref_type} in ${repo.name}`;
|
||||
description = `Created ${payload.ref_type}: ${payload.ref || repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'DeleteEvent':
|
||||
title = `${actor.login} deleted ${payload.ref_type} in ${repo.name}`;
|
||||
description = `Deleted ${payload.ref_type}: ${payload.ref}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'ReleaseEvent':
|
||||
title = `${actor.login} released ${payload.release?.name || payload.release?.tag_name} in ${repo.name}`;
|
||||
description = payload.release?.body || `Released ${payload.release?.tag_name}`;
|
||||
link = payload.release?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'PublicEvent':
|
||||
title = `${actor.login} made ${repo.name} public`;
|
||||
description = `Repository ${repo.name} was made public`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'MemberEvent':
|
||||
title = `${actor.login} ${payload.action} as a member of ${repo.name}`;
|
||||
description = `Member ${payload.action} in repository ${repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'GollumEvent':
|
||||
title = `${actor.login} update the wiki in ${repo.name}`;
|
||||
description = '<ul>';
|
||||
for (const page of payload.pages ?? []) {
|
||||
description += `<li>Page <a href=${page.html_url}>${page.page_name}</a> ${page.action} ${page.summary ? `: ${page.summary}` : ''}</li>`;
|
||||
}
|
||||
description += `</ul>`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'DiscussionEvent':
|
||||
title = `${actor.login} ${payload.action} a discussion ${repo.discussion?.title ?? ''} on ${repo.name}`;
|
||||
description = payload.discussion?.body ?? 'Unknown';
|
||||
link = payload.discussion?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
default:
|
||||
title = `${actor.login} performed ${type} in ${repo?.name || 'unknown repository'}`;
|
||||
description = `Activity type: ${type} ${JSON.stringify(event)}`;
|
||||
link = repo ? `https://github.com/${repo.name}` : `https://github.com/${actor.login}`;
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
pubDate: parseDate(created_at),
|
||||
author: actor.login,
|
||||
category: [type],
|
||||
guid: id,
|
||||
};
|
||||
}
|
||||
|
||||
export function filterEvents(types: string, data: any) {
|
||||
// Parse requested event types and map short names to full event types
|
||||
let filteredEventTypes: string[] = [];
|
||||
if (types !== 'all') {
|
||||
filteredEventTypes = types.split(',').map((type) => {
|
||||
const trimmedType = type.trim();
|
||||
return eventTypeMapping[trimmedType] || trimmedType;
|
||||
});
|
||||
}
|
||||
return data.filter((event) => filteredEventTypes.length === 0 || filteredEventTypes.includes(event.type)).map((event) => formatEventItem(event));
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import { Route, ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { config } from '@/config';
|
||||
import { filterEvents } from './eventapi';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/org_event/:org/:types?',
|
||||
categories: ['programming'],
|
||||
example: '/github/org_event/RSSNext',
|
||||
view: ViewType.Notifications,
|
||||
parameters: {
|
||||
org: 'Organization name',
|
||||
types: {
|
||||
description: 'Event types to include, comma separated',
|
||||
default: 'all',
|
||||
options: [
|
||||
{
|
||||
label: 'All events',
|
||||
value: 'all',
|
||||
},
|
||||
{
|
||||
label: 'Create events',
|
||||
value: 'create',
|
||||
},
|
||||
{
|
||||
label: 'Delete events',
|
||||
value: 'delete',
|
||||
},
|
||||
{
|
||||
label: 'Fork events',
|
||||
value: 'fork',
|
||||
},
|
||||
{
|
||||
label: 'Issue create events',
|
||||
value: 'issue',
|
||||
},
|
||||
{
|
||||
label: 'Issue comment events',
|
||||
value: 'issuecomm',
|
||||
},
|
||||
{
|
||||
label: 'Member events',
|
||||
value: 'member',
|
||||
},
|
||||
{
|
||||
label: 'Pull request events',
|
||||
value: 'pr',
|
||||
},
|
||||
{
|
||||
label: 'Pull request review comment events',
|
||||
value: 'prcomm',
|
||||
},
|
||||
{
|
||||
label: 'Pull request review events',
|
||||
value: 'prrev',
|
||||
},
|
||||
{
|
||||
label: 'Public events',
|
||||
value: 'public',
|
||||
},
|
||||
{
|
||||
label: 'Push events',
|
||||
value: 'push',
|
||||
},
|
||||
{
|
||||
label: 'Release events',
|
||||
value: 'release',
|
||||
},
|
||||
{
|
||||
label: 'Watch events (stars)',
|
||||
value: 'star',
|
||||
},
|
||||
{
|
||||
label: 'Wiki item create or update events',
|
||||
value: 'wiki',
|
||||
},
|
||||
{
|
||||
label: 'Commit comment events',
|
||||
value: 'cmcomm',
|
||||
},
|
||||
{
|
||||
label: 'Discussion events',
|
||||
value: 'discussion',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
features: {
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'GITHUB_ACCESS_TOKEN',
|
||||
optional: true,
|
||||
description: 'GitHub access token to avoid access limit',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['github.com/orgs/:org'],
|
||||
target: '/org_event/:org',
|
||||
},
|
||||
],
|
||||
name: 'Organization Event',
|
||||
maintainers: ['mslxl'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const org = ctx.req.param('org');
|
||||
const types = ctx.req.param('types') || 'all';
|
||||
|
||||
const isAuthenticated = config.github && config.github.access_token;
|
||||
|
||||
const headers: Record<string, string> = {};
|
||||
if (isAuthenticated) {
|
||||
headers.Authorization = `token ${config.github.access_token}`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.github.com/orgs/${org}/events`,
|
||||
headers,
|
||||
searchParams: {
|
||||
per_page: 100,
|
||||
},
|
||||
});
|
||||
|
||||
const items = filterEvents(types, response.data);
|
||||
const typeFilter = types === 'all' ? 'All Events' : `Events: ${types}`;
|
||||
|
||||
return {
|
||||
title: `${org} GitHub organization Feed - ${typeFilter}`,
|
||||
link: `https://github.com/${org}`,
|
||||
description: `GitHub events received by ${org}`,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
@@ -1,26 +1,13 @@
|
||||
import { Route } from '@/types';
|
||||
import { Route, ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
|
||||
const typeMapping: Record<string, string> = {
|
||||
push: 'PushEvent',
|
||||
pr: 'PullRequestEvent',
|
||||
prcomm: 'PullRequestReviewCommentEvent',
|
||||
issuecomm: 'IssueCommentEvent',
|
||||
star: 'WatchEvent',
|
||||
fork: 'ForkEvent',
|
||||
create: 'CreateEvent',
|
||||
delete: 'DeleteEvent',
|
||||
release: 'ReleaseEvent',
|
||||
public: 'PublicEvent',
|
||||
member: 'MemberEvent',
|
||||
};
|
||||
import { filterEvents } from './eventapi';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/feed/:user/:types?',
|
||||
categories: ['programming'],
|
||||
example: '/github/feed/yihong0618/star,release,pr',
|
||||
view: ViewType.Notifications,
|
||||
parameters: {
|
||||
user: 'GitHub username',
|
||||
types: {
|
||||
@@ -103,95 +90,6 @@ export const route: Route = {
|
||||
handler,
|
||||
};
|
||||
|
||||
function formatEventItem(event: any) {
|
||||
const { id, type, actor, repo, payload, created_at } = event;
|
||||
|
||||
let title = '';
|
||||
let description = '';
|
||||
let link = '';
|
||||
|
||||
switch (type) {
|
||||
case 'PushEvent': {
|
||||
title = `${actor.login} pushed to ${repo.name}`;
|
||||
const branch = payload.ref ? payload.ref.replace('refs/heads/', '') : 'unknown';
|
||||
const commitCount = payload.size ? `${payload.size} commit(s) ` : '';
|
||||
description = `Pushed ${commitCount}to ${branch} in ${repo.name}`;
|
||||
|
||||
if (payload.commits) {
|
||||
link = payload.commits.at(-1).url.replace('api.github.com/repos/', 'github.com/').replace('/commits/', '/commit/');
|
||||
description += `<br><strong>Latest commit:</strong> ${payload.commits.at(-1).message}`;
|
||||
} else {
|
||||
link = `https://github.com/${repo.name}/commit/${payload.head}`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'PullRequestEvent':
|
||||
title = `${actor.login} ${payload.action} a pull request in ${repo.name}`;
|
||||
description = `PR: ${payload.pull_request?.title || 'Unknown'}`;
|
||||
link = payload.pull_request?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'PullRequestReviewCommentEvent':
|
||||
title = `${actor.login} commented on a pull request review in ${repo.name}`;
|
||||
description = `Comment: ${payload.comment?.body || 'No comment'}`;
|
||||
link = payload.comment?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'IssueCommentEvent':
|
||||
title = `${actor.login} commented on an issue in ${repo.name}`;
|
||||
description = `Comment: ${payload.comment?.body || 'No comment'}`;
|
||||
link = payload.comment?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'WatchEvent':
|
||||
title = `${actor.login} starred ${repo.name}`;
|
||||
description = `Starred repository ${repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'ForkEvent':
|
||||
title = `${actor.login} forked ${repo.name}`;
|
||||
description = `Forked repository ${repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'CreateEvent':
|
||||
title = `${actor.login} created ${payload.ref_type} in ${repo.name}`;
|
||||
description = `Created ${payload.ref_type}: ${payload.ref || repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'DeleteEvent':
|
||||
title = `${actor.login} deleted ${payload.ref_type} in ${repo.name}`;
|
||||
description = `Deleted ${payload.ref_type}: ${payload.ref}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'ReleaseEvent':
|
||||
title = `${actor.login} released ${payload.release?.name || payload.release?.tag_name} in ${repo.name}`;
|
||||
description = payload.release?.body || `Released ${payload.release?.tag_name}`;
|
||||
link = payload.release?.html_url || `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'PublicEvent':
|
||||
title = `${actor.login} made ${repo.name} public`;
|
||||
description = `Repository ${repo.name} was made public`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
case 'MemberEvent':
|
||||
title = `${actor.login} ${payload.action} as a member of ${repo.name}`;
|
||||
description = `Member ${payload.action} in repository ${repo.name}`;
|
||||
link = `https://github.com/${repo.name}`;
|
||||
break;
|
||||
default:
|
||||
title = `${actor.login} performed ${type} in ${repo?.name || 'unknown repository'}`;
|
||||
description = `Activity type: ${type}`;
|
||||
link = repo ? `https://github.com/${repo.name}` : `https://github.com/${actor.login}`;
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
pubDate: parseDate(created_at),
|
||||
author: actor.login,
|
||||
category: [type],
|
||||
guid: id,
|
||||
};
|
||||
}
|
||||
|
||||
async function handler(ctx) {
|
||||
const user = ctx.req.param('user');
|
||||
const types = ctx.req.param('types') || 'all';
|
||||
@@ -212,16 +110,7 @@ async function handler(ctx) {
|
||||
},
|
||||
});
|
||||
|
||||
// Parse requested event types and map short names to full event types
|
||||
let filteredEventTypes: string[] = [];
|
||||
if (types !== 'all') {
|
||||
filteredEventTypes = types.split(',').map((type) => {
|
||||
const trimmedType = type.trim();
|
||||
return typeMapping[trimmedType] || trimmedType;
|
||||
});
|
||||
}
|
||||
|
||||
const items = response.data.filter((event) => filteredEventTypes.length === 0 || filteredEventTypes.includes(event.type)).map((event) => formatEventItem(event));
|
||||
const items = filterEvents(types, response.data);
|
||||
|
||||
const typeFilter = types === 'all' ? 'All Events' : `Events: ${types}`;
|
||||
const feedType = isAuthenticated ? 'Private Feed' : 'Public Feed';
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
import { Route, ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { config } from '@/config';
|
||||
import { filterEvents } from './eventapi';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/repo_event/:owner/:repo/:types?',
|
||||
categories: ['programming'],
|
||||
example: '/github/repo_event/DIYgod/RSSHub',
|
||||
view: ViewType.Notifications,
|
||||
parameters: {
|
||||
owner: 'Username or organization name',
|
||||
repo: 'Repository name',
|
||||
types: {
|
||||
description: 'Event types to include, comma separated',
|
||||
default: 'all',
|
||||
options: [
|
||||
{
|
||||
label: 'All events',
|
||||
value: 'all',
|
||||
},
|
||||
{
|
||||
label: 'Create events',
|
||||
value: 'create',
|
||||
},
|
||||
{
|
||||
label: 'Delete events',
|
||||
value: 'delete',
|
||||
},
|
||||
{
|
||||
label: 'Fork events',
|
||||
value: 'fork',
|
||||
},
|
||||
{
|
||||
label: 'Issue create events',
|
||||
value: 'issue',
|
||||
},
|
||||
{
|
||||
label: 'Issue comment events',
|
||||
value: 'issuecomm',
|
||||
},
|
||||
{
|
||||
label: 'Member events',
|
||||
value: 'member',
|
||||
},
|
||||
{
|
||||
label: 'Pull request events',
|
||||
value: 'pr',
|
||||
},
|
||||
{
|
||||
label: 'Pull request review comment events',
|
||||
value: 'prcomm',
|
||||
},
|
||||
{
|
||||
label: 'Pull request review events',
|
||||
value: 'prrev',
|
||||
},
|
||||
{
|
||||
label: 'Public events',
|
||||
value: 'public',
|
||||
},
|
||||
{
|
||||
label: 'Push events',
|
||||
value: 'push',
|
||||
},
|
||||
{
|
||||
label: 'Release events',
|
||||
value: 'release',
|
||||
},
|
||||
{
|
||||
label: 'Watch events (stars)',
|
||||
value: 'star',
|
||||
},
|
||||
{
|
||||
label: 'Wiki item create or update events',
|
||||
value: 'wiki',
|
||||
},
|
||||
{
|
||||
label: 'Commit comment events',
|
||||
value: 'cmcomm',
|
||||
},
|
||||
{
|
||||
label: 'Discussion events',
|
||||
value: 'discussion',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
features: {
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'GITHUB_ACCESS_TOKEN',
|
||||
optional: true,
|
||||
description: 'GitHub access token to access private repository events',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['github.com/:owner/:repo'],
|
||||
target: '/repo_event/:owner/:repo',
|
||||
},
|
||||
],
|
||||
name: 'Repository Event',
|
||||
maintainers: ['mslxl'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const owner = ctx.req.param('owner');
|
||||
const repo = ctx.req.param('repo');
|
||||
const types = ctx.req.param('types') || 'all';
|
||||
|
||||
const isAuthenticated = config.github && config.github.access_token;
|
||||
|
||||
const headers: Record<string, string> = {};
|
||||
if (isAuthenticated) {
|
||||
headers.Authorization = `token ${config.github.access_token}`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.github.com/repos/${owner}/${repo}/events`,
|
||||
headers,
|
||||
searchParams: {
|
||||
per_page: 100,
|
||||
},
|
||||
});
|
||||
|
||||
const items = filterEvents(types, response.data);
|
||||
const typeFilter = types === 'all' ? 'All Events' : `Events: ${types}`;
|
||||
|
||||
return {
|
||||
title: `${owner}/${repo} GitHub Repo Feed - ${typeFilter}`,
|
||||
link: `https://github.com/${owner}/${repo}`,
|
||||
description: `GitHub events received by ${owner}/${repo}${types === 'all' ? '' : ` (filtered: ${types})`}${isAuthenticated ? ' - includes private events' : ' - public events only'}`,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import { Route, ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { config } from '@/config';
|
||||
import { filterEvents } from './eventapi';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user_event/:username/:types?',
|
||||
categories: ['programming'],
|
||||
example: '/github/user_event/mslxl',
|
||||
view: ViewType.Notifications,
|
||||
parameters: {
|
||||
username: 'Username',
|
||||
types: {
|
||||
description: 'Event types to include, comma separated',
|
||||
default: 'all',
|
||||
options: [
|
||||
{
|
||||
label: 'All events',
|
||||
value: 'all',
|
||||
},
|
||||
{
|
||||
label: 'Create events',
|
||||
value: 'create',
|
||||
},
|
||||
{
|
||||
label: 'Delete events',
|
||||
value: 'delete',
|
||||
},
|
||||
{
|
||||
label: 'Fork events',
|
||||
value: 'fork',
|
||||
},
|
||||
{
|
||||
label: 'Issue create events',
|
||||
value: 'issue',
|
||||
},
|
||||
{
|
||||
label: 'Issue comment events',
|
||||
value: 'issuecomm',
|
||||
},
|
||||
{
|
||||
label: 'Member events',
|
||||
value: 'member',
|
||||
},
|
||||
{
|
||||
label: 'Pull request events',
|
||||
value: 'pr',
|
||||
},
|
||||
{
|
||||
label: 'Pull request review comment events',
|
||||
value: 'prcomm',
|
||||
},
|
||||
{
|
||||
label: 'Pull request review events',
|
||||
value: 'prrev',
|
||||
},
|
||||
{
|
||||
label: 'Public events',
|
||||
value: 'public',
|
||||
},
|
||||
{
|
||||
label: 'Push events',
|
||||
value: 'push',
|
||||
},
|
||||
{
|
||||
label: 'Release events',
|
||||
value: 'release',
|
||||
},
|
||||
{
|
||||
label: 'Watch events (stars)',
|
||||
value: 'star',
|
||||
},
|
||||
{
|
||||
label: 'Wiki item create or update events',
|
||||
value: 'wiki',
|
||||
},
|
||||
{
|
||||
label: 'Commit comment events',
|
||||
value: 'cmcomm',
|
||||
},
|
||||
{
|
||||
label: 'Discussion events',
|
||||
value: 'discussion',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
features: {
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'GITHUB_ACCESS_TOKEN',
|
||||
optional: true,
|
||||
description: 'GitHub access token to access private repository events',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['github.com/:username'],
|
||||
target: '/user_event/:username',
|
||||
},
|
||||
],
|
||||
name: 'User Event',
|
||||
maintainers: ['mslxl'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const username = ctx.req.param('username');
|
||||
const types = ctx.req.param('types') || 'all';
|
||||
|
||||
const isAuthenticated = config.github && config.github.access_token;
|
||||
|
||||
const headers: Record<string, string> = {};
|
||||
if (isAuthenticated) {
|
||||
headers.Authorization = `token ${config.github.access_token}`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.github.com/users/${username}/events` + (isAuthenticated ? '' : '/public'),
|
||||
headers,
|
||||
searchParams: {
|
||||
per_page: 100,
|
||||
},
|
||||
});
|
||||
|
||||
const items = filterEvents(types, response.data);
|
||||
const typeFilter = types === 'all' ? 'All Events' : `Events: ${types}`;
|
||||
|
||||
return {
|
||||
title: `${username} GitHub User Feed - ${typeFilter}`,
|
||||
link: `https://github.com/${username}`,
|
||||
description: `GitHub events received by ${username}${types === 'all' ? '' : ` (filtered: ${types})`}${isAuthenticated ? ' - includes private events' : ' - public events only'}`,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user