Skip to content

Commit

Permalink
perf: inactive-mode support more
Browse files Browse the repository at this point in the history
  • Loading branch information
xrkffgg committed Jul 27, 2023
1 parent 554782c commit 9a2f8c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ jobs:
| body-includes | Body filtering | string | ✖ |
| title-includes | Title filtering | string | ✖ |
| inactive-day | Inactive days filtering | number | ✖ |
| inactive-mode | Detect inactive mode, default `issue`, optional `comment`, which is the last comment update time | string | ✖ |
| inactive-mode | Detect inactive mode, default `issue` | string | ✖ |
| inactive-label | The label name adding | string | ✖ |
| exclude-labels | Exclude labels filtering | string | ✖ |

Expand All @@ -802,6 +802,13 @@ jobs:
- `inactive-day`: When entering, it will filter the issue update time earlier than the current time minus the number of inactive days. If not entered, all
- `inactive-label`: The default is `inactive`, others can be customized. When the project does not contain the label, it will be created automatically
- `exclude-labels`: When set to include `$exclude-empty`, no label issue can be excluded
- `inactive-mode`:
- Default `issue`: the issue updated time
- Optional `comment`: the last comment update time
- Optional `issue-created`: the issue created time
- Optional `comment-created`: the comment creation time
- You can also set multiple such as: `comment, issue-created`
- It will be detected with priority, the update time of the last comment will be detected first, if there is no comment, the creation time of the issue will be used

[⏫ Back to list](#List)

Expand Down
9 changes: 8 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ jobs:
| body-includes | 包含内容筛选 | string | ✖ |
| title-includes | 包含标题筛选 | string | ✖ |
| inactive-day | 非活跃天数筛选 | number | ✖ |
| inactive-mode | 检测不活跃的模式,默认 `issue`,可选 `comment`,即为最后一个评论更新时间 | string | ✖ |
| inactive-mode | 检测不活跃的模式 | string | ✖ |
| inactive-label | 新增标签名称 | string | ✖ |
| exclude-labels | 排除标签筛选 | string | ✖ |

Expand All @@ -806,6 +806,13 @@ jobs:
- `inactive-day`:当输入时,会筛选 issue 更新时间早于当前时间减去非活跃天数。不填时,会查询所有
- `inactive-label`:默认为 `inactive`,可自定义其他。当项目未包含该 label 时,会自动新建
- `exclude-labels`:设置包含 `$exclude-empty` 时,可排除无 label issue
- `inactive-mode`:
- 默认 `issue`,检查 issue 的更新时间
- 可选 `comment`,检查最后一个评论的更新时间
- 可选 `issue-created`,检查 issue 的创建时间
- 可选 `comment-created`,最后一个评论的创建时间
- 你也可以设置多个如:`comment, issue-created`
- 将会以优先级检测,先检测最后一条评论更新时间,如无评论,则使用 issue 的创建时间

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

Expand Down
32 changes: 24 additions & 8 deletions src/helper/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,32 @@ export async function doQueryIssues(

const lastTime = dayjs.utc().subtract(+inactiveDay, 'day');

const inactiveMode = core.getInput('inactive-mode') || 'issue';
let updateTime = dayjs.utc(issue.updated_at);
if (inactiveMode === 'comment') {
ICE.setIssueNumber(issue.number);
const comments = await ICE.listComments();
if (comments.length) {
updateTime = dayjs.utc(comments[comments.length - 1].updated_at);
const inactiveMode = dealStringToArr(core.getInput('inactive-mode'));
let checkTime: dayjs.Dayjs | null = null;

for (const mode of inactiveMode) {
if (checkTime) {
break;
}
if (mode === 'comment' || mode === 'comment-created') {
ICE.setIssueNumber(issue.number);
const comments = await ICE.listComments();
if (comments.length) {
checkTime = dayjs.utc(
comments[comments.length - 1][mode === 'comment' ? 'updated_at' : 'created_at'],
);
}
}
if (mode === 'issue-created') {
checkTime = dayjs.utc(issue.created_at);
}
}
if (updateTime && updateTime.isSameOrBefore(lastTime)) {

if (!checkTime) {
checkTime = dayjs.utc(issue.updated_at);
}

if (checkTime && checkTime.isSameOrBefore(lastTime)) {
issues.push(issue);
issueNumbers.push(issue.number);
}
Expand Down

0 comments on commit 9a2f8c1

Please sign in to comment.