Skip to content

Commit c0213f3

Browse files
authored
feat: support adding issue labels (#29)
1 parent 7e2cf82 commit c0213f3

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
[Requirements](#requirements) | [Configuration](#configuration) | [Publishing new release](#publishing-new-release)
66

77
`eslint-remote-tester-run-action` is a pre-configured Github workflow action for running [`eslint-remote-tester`](https://github.com/AriPerkkio/eslint-remote-tester).
8-
It runs `eslint-remote-tester` and posts results in Github issue. Results are commented on existing open issue if present.
8+
It runs `eslint-remote-tester` and posts results in Github issue.
9+
Results are commented on existing **open** issue if present. Existing issues are searched based on `issue-label` if present. Otherwise `issue-title` will be used.
910

1011
Check out the use case description from eslint-remote-tester's documentation: [Plugin maintainer making sure all existing rules do not crash](https://github.com/AriPerkkio/eslint-remote-tester#plugin-maintainer-making-sure-all-existing-rules-do-not-crash).
1112

@@ -50,6 +51,7 @@ jobs:
5051
- uses: AriPerkkio/eslint-remote-tester-run-action@v2
5152
with:
5253
issue-title: 'Results of weekly scheduled smoke test'
54+
issue-label: 'smoke-test'
5355
max-result-count: 100
5456
eslint-remote-tester-config: test/smoke/eslint-remote-tester.config.js
5557
```
@@ -60,6 +62,7 @@ jobs:
6062
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :--------------------------------------------: | :----------------------------------------- |
6163
| `github-token` | Token for Github Authentication. See [About the `GITHUB_TOKEN` secret](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret). | :x: | `${{github.token}}` | `${{secrets.SOME_CUSTOM_TOKEN}}` |
6264
| `issue-title` | Title of issue created for reporting results | :x: | `'Results of eslint-remote-tester-run-action'` | `'Results of weekly scheduled smoke test'` |
65+
| `issue-label` | Label used on the created issue | :x: | :x: | `'smoke-test'` |
6366
| `eslint-remote-tester-config` | Path to project's `eslint-remote-tester.config.js` | :x: | `'eslint-remote-tester.config.js'` | `./path/to/custom.config.js` |
6467
| `max-result-count` | Maximum result count to be posted in result comment. | :x: | `50` | `100` |
6568
| `working-directory` | The working directory where action is run | :x: | :x: | `./ci` |

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
description: 'Title of issue created for reporting results'
1212
reqired: false
1313
default: 'Results of eslint-remote-tester-run-action'
14+
issue-label:
15+
description: 'Label used on the created issue'
16+
reqired: false
1417
eslint-remote-tester-config:
1518
description: 'Path to eslint-remote-tester.config.js'
1619
reqired: false

dist/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5763,9 +5763,11 @@ var core = __toModule(require_core());
57635763
var import_github = __toModule(require_github());
57645764
var githubToken;
57655765
var issueTitle;
5766+
var issueLabel;
57665767
try {
57675768
githubToken = core.getInput("github-token");
57685769
issueTitle = core.getInput("issue-title", {required: true});
5770+
issueLabel = core.getInput("issue-label");
57695771
} catch (error2) {
57705772
core.setFailed(error2.message);
57715773
}
@@ -5801,26 +5803,28 @@ var GithubClient = class {
58015803
}));
58025804
}
58035805
async getExistingIssue() {
5806+
const query = issueLabel ? `label:"${issueLabel}"` : `${issueTitle} in:title`;
58045807
const response = await this.requestAndRetry(() => this.octokit.search.issuesAndPullRequests({
58055808
sort: "created",
58065809
order: "desc",
58075810
q: [
5808-
`${issueTitle} in:title`,
5811+
query,
58095812
"is:issue",
58105813
"is:open",
58115814
`repo:${import_github.context.repo.owner}/${import_github.context.repo.repo}`
58125815
].join(" ")
58135816
}));
58145817
const {items} = response.data;
5815-
core.info(`Found ${items.length} open issues with title ${issueTitle}`);
5816-
const issue = items.find((a) => a.title === issueTitle);
5818+
core.info(`Found ${items.length} open issues matcing query (${query})`);
5819+
const issue = items[0];
58175820
return issue ? issue.number : void 0;
58185821
}
58195822
async createIssue(body) {
58205823
await this.requestAndRetry(() => this.octokit.issues.create({
58215824
owner: import_github.context.repo.owner,
58225825
repo: import_github.context.repo.repo,
58235826
title: issueTitle,
5827+
labels: issueLabel ? [issueLabel] : void 0,
58245828
body
58255829
}));
58265830
}

src/github-client.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { context, getOctokit } from '@actions/github';
33

44
let githubToken: string;
55
let issueTitle: string;
6+
let issueLabel: string | undefined;
67

78
try {
89
githubToken = core.getInput('github-token');
910
issueTitle = core.getInput('issue-title', { required: true });
11+
issueLabel = core.getInput('issue-label');
1012
} catch (error) {
1113
core.setFailed(error.message);
1214
}
@@ -68,12 +70,17 @@ class GithubClient {
6870
}
6971

7072
private async getExistingIssue(): Promise<number | undefined> {
73+
// Look for existing issues based on issue label if present. Otherwise use issue title
74+
const query = issueLabel
75+
? `label:"${issueLabel}"`
76+
: `${issueTitle} in:title`;
77+
7178
const response = await this.requestAndRetry(() =>
7279
this.octokit.search.issuesAndPullRequests({
7380
sort: 'created',
7481
order: 'desc',
7582
q: [
76-
`${issueTitle} in:title`,
83+
query,
7784
'is:issue',
7885
'is:open',
7986
`repo:${context.repo.owner}/${context.repo.repo}`,
@@ -82,10 +89,10 @@ class GithubClient {
8289
);
8390

8491
const { items } = response.data;
85-
core.info(`Found ${items.length} open issues with title ${issueTitle}`);
92+
core.info(`Found ${items.length} open issues matcing query (${query})`);
8693

8794
// In case of many matches use the latest issue
88-
const issue = items.find(a => a.title === issueTitle);
95+
const issue = items[0];
8996
return issue ? issue.number : undefined;
9097
}
9198

@@ -95,6 +102,7 @@ class GithubClient {
95102
owner: context.repo.owner,
96103
repo: context.repo.repo,
97104
title: issueTitle,
105+
labels: issueLabel ? [issueLabel] : undefined,
98106
body,
99107
})
100108
);

test/__mocks__/GithubAPI.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export default setupServer(
4747
items: mockNoExistingIssues()
4848
? []
4949
: [
50-
{ title: 'Should not match', number: 1 },
5150
{ title, number: expectedIssueNumber },
51+
{ title: 'Should not match', number: 1 },
5252
],
5353
})
5454
);

test/jest.setup.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import GithubAPI from './__mocks__/GithubAPI.mock';
22

33
jest.mock('@actions/core', () => ({
4-
getInput: jest.fn().mockImplementation(key => `mock-${key}`),
4+
getInput: jest
5+
.fn()
6+
.mockImplementation(key =>
7+
key === 'issue-label' ? undefined : `mock-${key}`
8+
),
59
info: jest.fn(),
610
}));
711

0 commit comments

Comments
 (0)