Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support default issueNumber get from context #81

Merged
merged 2 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ jobs:
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| assignees | Designated person. No operation when no input or empty character | string | ✖ |
| random-to | When set, it will be randomly selected in assignees | number | ✖ |

Expand Down Expand Up @@ -271,7 +271,7 @@ jobs:
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| labels | New labels. When it is not filled in or is empty character, do not add | string | ✖ |

- `labels` support multiple and separated by comma
Expand All @@ -296,7 +296,7 @@ Close the specified issue.
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |

⏫ [Back to list](#List)

Expand Down Expand Up @@ -333,7 +333,7 @@ jobs:
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| body | Add comment content | string | ✖ |
| contents | Add [reaction](#reactions-types) | string | ✖ |

Expand Down Expand Up @@ -468,7 +468,7 @@ jobs:
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| lock-reason | Reason for locking issue | string | ✖ |

- `lock-reason`: Optional values are `off-topic` `too heated` `resolved` `spam`
Expand Down Expand Up @@ -537,7 +537,7 @@ Open the specified issue.
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |

⏫ [Back to list](#List)

Expand All @@ -559,7 +559,7 @@ Remove the person designated by issue.
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| assignees | Designated person removed. When it is an empty character, do not remove | string | ✔ |

⏫ [Back to list](#List)
Expand All @@ -582,7 +582,7 @@ Remove the specified labels.
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| labels | The removed labels. When it is a blank character, do not remove | string | ✔ |

- `labels` supports multiple, such as `x1,x2,x3`, only the labels added by the issue will be removed
Expand All @@ -607,7 +607,7 @@ Replace the labels of issue.
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| labels | labels set. When empty characters, will remove all | string | ✔ |

⏫ [Back to list](#List)
Expand All @@ -629,7 +629,7 @@ Unlock the specified issue.
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |

⏫ [Back to list](#List)

Expand Down Expand Up @@ -699,7 +699,7 @@ Update the specified issue according to the `issue-number`.
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| state | Modify the status of issue, optional value `open` `closed` | string | ✖ |
| title | Modify the title of the issue | string | ✖ |
| body | Modify the content of issue | string | ✖ |
Expand Down Expand Up @@ -841,7 +841,7 @@ jobs:
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| assignee-includes | Assignees contains check | string | ✖ |
| title-includes | Title contains check | string | ✖ |
| title-excludes | Check whether the title is empty after removing the default title | string | ✖ |
Expand Down Expand Up @@ -916,7 +916,7 @@ Find the current warehouse issue No. 1, the creator is k and the content contain
| -- | -- | -- | -- |
| actions | Action type | string | ✔ |
| token | [Token explain](#token) | string | ✔ |
| issue-number | The number of issue | number | |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | |
| comment-auth | Comment creator, all will be queried if not filled | string | ✖ |
| body-includes | Comment content includes filtering, no verification if not filled | string | ✖ |
| direction | Return `comments` sort | string | ✖ |
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| assignees | 指定人。当不填或者为空字符时,不操作 | string | ✖ |
| random-to | 当设置时,会在 assignees 中随机选择 | number | ✖ |

Expand Down Expand Up @@ -275,7 +275,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| labels | 新增的 labels。当不填或者为空字符时,不新增 | string | ✖ |

- `labels` 支持多个,需用逗号隔开
Expand All @@ -300,7 +300,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |

⏫ [返回列表](#列-表)

Expand Down Expand Up @@ -337,7 +337,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| body | 新增评论的内容 | string | ✖ |
| contents | 为新增评论的增加 [reaction](#reactions-types) | string | ✖ |

Expand Down Expand Up @@ -472,7 +472,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| lock-reason | 锁定 issue 的原因 | string | ✖ |

- `lock-reason`:可选值有 `off-topic` `too heated` `resolved` `spam`
Expand Down Expand Up @@ -541,7 +541,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |

⏫ [返回列表](#列-表)

Expand All @@ -563,7 +563,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| assignees | 移除的指定人。当为空字符时,不进行移除 | string | ✔ |

⏫ [返回列表](#列-表)
Expand All @@ -586,7 +586,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| labels | 移除的 labels。当为空字符时,不进行移除 | string | ✔ |

- `labels` 支持多个,如 `x1,x2,x3`,只会移除 issue 已添加的 labels
Expand All @@ -611,7 +611,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| labels | labels 设置。当空字符时,会移除所有 | string | ✔ |

⏫ [返回列表](#列-表)
Expand All @@ -633,7 +633,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |

⏫ [返回列表](#列-表)

Expand Down Expand Up @@ -703,7 +703,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| state | 修改 issue 的状态,可选值 `open` `closed` | string | ✖ |
| title | 修改 issue 的标题 | string | ✖ |
| body | 修改 issue 的内容 | string | ✖ |
Expand Down Expand Up @@ -839,7 +839,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| assignee-includes | 是否包含指定人 | string | ✖ |
| title-includes | 标题包含校验 | string | ✖ |
| title-excludes | 检测标题移除默认 title 后是否为空 | string | ✖ |
Expand Down Expand Up @@ -914,7 +914,7 @@ jobs:
| -- | -- | -- | -- |
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✔ |
| issue-number | 指定的 issue | number | |
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | |
| comment-auth | 评论创建者,不填时会查询所有 | string | ✖ |
| body-includes | 评论内容包含过滤,不填时无校验 | string | ✖ |
| direction | 返回 `comments` 排序 | string | ✖ |
Expand Down
9 changes: 6 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ const ALLACTIONS = [
// **************************************************************************
async function main() {
try {
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const ctx = github.context;
const { owner, repo } = ctx.repo;

const issueNumber = core.getInput('issue-number');
let defaultNo;
if (ctx.eventName === 'issues') defaultNo = ctx.payload.issue.number;

const issueNumber = core.getInput('issue-number') || defaultNo;
Comment on lines +71 to +73
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use optional chaining here? (Not sure if it's supported in github actions)

const issueNumber = core.getInput('issue-number') || ctx.payload?.issue?.number;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node 12 does not support

const commentId = core.getInput('comment-id');

const defaultBody = `Currently at ${owner}/${repo}. And this is default comment.`;
Expand Down