|
1 | 1 | import { Toolkit } from 'actions-toolkit'
|
2 | 2 | import { ReadmeBox } from 'readme-box'
|
3 |
| -import Parser from 'rss-parser' |
4 |
| -import mustache from 'mustache' |
5 |
| - |
6 |
| -const parser = new Parser() |
7 | 3 |
|
8 | 4 | interface Inputs {
|
9 |
| - 'feed-url': string |
10 | 5 | 'readme-section': string
|
11 |
| - max: string |
12 |
| - template: string |
13 | 6 | github_token: string
|
14 | 7 | branch: string
|
15 | 8 | message: string
|
16 | 9 | [key: string]: string
|
17 | 10 | }
|
18 | 11 |
|
19 | 12 | Toolkit.run<Inputs>(async tools => {
|
| 13 | + console.log('🚀 Hugo Updater v2 - Starting update'); |
| 14 | + |
20 | 15 | // Check if we have a valid token
|
21 | 16 | if (!tools.token) {
|
22 | 17 | throw new Error('GitHub token is required but not provided. Please ensure GITHUB_TOKEN is available or pass it explicitly as github_token input.')
|
23 | 18 | }
|
24 | 19 |
|
25 |
| - console.log('=== DEBUG INFO ==='); |
26 |
| - console.log('Environment check - start of action'); |
27 |
| - console.log('Repository:', tools.context.repo.owner + '/' + tools.context.repo.repo); |
28 |
| - |
29 |
| - // Fetch feed |
30 |
| - const feed = await parser.parseURL(tools.inputs['feed-url']) |
31 |
| - console.log('RSS feed fetched successfully, items:', feed.items?.length || 0); |
32 |
| - |
33 |
| - if (!feed.items) { |
34 |
| - throw new Error('feed.items was not found!') |
35 |
| - } |
36 |
| - |
37 |
| - // Create our new list |
38 |
| - // const timestamp = new Date().getTime().toString(); |
39 |
| - const newString = feed.items |
40 |
| - .slice(0, parseInt(tools.inputs.max, 10)) |
41 |
| - .map(item => mustache.render(tools.inputs.template, item)) |
42 |
| - .join('\n') |
43 |
| - // .concat(`<!--Updated at ${timestamp}-->\n`) |
44 |
| - |
45 | 20 | // Use the token from inputs if provided, otherwise fall back to tools.token
|
46 | 21 | const token = tools.inputs.github_token || tools.token;
|
| 22 | + const repository = tools.context.repo.owner + '/' + tools.context.repo.repo; |
| 23 | + const branch = tools.inputs.branch || tools.context.payload.repository?.default_branch; |
| 24 | + const section = tools.inputs['readme-section']; |
| 25 | + |
| 26 | + console.log('📊 Configuration:'); |
| 27 | + console.log(` Repository: ${repository}`); |
| 28 | + console.log(` Branch: ${branch}`); |
| 29 | + console.log(` Section: ${section}`); |
| 30 | + console.log(` Token source: ${tools.inputs.github_token ? 'from input' : 'from tools.token'}`); |
47 | 31 |
|
48 |
| - // Debug logging (token will be masked in logs automatically) |
49 |
| - console.log('Token source:', tools.inputs.github_token ? 'from input' : 'from tools.token'); |
50 |
| - console.log('Token exists:', !!token); |
51 |
| - console.log('Repository:', tools.context.repo.owner + '/' + tools.context.repo.repo); |
52 |
| - console.log('Branch:', tools.inputs.branch || tools.context.payload.repository?.default_branch); |
| 32 | + // Create timestamp comment |
| 33 | + const timestamp = new Date().toISOString(); |
| 34 | + const timestampComment = `<!--Updated at ${timestamp}-->`; |
53 | 35 |
|
54 |
| - console.log('About to call ReadmeBox.updateSection...'); |
| 36 | + console.log('⏰ Generated timestamp:', timestamp); |
| 37 | + console.log('📝 Updating README section with timestamp comment...'); |
55 | 38 |
|
56 | 39 | try {
|
57 | 40 | // Update the section of our README
|
58 |
| - await ReadmeBox.updateSection(newString, { |
| 41 | + await ReadmeBox.updateSection(timestampComment, { |
59 | 42 | ...tools.context.repo,
|
60 | 43 | token: token,
|
61 |
| - section: tools.inputs['readme-section'], |
62 |
| - branch: tools.inputs.branch || tools.context.payload.repository?.default_branch, |
| 44 | + section: section, |
| 45 | + branch: branch, |
63 | 46 | message: tools.inputs.message
|
64 |
| - }) |
65 |
| - console.log('ReadmeBox.updateSection completed successfully'); |
| 47 | + }); |
| 48 | + |
| 49 | + console.log('✅ README section updated successfully!'); |
| 50 | + console.log(` Section '${section}' now contains: ${timestampComment}`); |
| 51 | + console.log(` Committed with message: "${tools.inputs.message}"`); |
| 52 | + |
66 | 53 | } catch (error) {
|
67 |
| - console.error('ReadmeBox.updateSection failed:', error); |
| 54 | + console.error('❌ Failed to update README section:', error); |
68 | 55 | throw error;
|
69 | 56 | }
|
70 | 57 | })
|
0 commit comments