@@ -23,7 +23,26 @@ async function writeCache(cacheFile: string, cacheLimit: number, cache: string[]
23
23
}
24
24
}
25
25
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
+
27
46
// authenticate with mastodon
28
47
let masto : MastoClient ;
29
48
try {
@@ -105,6 +124,8 @@ export async function main(): Promise<void> {
105
124
core . debug ( `cacheLimit: ${ cacheLimit } ` ) ;
106
125
const statusVisibility : StatusVisibility = < StatusVisibility > core . getInput ( 'status-visibility' , { trimWhitespace : true } ) ;
107
126
core . debug ( `statusVisibility: ${ statusVisibility } ` ) ;
127
+ const dryRun : boolean = core . getBooleanInput ( 'dry-run' ) ;
128
+ core . debug ( `dryRun: ${ dryRun } ` ) ;
108
129
109
130
// get the rss feed
110
131
let rss = await getRss ( rssFeed ) ;
@@ -116,7 +137,7 @@ export async function main(): Promise<void> {
116
137
rss = await filterCachedItems ( < FeedEntry [ ] > rss , cache ) ;
117
138
118
139
// post the new items
119
- await postItems ( apiEndpoint , apiToken , < FeedEntry [ ] > rss , statusVisibility , cache ) ;
140
+ await postItems ( apiEndpoint , apiToken , < FeedEntry [ ] > rss , statusVisibility , dryRun , cache ) ;
120
141
121
142
// write the cache
122
143
await writeCache ( cacheFile , cacheLimit , cache ) ;
0 commit comments