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: add exclude-labels for query issues #74

Merged
merged 4 commits into from Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -15,5 +15,8 @@ jobs:
- name: format
run: yarn format-check

- name: test
run: yarn test

- name: package
run: yarn package
3 changes: 3 additions & 0 deletions README.en-US.md
Expand Up @@ -781,6 +781,7 @@ jobs:
| title-includes | Title filtering | string | ✖ |
| inactive-day | Inactive days filtering | number | ✖ |
| inactive-label | The label name adding | string | ✖ |
| exclude-labels | Exclude labels filtering | string | ✖ |

- `labels`: When there are multiple, the query will have multiple at the same time. If not entered, all
- `issue-state`: The default is `all`. Optional value `open` `closed`, when these 2 items are not, both are `all`
Expand Down Expand Up @@ -873,6 +874,7 @@ jobs:
| body-includes | Body filtering | string | ✖ |
| title-includes | Title filtering | string | ✖ |
| inactive-day | Inactive days filtering | number | ✖ |
| exclude-labels | Exclude labels filtering | string | ✖ |

- `labels`: When there are multiple, the query will have multiple at the same time. If not entered, all
- `issue-assignee`: Multiplayer is not supported. If you do not enter or enter *, all will be searched. Entering `none` will query issues for which the specified person is not added
Expand Down Expand Up @@ -957,6 +959,7 @@ jobs:
| title-includes | Title filtering | string | ✖ |
| inactive-day | Inactive days filtering | number | ✖ |
| lock-reason | Reason for locking issue | string | ✖ |
| exclude-labels | Exclude labels filtering | string | ✖ |

- `labels`: When there are multiple, the query will have multiple at the same time. If not entered, all
- `issue-state`: The default is `all`. Optional value `open` `closed`, when these 2 items are not, both are `all`
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -783,6 +783,7 @@ jobs:
| title-includes | 包含标题筛选 | string | ✖ |
| inactive-day | 非活跃天数筛选 | number | ✖ |
| inactive-label | 新增标签名称 | string | ✖ |
| exclude-labels | 排除标签筛选 | string | ✖ |

- `labels`:为多个时,会查询同时拥有多个。不填时,会查询所有
- `issue-state`:默认为 `open`。可选值 `all` `closed`,非这 2 项时,均为 `open`
Expand Down Expand Up @@ -871,6 +872,7 @@ jobs:
| body-includes | 包含内容筛选 | string | ✖ |
| title-includes | 包含标题筛选 | string | ✖ |
| inactive-day | 非活跃天数筛选 | number | ✖ |
| exclude-labels | 排除标签筛选 | string | ✖ |

- `labels`:为多个时,会查询同时拥有多个。不填时,会查询所有
- `issue-assignee`:不支持多人。不填或输入 * 时,查询所有。输入 `none` 会查询未添加指定人的 issues
Expand Down Expand Up @@ -955,6 +957,7 @@ jobs:
| title-includes | 包含标题筛选 | string | ✖ |
| inactive-day | 非活跃天数筛选 | number | ✖ |
| lock-reason | 锁定 issue 的原因 | string | ✖ |
| exclude-labels | 排除标签筛选 | string | ✖ |

- `labels`:为多个时,会查询同时拥有多个。不填时,会查询所有
- `issue-state`:默认为 `open`。可选值 `all` `closed`,非这 2 项时,均为 `open`
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -74,6 +74,9 @@ inputs:
description: 'The reason lock issue'
inactive-label:
description: 'Issue label set use'
exclude-labels:
description: 'Query issues exclude labels'

duplicate-command:
description: 'For mark-duplicate'
duplicate-labels:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -12,6 +12,7 @@
"deploy": "npm run docs:build && npm run docs:deploy",
"format": "prettier --write **/*.ts **/*.js",
"format-check": "prettier --check **/*.ts **/*.js",
"test": "father test",
"package": "ncc build src/main.js -o dist",
"users": "node ./script/update-users.js",
"main": "node ./src/main.js",
Expand All @@ -35,6 +36,7 @@
"@actions/github": "^4.0.0",
"@octokit/rest": "^18.0.12",
"dayjs": "^1.9.7",
"father": "^2.30.7",
"lodash": "^4.17.20"
},
"devDependencies": {
Expand Down
20 changes: 19 additions & 1 deletion src/public.js
@@ -1,7 +1,7 @@
const core = require('@actions/core');
const { Octokit } = require('@octokit/rest');

const { getPreMonth } = require('./util.js');
const { getPreMonth, dealStringToArr } = require('./util.js');

// **************************************************************************
var dayjs = require('dayjs');
Expand All @@ -23,9 +23,20 @@ const issueMentioned = core.getInput('issue-mentioned');
const bodyIncludes = core.getInput('body-includes');
const titleIncludes = core.getInput('title-includes');

const excludeLabels = core.getInput('exclude-labels');

const inactiveDay = core.getInput('inactive-day');

// **************************************************************************
/**
* 查询 Issues 列表
* @param {*} owner
* @param {*} repo
* @param {*} labels
* @param {*} state
* @param {*} creator
* @returns
*/
async function doQueryIssues(owner, repo, labels, state, creator) {
let params = {
owner,
Expand Down Expand Up @@ -58,6 +69,13 @@ async function doQueryIssues(owner, repo, labels, state, creator) {
* You can identify pull requests by the pull_request key.
*/
if (a && b && iss.pull_request === undefined) {
if (excludeLabels) {
const labels = dealStringToArr(excludeLabels);
Copy link
Member

@meteorlxy meteorlxy Aug 9, 2021

Choose a reason for hiding this comment

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

The result of dealStringToArr(excludeLabels) could be extracted to outer scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

PR welcome ~

for (let i = 0; i < iss.labels.length; i += 1) {
if (labels.includes(iss.labels[i].name)) return;
}
}

if (inactiveDay) {
let lastTime = dayjs.utc().subtract(Number(inactiveDay), 'day');
let updateTime = dayjs.utc(iss.updated_at);
Expand Down
45 changes: 45 additions & 0 deletions tests/public.test.js
@@ -0,0 +1,45 @@
describe('Test Public', () => {
it('test query', () => {
const issues = [
{
id: 0,
labels: [{ name: '0' }, { name: '1' }],
},
{
id: 1,
labels: [{ name: '1' }, { name: '2' }],
},
{
id: 2,
labels: [{ name: '2' }, { name: '3' }],
},
{
id: 3,
labels: [{ name: '1' }, { name: '4' }],
},
{
id: 4,
labels: [{ name: '1' }, { name: '3' }],
},
{
id: 5,
labels: [{ name: '1' }, { name: '5' }],
},
];

let ex = ['2', '4'];
let r = [];

issues.forEach(iss => {
for (let i = 0; i < iss.labels.length; i += 1) {
if (ex.includes(iss.labels[i].name)) return;
}
r.push(iss);
});

expect(r[0].id).toEqual(0);
expect(r[1].id).toEqual(4);
expect(r[2].id).toEqual(5);
expect(r.length).toEqual(3);
});
});