Skip to content

Commit

Permalink
Add command to delete an issue
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed Feb 4, 2024
1 parent d2a7cae commit d357fc4
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 78 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ If `member-token` is not provided, `repo-token` will be used to check user's mem

### Commands

| Name | Description | Default value |
| -------------------- | --------------------------------------- | --------------- |
| `blurb-command` | Optional blurb command text. | Blurb |
| `duplicate-command` | Optional duplicate command text. | Duplicate of # |
| `edit-title-command` | Optional edit issue title command text. | Edit title to |
| `lock-command` | Optional lock command text. | Lock this issue |
| Name | Description | Default value |
| -------------------- | --------------------------------------- | ----------------- |
| `blurb-command` | Optional blurb command text. | Blurb |
| `delete-command` | Optional delete command text. | Delete this issue |
| `duplicate-command` | Optional duplicate command text. | Duplicate of # |
| `edit-title-command` | Optional edit issue title command text. | Edit title to |
| `lock-command` | Optional lock command text. | Lock this issue |

---

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
required: false
default: Blurb
description: Command to close an issue with a blurb posted as a comment
delete-command:
required: false
default: Delete this issue
description: Command to delete an issue
edit-title-command:
required: false
default: Edit title to
Expand Down
112 changes: 59 additions & 53 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion integ/duplicate-url-check.integ.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Octokit } from '@octokit/action';
import { beforeAll, describe, expect, test } from 'vitest';

import { baseIssueMetadata, deleteIssue, waitForClosedIssue } from './util';
import { baseIssueMetadata, waitForClosedIssue } from './util';
import { deleteIssue } from '../src/util/issues';

const octokit = new Octokit();

Expand Down
3 changes: 2 additions & 1 deletion integ/existing-source-check.integ.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Octokit } from '@octokit/action';
import { describe, expect, test } from 'vitest';

import { baseIssueMetadata, deleteIssue, waitForClosedIssue } from './util';
import { baseIssueMetadata, waitForClosedIssue } from './util';
import { deleteIssue } from '../src/util/issues';

const octokit = new Octokit();

Expand Down
16 changes: 0 additions & 16 deletions integ/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,3 @@ export async function waitForClosedIssue(
}
return issue;
}

export async function deleteIssue(client: GitHubClient, issueId: string) {
try {
await client.graphql(
`
mutation {
deleteIssue(input: {issueId: "${issueId}", clientMutationId: "Delete test issue"}) {
clientMutationId
}
}
`,
);
} catch (error: any) {
console.log(`Failed to delete issue: ${error.message}`);
}
}
7 changes: 6 additions & 1 deletion src/feature/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { IssueCommentEvent } from '@octokit/webhooks-types/schema';
import { GitHubClient } from '../../types';
import { minimizeComment } from '../../util/comments';

import { handleBlurb } from './blurbs';
import { closeDuplicateIssue } from './close-duplicate-issue';
import { deleteIssue } from './delete-issue';
import { editIssueTitle } from './edit-issue-title';
import { lockIssue } from './lock-issue';
import { handleBlurb } from './blurbs';

type CommandFn = (client: GitHubClient, commentBody: string) => Promise<void>;
interface Command {
Expand All @@ -24,6 +25,10 @@ const COMMANDS: Record<string, Command> = {
minimizeComment: true,
fn: handleBlurb,
},
delete: {
minimizeComment: false,
fn: deleteIssue,
},
duplicate: {
minimizeComment: false,
fn: closeDuplicateIssue,
Expand Down
16 changes: 16 additions & 0 deletions src/util/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ export async function addLabels(
});
core.info(`Added labels: ${labels}`);
}

export async function deleteIssue(client: GitHubClient, issueId: string) {
try {
await client.graphql(
`
mutation {
deleteIssue(input: {issueId: "${issueId}", clientMutationId: "Delete test issue"}) {
clientMutationId
}
}
`,
);
} catch (error: any) {
core.warning(`Failed to delete issue: ${error.message}`);
}
}

0 comments on commit d357fc4

Please sign in to comment.