Skip to content

Commit 9e4b3b6

Browse files
authored
[refactor] replace Issue Comment with Action Output (#32)
1 parent ef0d17a commit 9e4b3b6

12 files changed

+704
-605
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: 'Bug Report(bug 提交)'
2-
about: 'Report a software bug on this repo.(提交本仓库的 Bug)'
3-
title: ''
2+
description: 'Report a software bug on this repo.(提交本仓库的 Bug)'
43
labels:
54
- bug
6-
assignees:
5+
assignees:
76
- TechQuery
87

98
body:
@@ -12,6 +11,7 @@ body:
1211
attributes:
1312
label: 'Describe the bug(bug 描述)'
1413
placeholder: 'A clear and concise description of what the bug is.(用简单的语言描述 bug。)'
14+
validations:
1515
required: true
1616

1717
- type: textarea
@@ -24,13 +24,15 @@ body:
2424
2. Click on '....'(点击“...”)
2525
3. See bug(出现 bug)
2626
4. ...
27+
validations:
2728
required: true
2829

2930
- type: textarea
3031
id: expected-behavior
3132
attributes:
3233
label: 'Expected behavior(预期现象)'
3334
placeholder: 'A clear and concise description of what you expected to happen.(用简单的语言描述期待看到的现象。)'
35+
validations:
3436
required: true
3537

3638
- type: textarea
@@ -46,10 +48,11 @@ body:
4648
placeholder: |
4749
- OS(操作系统): [e.g. iOS(例如:iOS)]
4850
- Node.js’s Version(Node.js 版本): [e.g. 12.12.12(例如:12.12.12)]
51+
validations:
4952
required: true
5053

5154
- type: textarea
5255
id: additional-context
5356
attributes:
5457
label: 'Additional context(其他)'
55-
placeholder: 'Add any other context about the problem here.(添加其他你想添加的内容)'
58+
placeholder: 'Add any other context about the problem here.(添加其他你想添加的内容)'

.github/ISSUE_TEMPLATE/feature.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: 'Feature(新特性)'
2-
about: 'Suggest an idea for this repo.(对本仓库新功能提出建议。)'
3-
title: ''
2+
description: 'Suggest an idea for this repo.(对本仓库新功能提出建议。)'
43
labels:
54
- feature
6-
assignees:
5+
assignees:
76
- TechQuery
87

98
body:
@@ -12,17 +11,19 @@ body:
1211
attributes:
1312
label: 'Is your feature request related to a problem? Please describe.(遇见的问题)'
1413
placeholder: 'A clear and concise description of what the problem is.(简单地描述问题)'
14+
validations:
1515
required: true
1616

1717
- type: textarea
1818
id: proposed-solution
1919
attributes:
20-
label: 'Describe the solution you'd like(描述想要的解决方案)'
20+
label: "Describe the solution you'd like(描述想要的解决方案)"
2121
placeholder: 'A clear and concise description of what you want to happen.(简洁地描述你想要的解决方案。)'
22+
validations:
2223
required: true
2324

2425
- type: textarea
2526
id: additional-context
2627
attributes:
2728
label: 'Additional context(其他)'
28-
placeholder: 'Add any other context about the problem here.(添加其他你想添加的内容)'
29+
placeholder: 'Add any other context about the problem here.(添加其他你想添加的内容)'

README-zh-cn.md

+43-39
Original file line numberDiff line numberDiff line change
@@ -45,50 +45,54 @@ news-translate
4545
```yml
4646
- uses: freeCodeCamp-China/article-webpage-to-markdown-action@v1
4747
with:
48-
newsLink: '${{ github.event.issue.Body }}'
49-
markDownFilePath: './articles/'
48+
pageURL: '${{ github.event.issue.body }}'
49+
markdownFolder: './articles/'
5050
githubToken: ${{ github.token }}
5151
```
5252
53-
下面是一个扩展示例,尽可能包含所有选项:
53+
下面是一个扩展示例,尽可能包含所有选项、输出
5454
5555
```yml
56-
- uses: freeCodeCamp-China/article-webpage-to-markdown-action@v1
57-
with:
58-
# 一个包含原文 URL 的字符串
59-
newsLink: '${{ github.event.issue.Body }}'
60-
# 需忽略元素的 CSS 选择符
61-
ignoreSelector: '.ad-wrapper'
62-
# 生成 MarkDown 文件的路径
63-
# 相对命令行工作目录的相对路径
64-
markDownFilePath: './articles/'
65-
githubToken: ${{ github.token }}
66-
```
67-
68-
其他 Action 获取 Markdown 文件路径:
69-
70-
```yml
71-
- name: fetch webpage to Markdown file
72-
# 你需要设置 action 的 id 名
73-
id: fetch-webpage-to-markdown
74-
uses: freeCodeCamp-China/article-webpage-to-markdown-action@v1
75-
with:
76-
# 一个包含原文 URL 的字符串
77-
newsLink: '${{ github.event.issue.Body }}'
78-
# 需忽略元素的 CSS 选择符
79-
ignoreSelector: '.ad-wrapper'
80-
# 生成 MarkDown 文件的路径
81-
# 相对命令行工作目录的相对路径
82-
markDownFilePath: './articles/'
83-
githubToken: ${{ github.token }}
84-
85-
- name: Use the output from my custom action
86-
run: |
87-
markdown_file_path=${{ steps.fetch-webpage-to-markdown.outputs.markdown_file_path }}
88-
echo "The file path is $markdown_file_path"
56+
name: 下载网页
57+
on:
58+
issues:
59+
types:
60+
- labeled
61+
jobs:
62+
fetch-pages:
63+
if: github.event.label.name == '文章'
64+
runs-on: ubuntu-latest
65+
permissions:
66+
contents: write
67+
issues: write
68+
steps:
69+
- id: fetch-md
70+
uses: freeCodeCamp-China/article-webpage-to-markdown-action@v2
71+
with:
72+
# 一个包含原文 URL 的字符串
73+
pageURL: '${{ github.event.issue.body }}'
74+
# 需包含元素的 CSS 选择符
75+
includedSelector: '.post-full-content'
76+
# 需排除元素的 CSS 选择符
77+
excludedSelector: '.ad-wrapper'
78+
# 生成 MarkDown 文件的路径是
79+
# 一个相对于命令行工作目录的相对路径
80+
markdownFolder: './articles/'
81+
githubToken: ${{ github.token }}
82+
83+
- name: 将输出发至评论区
84+
run: gh issue comment "$NUMBER" --body "$BODY"
85+
env:
86+
GH_TOKEN: ${{ github.token }}
87+
GH_REPO: ${{ github.repository }}
88+
NUMBER: ${{ github.event.issue.number }}
89+
BODY: |
90+
- 原文网址: [${{ steps.fetch-md.outputs.title }}](${{ steps.fetch-md.outputs.original_url }})
91+
- 原文作者: [${{ steps.fetch-md.outputs.author || 'anonymous' }}](${{ steps.fetch-md.outputs.author_url }})
92+
- Markdown 文件: [点击编辑](${{ steps.fetch-md.outputs.editor_url }})
8993
```
9094
91-
如果未配置选项 `markDownFilePath`,则默认情况下会在当前路径中生成文件。
95+
如果未配置选项 `markdownFolder`,则默认情况下会在当前路径中生成文件。
9296

9397
### 通过 GitHub 的 issue 运行脚本
9498

@@ -100,7 +104,7 @@ news-translate
100104
[原文链接](https://example.com/path/to/your/article/)
101105
```
102106

103-
用原文 URL 替换上文中的 URL,本 action 会在 issue 提交后运行,并将成功或失败消息发到 issue 评论中。
107+
用原文 URL 替换上文中的 URL,本 action 会在 issue 提交后运行,并将失败消息发到 issue 评论中。
104108

105109
如果脚本执行**失败**,您需要确认问题,解决问题,然后根据前面的步骤发布**新 issue**。 [_常见错误消息_](#常见错误消息) 和 _Actions 的日志_ 将为您提供一些可靠的提示。
106110

@@ -109,7 +113,7 @@ news-translate
109113
- **No parameters were found. Please confirm that the description of the issue has been entered.**
110114
issue 的描述为空,请根据模板填写内容。
111115
- **There is one file with the same name exists.Please check if the article has been added.**
112-
在 `markDownFilePath` 文件夹下有一个同名文件。
116+
在 `markdownFolder` 文件夹下有一个同名文件。
113117
- **The DOM of the website has been modified, or there is a problem with loading, please confirm.**
114118
网站的 DOM 结构可能更改,并且脚本需要修改。
115119

README.md

+44-40
Original file line numberDiff line numberDiff line change
@@ -43,52 +43,56 @@ news-translate
4343
Add the following step in the `jobs` field of your GitHub action configuration:
4444

4545
```yml
46-
- uses: freeCodeCamp-China/article-webpage-to-markdown-action@v1
46+
- uses: freeCodeCamp-China/article-webpage-to-markdown-action@v2
4747
with:
48-
newsLink: '${{ github.event.issue.Body }}'
49-
markDownFilePath: './articles/'
48+
pageURL: '${{ github.event.issue.body }}'
49+
markdownFolder: './articles/'
5050
githubToken: ${{ github.token }}
5151
```
5252
53-
The following is an extended example with all possible options available for this Action:
53+
The following is an extended example with all possible options & outputs available for this Action:
5454
5555
```yml
56-
- uses: freeCodeCamp-China/article-webpage-to-markdown-action@v1
57-
with:
58-
# A string contains an Original Article URL
59-
newsLink: '${{ github.event.issue.Body }}'
60-
# CSS selector of elements which should be ignored
61-
ignoreSelector: '.ad-wrapper'
62-
# Path of the generated MarkDown file
63-
# Relative path relative to current working directory
64-
markDownFilePath: './articles/'
65-
githubToken: ${{ github.token }}
66-
```
67-
68-
Other Action get Markdown file path:
69-
70-
```yml
71-
- name: fetch webpage to Markdown file
72-
# you need set action id
73-
id: fetch-webpage-to-markdown
74-
uses: freeCodeCamp-China/article-webpage-to-markdown-action@v1
75-
with:
76-
# A string contains an Original Article URL
77-
newsLink: '${{ github.event.issue.Body }}'
78-
# CSS selector of elements which should be ignored
79-
ignoreSelector: '.ad-wrapper'
80-
# Path of the generated MarkDown file
81-
# Relative path relative to current working directory
82-
markDownFilePath: './articles/'
83-
githubToken: ${{ github.token }}
84-
85-
- name: Use the output from my custom action
86-
run: |
87-
markdown_file_path=${{ steps.fetch-webpage-to-markdown.outputs.markdown_file_path }}
88-
echo "The file path is ${{markdown_file_path}}"
56+
name: fetch Web pages
57+
on:
58+
issues:
59+
types:
60+
- labeled
61+
jobs:
62+
fetch-pages:
63+
if: github.event.label.name == 'Article'
64+
runs-on: ubuntu-latest
65+
permissions:
66+
contents: write
67+
issues: write
68+
steps:
69+
- id: fetch-md
70+
uses: freeCodeCamp-China/article-webpage-to-markdown-action@v2
71+
with:
72+
# A string contains an Original Article URL
73+
pageURL: '${{ github.event.issue.body }}'
74+
# CSS selector of elements which should be included
75+
includedSelector: '.post-full-content'
76+
# CSS selector of elements which should be excluded
77+
excludedSelector: '.ad-wrapper'
78+
# Path of the generated MarkDown file is
79+
# a Relative Path relative to current working directory
80+
markdownFolder: './articles/'
81+
githubToken: ${{ github.token }}
82+
83+
- name: comment Outputs
84+
run: gh issue comment "$NUMBER" --body "$BODY"
85+
env:
86+
GH_TOKEN: ${{ github.token }}
87+
GH_REPO: ${{ github.repository }}
88+
NUMBER: ${{ github.event.issue.number }}
89+
BODY: |
90+
- Original URL: [${{ steps.fetch-md.outputs.title }}](${{ steps.fetch-md.outputs.original_url }})
91+
- Original author: [${{ steps.fetch-md.outputs.author || 'anonymous' }}](${{ steps.fetch-md.outputs.author_url }})
92+
- Markdown file: [click to edit](${{ steps.fetch-md.outputs.editor_url }})
8993
```
9094
91-
If you do not configure the option `markDownFilePath`, the file is generated in the current path by default.
95+
If you do not configure the option `markdownFolder`, the file is generated in the current path by default.
9296

9397
### Run the script by the issue of GitHub
9498

@@ -100,7 +104,7 @@ If you do not configure the option `markDownFilePath`, the file is generated in
100104
[Original article](https://example.com/path/to/your/article/)
101105
```
102106

103-
Replace the Link Value with the URL of an Original article, after the issue submitted, the action will run, and a success or failed message will be commented to the issue in the end.
107+
Replace the Link Value with the URL of an Original article, after the issue submitted, the action will run, and a failed message will be commented to the issue in the end.
104108

105109
If the script execution **fails**, you need to confirm the problem, solve them, and post a **new issue** according to the previous steps. In the **Action log**, The [_Common Error Messages_](#Common-Error-Messages) will give you some reliable tips.
106110

@@ -109,7 +113,7 @@ If the script execution **fails**, you need to confirm the problem, solve them,
109113
- **No parameters were found. Please confirm that the description of the issue has been entered.**
110114
The description of the issue is empty, please fill in the content according to the template.
111115
- **There is one file with the same name exists. Please check if the article has been added.**
112-
There is a file with the same name under the folder `markDownFilePath`.
116+
There is a file with the same name under the folder `markdownFolder`.
113117
- **The DOM of the website has been modified, or there is a problem with loading, please confirm.**
114118
The DOM structure of the website may be changed and the script needs to be modified.
115119

action.yml

+21-7
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@ name: 'article-webpage-to-markdown-action'
22
description: "Automatically generate Markdown files based on the webpages of articles. Currently supports freeCodeCamp's news site."
33
author: 'freeCodeCamp-China'
44
inputs:
5-
newsLink:
6-
description: 'A string in a specific format that contains a link to a article.'
5+
pageURL:
6+
description: 'A string contains an Original Article URL'
77
required: true
8-
ignoreSelector:
9-
description: 'CSS selector of elements which should be ignored'
10-
markDownFilePath:
11-
description: 'Path of the generated MarkDown file and relative path relative to the root folder.'
8+
includedSelector:
9+
description: 'CSS selector of elements which should be included'
10+
excludedSelector:
11+
description: 'CSS selector of elements which should be excluded'
12+
markdownFolder:
13+
description: 'Path of the generated MarkDown file is a Relative Path relative to current working directory'
1214
required: false
1315
default: './'
1416
githubToken:
15-
description: ' GitHub write and read token,auto create,no need to set'
17+
description: ' GitHub write and read token, auto created, no need to set'
1618
default: ''
1719

1820
runs:
1921
using: 'node20'
2022
main: 'dist/index.js'
2123

2224
outputs:
25+
original_url:
26+
description: 'The original URL of the article.'
27+
title:
28+
description: 'The title of the article.'
29+
date:
30+
description: 'The publish date of the article.'
31+
author:
32+
description: 'The author of the article.'
33+
author_url:
34+
description: 'The URL of the article author.'
2335
markdown_file_path:
2436
description: 'The path to the generated Markdown file.'
37+
editor_url:
38+
description: 'The editor URL of the generated Markdown file.'

dist/index.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "article-webpage-to-markdown-action",
33
"private": true,
4-
"version": "1.0.6",
4+
"version": "2.0.0",
55
"description": "Automatically generate Markdown files based on the webpages of articles. Currently supports freeCodeCamp's news site.",
66
"main": "dist/index.js",
77
"scripts": {
@@ -24,26 +24,26 @@
2424
"@actions/github": "^6.0.0",
2525
"@octokit/rest": "^20.1.1",
2626
"fs-extra": "^11.2.0",
27-
"linkedom": "^0.18.3",
28-
"marked": "^13.0.1",
27+
"linkedom": "^0.18.4",
28+
"marked": "^13.0.3",
2929
"turndown": "^7.2.0",
3030
"turndown-plugin-gfm": "^1.0.2",
31-
"yaml": "^2.4.5"
31+
"yaml": "^2.5.0"
3232
},
3333
"devDependencies": {
3434
"@types/fs-extra": "^11.0.4",
3535
"@types/jest": "^29.5.12",
36-
"@types/node": "^20.14.8",
37-
"@types/turndown": "^5.0.4",
36+
"@types/node": "^20.14.13",
37+
"@types/turndown": "^5.0.5",
3838
"@vercel/ncc": "^0.38.1",
39-
"husky": "^9.0.11",
39+
"husky": "^9.1.4",
4040
"jest": "^29.7.0",
4141
"lint-md-cli": "^0.1.2",
4242
"lint-staged": "^15.2.7",
43-
"prettier": "^3.3.2",
44-
"rimraf": "^5.0.7",
45-
"ts-jest": "^29.1.5",
46-
"typescript": "~5.5.2"
43+
"prettier": "^3.3.3",
44+
"rimraf": "^6.0.1",
45+
"ts-jest": "^29.2.3",
46+
"typescript": "~5.5.4"
4747
},
4848
"prettier": {
4949
"singleQuote": true,

0 commit comments

Comments
 (0)