Skip to content

Commit

Permalink
feat: support adding issue labels
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Oct 7, 2023
1 parent 7e2cf82 commit bfd7e38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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
```
Expand All @@ -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` |
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -5801,11 +5803,12 @@ 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}`
Expand All @@ -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
}));
}
Expand Down
10 changes: 9 additions & 1 deletion src/github-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -68,12 +70,17 @@ class GithubClient {
}

private async getExistingIssue(): Promise<number | undefined> {
// 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}`,
Expand All @@ -95,6 +102,7 @@ class GithubClient {
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
labels: issueLabel ? [issueLabel] : undefined,
body,
})
);
Expand Down

0 comments on commit bfd7e38

Please sign in to comment.