Skip to content

Commit 31772f4

Browse files
committed
Add dry-run functionality (#11)
Refs selfagency#3
1 parent 5f8e2bd commit 31772f4

File tree

4 files changed

+53
-28
lines changed

4 files changed

+53
-28
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
description: 'Visibility of the posted status (public | unlisted | private | direct)'
1313
required: false
1414
default: 'public'
15+
dry-run:
16+
description: 'Only fetch RSS feed and update cache but skip posting to Mastodon.'
17+
required: false
18+
default: 'false'
1519
cache-file:
1620
description: 'Cache file'
1721
required: true

dist/index.js

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,26 @@ async function writeCache(cacheFile: string, cacheLimit: number, cache: string[]
2323
}
2424
}
2525

26-
async function postItems(apiEndpoint: string, apiToken: string, rss: FeedEntry[], visibility: StatusVisibility, cache: string[]) {
26+
async function postItems(
27+
apiEndpoint: string, apiToken: string, rss: FeedEntry[],
28+
visibility: StatusVisibility, dryRun: boolean, cache: string[]) {
29+
if (dryRun) {
30+
// Add new items to cache
31+
for (const item of rss) {
32+
try {
33+
const hash = <string>new SHA256Hash().hash(<string>item.link);
34+
core.debug(`Adding ${item.title} with hash ${hash} to cache`);
35+
36+
// add the item to the cache
37+
cache.push(hash);
38+
} catch (e) {
39+
core.setFailed(`Failed to ad item to cache: ${(<Error>e).message}`);
40+
}
41+
}
42+
43+
return;
44+
}
45+
2746
// authenticate with mastodon
2847
let masto: MastoClient;
2948
try {
@@ -105,6 +124,8 @@ export async function main(): Promise<void> {
105124
core.debug(`cacheLimit: ${cacheLimit}`);
106125
const statusVisibility: StatusVisibility = <StatusVisibility>core.getInput('status-visibility', { trimWhitespace: true });
107126
core.debug(`statusVisibility: ${statusVisibility}`);
127+
const dryRun: boolean = core.getBooleanInput('dry-run');
128+
core.debug(`dryRun: ${dryRun}`);
108129

109130
// get the rss feed
110131
let rss = await getRss(rssFeed);
@@ -116,7 +137,7 @@ export async function main(): Promise<void> {
116137
rss = await filterCachedItems(<FeedEntry[]>rss, cache);
117138

118139
// post the new items
119-
await postItems(apiEndpoint, apiToken, <FeedEntry[]>rss, statusVisibility, cache);
140+
await postItems(apiEndpoint, apiToken, <FeedEntry[]>rss, statusVisibility, dryRun, cache);
120141

121142
// write the cache
122143
await writeCache(cacheFile, cacheLimit, cache);

0 commit comments

Comments
 (0)