diff --git a/.github/workflows/feedbot.yml b/.github/workflows/feedbot.yml index 9ffd94f..1fe56b8 100644 --- a/.github/workflows/feedbot.yml +++ b/.github/workflows/feedbot.yml @@ -30,6 +30,8 @@ jobs: uses: 'selfagency/slackfeedbot@dev' with: rss: 'https://feeds.washingtonpost.com/rss/homepage' + feed_name: 'Washington Post' + feed_image: 'https://www.washingtonpost.com/wp-stat/assets/favicons/touch-icon-iphone.png' slack_webhook: ${{ secrets.SLACK_WEBHOOK }} cache_dir: './slackfeedbot-cache' continue-on-error: true @@ -68,31 +70,4 @@ jobs: slack_webhook: ${{ secrets.SLACK_WEBHOOK }} cache_dir: './slackfeedbot-cache' continue-on-error: true - - name: New Relic - uses: 'selfagency/slackfeedbot@dev' - with: - rss: 'https://status.newrelic.com/history.rss' - slack_webhook: ${{ secrets.SLACK_WEBHOOK }} - cache_dir: './slackfeedbot-cache' - continue-on-error: true - - name: Fastly - uses: 'selfagency/slackfeedbot@dev' - with: - rss: 'https://status.fastly.com/history.rss' - slack_webhook: ${{ secrets.SLACK_WEBHOOK }} - cache_dir: './slackfeedbot-cache' - continue-on-error: true - - name: 1Password - uses: 'selfagency/slackfeedbot@dev' - with: - rss: 'https://1password.statuspage.io/history.rss' - slack_webhook: ${{ secrets.SLACK_WEBHOOK }} - cache_dir: './slackfeedbot-cache' - continue-on-error: true - - name: DataDog - uses: 'selfagency/slackfeedbot@dev' - with: - rss: 'https://status.datadoghq.com/history.rss' - slack_webhook: ${{ secrets.SLACK_WEBHOOK }} - cache_dir: './slackfeedbot-cache' - continue-on-error: true + diff --git a/README.md b/README.md index f68b016..ca6ed60 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - name: NYT - uses: 'selfagency/slackfeedbot@v1.2.8' + uses: 'selfagency/slackfeedbot@v1.2.9' with: rss: 'https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml' slack_webhook: ${{ secrets.SLACK_WEBHOOK }} @@ -35,7 +35,9 @@ jobs: Required fields denoted with `*`. Must specify `cache_dir` (which requires separate use of [actions/cache](https://github.com/actions/cache) or a similar solution) _or_ `interval`. -- `rss`*: The RSS feed URL. +- `rss`\*: The RSS feed URL. +- `feed_name`: A title to override the RSS feed's own title. +- `feed_image`: An image to override the RSS feed's default feed image. - `slack_webhook`\*: The Slack webhook URL (this can and probably should be a repository or organization secret). - `cache_dir`\*: The folder in which to cache feed data, which prevents publishing duplicates, or _alternately_... - `interval`\*: The number of minutes between runs of the parent workflow, as specified in the `cron` section of the `schedule` workflow trigger (may publish duplicates due to post pinning). @@ -73,7 +75,7 @@ jobs: key: feed-cache-${{ steps.generate-key.outputs.cache-key }} restore-keys: feed-cache- - name: NYT - uses: 'selfagency/slackfeedbot@v1.2.8' + uses: 'selfagency/slackfeedbot@v1.2.9' with: rss: 'https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml' slack_webhook: ${{ secrets.SLACK_WEBHOOK }} @@ -94,7 +96,7 @@ jobs: runs-on: ubuntu-latest steps: - name: NYT - uses: 'selfagency/slackfeedbot@v1.2.8' + uses: 'selfagency/slackfeedbot@v1.2.9' with: rss: 'https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml' slack_webhook: ${{ secrets.SLACK_WEBHOOK }} @@ -113,13 +115,13 @@ jobs: runs-on: ubuntu-latest steps: - name: LAT - uses: 'selfagency/slackfeedbot@v1.2.8' + uses: 'selfagency/slackfeedbot@v1.2.9' with: rss: 'https://www.latimes.com/rss2.0.xml' slack_webhook: ${{ secrets.SLACK_WEBHOOK }} interval: 15 - name: WaPo - uses: 'selfagency/slackfeedbot@v1.2.8' + uses: 'selfagency/slackfeedbot@v1.2.9' with: rss: 'https://feeds.washingtonpost.com/rss/homepage' slack_webhook: ${{ secrets.SLACK_WEBHOOK }} diff --git a/action.yml b/action.yml index c8bebf0..b810347 100644 --- a/action.yml +++ b/action.yml @@ -6,10 +6,16 @@ branding: color: 'orange' inputs: rss: - description: 'RSS Feed URL' + description: 'RSS feed URL' required: true + feed_name: + description: 'Feed name' + required: false + feed_image: + description: 'Feed image URL' + required: false slack_webhook: - description: 'Slack Webhook URL' + description: 'Slack webhook URL' required: true cache_dir: description: 'Cache folder' diff --git a/dist/index.cjs b/dist/index.cjs index e984813..a38b5f3 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -30101,7 +30101,7 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) { var getFeedImg = async (rssFeed) => { var _a, _b; const url = new URL(rssFeed); - const host = url.hostname.replace("//status.", "//").replace("//feed.", "//").replace("//feeds.", "//").replace("//rss.", "//"); + const host = url.hostname.replace(/^status\./, "").replace(/^feed\./, "").replace(/^feeds\./, "").replace(/^rss\./, ""); import_core3.default.debug(`Getting favicons for ${host}`); let favicon; try { @@ -30123,7 +30123,7 @@ var converter = new import_showdown.default.Converter(); var html2txt = (0, import_html_to_text.compile)({ wordwrap: 255 }); -var genPayload = async (filtered, unfiltered, rssFeed, unfurl, showDesc, showImg, showDate, showLink) => { +var genPayload = async (filtered, unfiltered, rssFeed, feedName, feedImg, unfurl, showDesc, showImg, showDate, showLink) => { try { const blocks = []; filtered.forEach((item) => { @@ -30134,7 +30134,7 @@ var genPayload = async (filtered, unfiltered, rssFeed, unfurl, showDesc, showImg const { document: document2 } = parseHTML("
"); const desc = (0, import_striptags.default)(item.description.replace(/>/g, ">").replace(/</g, "<"), ["p", "strong", "b", "em", "i", "a", "ul", "ol", "li"], " "); const markdown = converter.makeMarkdown(desc, document2); - text += `${markdown.replace(/\\-/g, "-").replace(/\\\|/g, "|").replace(/\*{2}/g, "*").replace(/\[(.+)\]\((.+)\)/g, "<$2|$1>")}`; + text += `${markdown.replace(/\\-/g, "-").replace(/\\\|/g, "|").replace(/\*{2,}/g, "*").replace(/\[(.+)\]\((.+)\)/g, "<$2|$1>")}`; } } if (item == null ? void 0 : item.title) { @@ -30181,8 +30181,8 @@ var genPayload = async (filtered, unfiltered, rssFeed, unfurl, showDesc, showImg }); const payload = { as_user: false, - username: unfiltered.title ? html2txt(unfiltered.title) : "FeedBot", - icon_url: await getFeedImg(rssFeed), + username: feedName.length ? feedName : unfiltered.title ? html2txt(unfiltered.title) : "FeedBot", + icon_url: feedImg.length ? feedImg : await getFeedImg(rssFeed), unfurl_links: unfurl, unfurl_media: unfurl, blocks @@ -30247,6 +30247,8 @@ var run = async () => { validate(); const slackWebhook = import_core7.default.getInput("slack_webhook"); const rssFeed = import_core7.default.getInput("rss"); + const feedName = import_core7.default.getInput("feed_name"); + const feedImg = import_core7.default.getInput("feed_image"); const cacheDir = import_core7.default.getInput("cache_dir"); const interval = import_core7.default.getInput("interval").length > 0 ? parseInt(import_core7.default.getInput("interval")) : void 0; const unfurl = import_core7.default.getInput("unfurl").length > 0 ? import_core7.default.getBooleanInput("unfurl") : false; @@ -30257,6 +30259,8 @@ var run = async () => { import_core7.default.debug(`Processed inputs: ${JSON.stringify({ slackWebhook, rssFeed, + feedName, + feedImg, cacheDir, interval, unfurl, @@ -30266,7 +30270,7 @@ var run = async () => { })}`); const { filtered, unfiltered, cached } = await getFeed(rssFeed, cacheDir, interval); if (filtered.length) { - const payload = await genPayload(filtered, unfiltered, rssFeed, unfurl, showDesc, showImg, showDate, showLink); + const payload = await genPayload(filtered, unfiltered, rssFeed, feedName, feedImg, unfurl, showDesc, showImg, showDate, showLink); await slack(payload, slackWebhook); if (cacheDir) await writeCache((unfiltered == null ? void 0 : unfiltered.title) || "", rssFeed, cacheDir, filtered, cached); diff --git a/src/action.ts b/src/action.ts index 5af1513..b996fc9 100644 --- a/src/action.ts +++ b/src/action.ts @@ -13,6 +13,8 @@ const run = async () => { // Parse inputs const slackWebhook = core.getInput('slack_webhook'); const rssFeed = core.getInput('rss'); + const feedName = core.getInput('feed_name'); + const feedImg = core.getInput('feed_image'); const cacheDir = core.getInput('cache_dir'); const interval = core.getInput('interval').length > 0 ? parseInt(core.getInput('interval')) : undefined; const unfurl = core.getInput('unfurl').length > 0 ? core.getBooleanInput('unfurl') : false; @@ -25,6 +27,8 @@ const run = async () => { `Processed inputs: ${JSON.stringify({ slackWebhook, rssFeed, + feedName, + feedImg, cacheDir, interval, unfurl, @@ -39,7 +43,18 @@ const run = async () => { if (filtered.length) { // Generate payload - const payload = await genPayload(filtered, unfiltered, rssFeed, unfurl, showDesc, showImg, showDate, showLink); + const payload = await genPayload( + filtered, + unfiltered, + rssFeed, + feedName, + feedImg, + unfurl, + showDesc, + showImg, + showDate, + showLink + ); // Send payload to Slack await slack(payload, slackWebhook); diff --git a/src/lib/feedimg.ts b/src/lib/feedimg.ts index 8dc039e..17a8193 100644 --- a/src/lib/feedimg.ts +++ b/src/lib/feedimg.ts @@ -6,10 +6,10 @@ import type { Icons } from '../types.d'; const getFeedImg = async (rssFeed: string): Promise => { const url = new URL(rssFeed); const host = url.hostname - .replace('//status.', '//') - .replace('//feed.', '//') - .replace('//feeds.', '//') - .replace('//rss.', '//'); + .replace(/^status\./, '') + .replace(/^feed\./, '') + .replace(/^feeds\./, '') + .replace(/^rss\./, ''); core.debug(`Getting favicons for ${host}`); let favicon; diff --git a/src/lib/payload.ts b/src/lib/payload.ts index 57b35e3..873d889 100644 --- a/src/lib/payload.ts +++ b/src/lib/payload.ts @@ -17,6 +17,8 @@ const genPayload = async ( filtered: RssFeedItem[], unfiltered: RssFeed, rssFeed: string, + feedName: string, + feedImg: string, unfurl: boolean, showDesc: boolean, showImg: boolean, @@ -42,7 +44,7 @@ const genPayload = async ( text += `${markdown .replace(/\\-/g, '-') .replace(/\\\|/g, '|') - .replace(/\*{2}/g, '*') + .replace(/\*{2,}/g, '*') .replace(/\[(.+)\]\((.+)\)/g, '<$2|$1>')}`; } } @@ -102,8 +104,8 @@ const genPayload = async ( const payload = { as_user: false, - username: unfiltered.title ? html2txt(unfiltered.title) : 'FeedBot', - icon_url: await getFeedImg(rssFeed), + username: feedName.length ? feedName : unfiltered.title ? html2txt(unfiltered.title) : 'FeedBot', + icon_url: feedImg.length ? feedImg : await getFeedImg(rssFeed), unfurl_links: unfurl, unfurl_media: unfurl, blocks