diff --git a/README.md b/README.md index a3c5587..c12ccb4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ [Requirements](#requirements) | [Configuration](#configuration) | [Publishing new release](#publishing-new-release) `eslint-remote-tester-run-action` is a pre-configured Github workflow action for running [`eslint-remote-tester`](https://github.com/AriPerkkio/eslint-remote-tester). -It runs `eslint-remote-tester` and posts results in Github issue. Results are commented on existing open issue if present. +It runs `eslint-remote-tester` and posts results in Github issue. +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. 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). @@ -50,6 +51,7 @@ jobs: - uses: AriPerkkio/eslint-remote-tester-run-action@v2 with: issue-title: 'Results of weekly scheduled smoke test' + issue-label: 'smoke-test' max-result-count: 100 eslint-remote-tester-config: test/smoke/eslint-remote-tester.config.js ``` @@ -60,6 +62,7 @@ jobs: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :--------------------------------------------: | :----------------------------------------- | | `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}}` | | `issue-title` | Title of issue created for reporting results | :x: | `'Results of eslint-remote-tester-run-action'` | `'Results of weekly scheduled smoke test'` | +| `issue-label` | Label used on the created issue | :x: | :x: | `'smoke-test'` | | `eslint-remote-tester-config` | Path to project's `eslint-remote-tester.config.js` | :x: | `'eslint-remote-tester.config.js'` | `./path/to/custom.config.js` | | `max-result-count` | Maximum result count to be posted in result comment. | :x: | `50` | `100` | | `working-directory` | The working directory where action is run | :x: | :x: | `./ci` | diff --git a/action.yml b/action.yml index 679d173..eca45d6 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,9 @@ inputs: description: 'Title of issue created for reporting results' reqired: false default: 'Results of eslint-remote-tester-run-action' + issue-label: + description: 'Label used on the created issue' + reqired: false eslint-remote-tester-config: description: 'Path to eslint-remote-tester.config.js' reqired: false diff --git a/dist/index.js b/dist/index.js index 6fea9b7..a6b8fd9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5763,9 +5763,11 @@ var core = __toModule(require_core()); var import_github = __toModule(require_github()); var githubToken; var issueTitle; +var issueLabel; try { githubToken = core.getInput("github-token"); issueTitle = core.getInput("issue-title", {required: true}); + issueLabel = core.getInput("issue-label"); } catch (error2) { core.setFailed(error2.message); } @@ -5801,19 +5803,20 @@ var GithubClient = class { })); } async getExistingIssue() { + const query = issueLabel ? `label:"${issueLabel}"` : `${issueTitle} in:title`; const response = await this.requestAndRetry(() => this.octokit.search.issuesAndPullRequests({ sort: "created", order: "desc", q: [ - `${issueTitle} in:title`, + query, "is:issue", "is:open", `repo:${import_github.context.repo.owner}/${import_github.context.repo.repo}` ].join(" ") })); const {items} = response.data; - core.info(`Found ${items.length} open issues with title ${issueTitle}`); - const issue = items.find((a) => a.title === issueTitle); + core.info(`Found ${items.length} open issues matcing query (${query})`); + const issue = items[0]; return issue ? issue.number : void 0; } async createIssue(body) { @@ -5821,6 +5824,7 @@ var GithubClient = class { owner: import_github.context.repo.owner, repo: import_github.context.repo.repo, title: issueTitle, + labels: issueLabel ? [issueLabel] : void 0, body })); } diff --git a/src/github-client.ts b/src/github-client.ts index 30b8caa..cfe68ce 100644 --- a/src/github-client.ts +++ b/src/github-client.ts @@ -3,10 +3,12 @@ import { context, getOctokit } from '@actions/github'; let githubToken: string; let issueTitle: string; +let issueLabel: string | undefined; try { githubToken = core.getInput('github-token'); issueTitle = core.getInput('issue-title', { required: true }); + issueLabel = core.getInput('issue-label'); } catch (error) { core.setFailed(error.message); } @@ -68,12 +70,17 @@ class GithubClient { } private async getExistingIssue(): Promise { + // Look for existing issues based on issue label if present. Otherwise use issue title + const query = issueLabel + ? `label:"${issueLabel}"` + : `${issueTitle} in:title`; + const response = await this.requestAndRetry(() => this.octokit.search.issuesAndPullRequests({ sort: 'created', order: 'desc', q: [ - `${issueTitle} in:title`, + query, 'is:issue', 'is:open', `repo:${context.repo.owner}/${context.repo.repo}`, @@ -82,10 +89,10 @@ class GithubClient { ); const { items } = response.data; - core.info(`Found ${items.length} open issues with title ${issueTitle}`); + core.info(`Found ${items.length} open issues matcing query (${query})`); // In case of many matches use the latest issue - const issue = items.find(a => a.title === issueTitle); + const issue = items[0]; return issue ? issue.number : undefined; } @@ -95,6 +102,7 @@ class GithubClient { owner: context.repo.owner, repo: context.repo.repo, title: issueTitle, + labels: issueLabel ? [issueLabel] : undefined, body, }) ); diff --git a/test/__mocks__/GithubAPI.mock.ts b/test/__mocks__/GithubAPI.mock.ts index 52d314a..2d6973d 100644 --- a/test/__mocks__/GithubAPI.mock.ts +++ b/test/__mocks__/GithubAPI.mock.ts @@ -47,8 +47,8 @@ export default setupServer( items: mockNoExistingIssues() ? [] : [ - { title: 'Should not match', number: 1 }, { title, number: expectedIssueNumber }, + { title: 'Should not match', number: 1 }, ], }) ); diff --git a/test/jest.setup.ts b/test/jest.setup.ts index 5e33d1e..7638a3e 100644 --- a/test/jest.setup.ts +++ b/test/jest.setup.ts @@ -1,7 +1,11 @@ import GithubAPI from './__mocks__/GithubAPI.mock'; jest.mock('@actions/core', () => ({ - getInput: jest.fn().mockImplementation(key => `mock-${key}`), + getInput: jest + .fn() + .mockImplementation(key => + key === 'issue-label' ? undefined : `mock-${key}` + ), info: jest.fn(), }));