Files
dependabot[bot]andTonyRL 6bce9493b5 chore(deps-dev): bump eslint-plugin-unicorn from 71.1.0 to 72.0.0 (#22723)
* chore(deps-dev): bump eslint-plugin-unicorn from 71.1.0 to 72.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 71.1.0 to 72.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v71.1.0...v72.0.0)

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

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

* style: fix prefer-dom-node-html-methods

* style: fix prefer-split-limit

* style: fix no-unnecessary-string-trim

* style: fix no-multiple-promise-resolver-calls

* style: add v72 preset

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
2026-07-15 23:11:15 +08:00

135 lines
5.0 KiB
TypeScript
Raw Permalink 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 { load } from 'cheerio';
import { raw } from 'hono/html';
import { renderToString } from 'hono/jsx/dom/server';
import type { Route } from '@/types';
import got from '@/utils/got';
import md5 from '@/utils/md5';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/pulse/:user/:repo/:period?',
categories: ['programming'],
example: '/github/pulse/DIYgod/RSSHub',
parameters: {
user: 'User name',
repo: 'Repo name',
period: "Time frame, selected from a repository's Pulse/Insights page. Possible values are: `daily`, `halfweekly`, `weekly`, or `monthly`. Default: `weekly`. If your RSS client supports it, consider aligning the polling frequency of the feed to the period.",
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['github.com/:user/:repo/pulse', 'github.com/:user/:repo/pulse/:period'],
},
],
name: 'Repo Pulse',
maintainers: ['jameschensmith'],
handler,
};
async function handler(ctx) {
const { user, repo, period } = ctx.req.param();
const periods = ['daily', 'halfweekly', 'weekly', 'monthly'];
const pulsePeriod = periods.includes(period) ? period : periods[2];
const link = `https://github.com/${user}/${repo}/pulse/${pulsePeriod}`;
const { data: pulsePage } = await got(link);
const $ = load(pulsePage);
const $mainSections = $('main .Layout-main').children();
const $subheading = $mainSections.eq(0);
const [periodFrom, periodTo] = $subheading.find('h2').text().split('–', 2);
const $overview = $mainSections.eq(1);
const overviewItems = $overview
.find('ul ul li')
.toArray()
.map((el) => $(el).text());
const $commitActivity = $mainSections.eq(2);
let commitActivity;
const $contributionData = $commitActivity.find('.js-pulse-contribution-data');
if ($contributionData.length) {
const summaryUrl = $contributionData.attr('data-pulse-diffstat-summary-url');
commitActivity = (await got(`https://github.com${summaryUrl}`)).data;
} else {
commitActivity = $commitActivity.text();
}
const $githubActivity = $mainSections.eq(3);
let githubActivity;
const $sections = $githubActivity.find('h3');
if ($sections.length) {
githubActivity = $sections.toArray().map((section) => {
const $section = $(section);
const $sectionSiblings = $section.nextUntil('h3');
const $paragraph = $section.nextUntil('ul');
const $list = $sectionSiblings.last();
return {
heading: $section.text(),
paragraph: $paragraph.length > 0 ? $paragraph.text() : undefined,
items: $list
.children()
.toArray()
.map((item) => {
const $item = $(item);
const $link = $item.find('a');
const $details = $item.find('p');
const $relativeTime = $details.find('relative-time');
$relativeTime.replaceWith($relativeTime.attr('datetime'));
return {
link: { text: $link.text(), url: $link.attr('href') },
details: $details.text(),
};
}),
};
});
}
return {
title: `${user}/${repo} ${pulsePeriod} Pulse`,
link,
item: [
{
guid: md5(`${user}${repo}${period}${periodFrom}${periodTo}`),
title: `${periodFrom} - ${periodTo}`,
description: renderToString(
<>
<h2>Overview</h2>
<ul>
{overviewItems.map((item) => (
<li>{item}</li>
))}
</ul>
{commitActivity ? raw(commitActivity) : null}
{(githubActivity ?? []).map((activity) => (
<>
<h2>{activity.heading}</h2>
{activity.paragraph ? <p>{activity.paragraph}</p> : null}
<ul>
{activity.items.map((item) => (
<li>
<a href={item.link.url}>{item.link.text}</a>
<p>{item.details}</p>
</li>
))}
</ul>
</>
))}
</>
),
pubDate: parseDate(periodTo),
},
],
};
}