Skip to content

Commit

Permalink
feat: plugin for issue closed
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Apr 26, 2024
1 parent 57ff615 commit 36e1a03
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ coverage
junit.xml

*.pem

*.pem
Binary file removed bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions src/github/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { issueCommentCreated } from "./issue-comment/created";
import { repositoryDispatch } from "./repository-dispatch";
import { dispatchWorkflow, getDefaultBranch } from "../utils/workflow-dispatch";
import { DelegatedComputeInputs } from "../types/plugin";
import { issuesClosed } from "./issues/closed";

function tryCatchWrapper(fn: (event: EmitterWebhookEvent) => unknown) {
return async (event: EmitterWebhookEvent) => {
Expand All @@ -18,6 +19,7 @@ function tryCatchWrapper(fn: (event: EmitterWebhookEvent) => unknown) {

export function bindHandlers(eventHandler: GitHubEventHandler) {
eventHandler.on("issue_comment.created", issueCommentCreated);
eventHandler.on("issues.closed", issuesClosed);
eventHandler.on("repository_dispatch", repositoryDispatch);
eventHandler.onAny(tryCatchWrapper((event) => handleEvent(event, eventHandler))); // onAny should also receive GithubContext but the types in octokit/webhooks are weird
}
Expand Down
12 changes: 12 additions & 0 deletions src/github/handlers/issues/closed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GitHubContext } from "../../github-context";

export async function issuesClosed(event: GitHubContext<"issues.closed">) {
if (event.payload.issue.state_reason === "not_planned") {
await event.octokit.issues.createComment({
owner: event.payload.repository.owner.login,
repo: event.payload.repository.name,
issue_number: event.payload.issue.number,
body: "Skipping reward generation as the issue was closed as not planned.",
});
}
}
2 changes: 1 addition & 1 deletion src/github/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Type as T } from "@sinclair/typebox";
import { StaticDecode } from "@sinclair/typebox";
import { githubWebhookEvents } from "./webhook-events";

const pluginNameRegex = new RegExp("^([0-9a-zA-Z-._]+)/([0-9a-zA-Z-._]+)(?::([0-9a-zA-Z-._]+))?(?:@([0-9a-zA-Z-._]+))?$");
const pluginNameRegex = new RegExp("^([0-9a-zA-Z-._]+)\\/([0-9a-zA-Z-._]+)(?::([0-9a-zA-Z-._]+))?(?:@([0-9a-zA-Z-._]+(?:\\/[0-9a-zA-Z-._]+)?))?$");

type GithubPlugin = {
owner: string;
Expand Down

0 comments on commit 36e1a03

Please sign in to comment.