generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: help is displayed on /help command
- Loading branch information
1 parent
42a6e27
commit 7033aac
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { GitHubContext } from "../github-context"; | ||
import { getConfig } from "../utils/config"; | ||
|
||
export default async function issueCommentCreated(context: GitHubContext<"issue_comment.created">) { | ||
const body = context.payload.comment.body.trim(); | ||
if (/^\/help$/.test(body)) { | ||
const comments = ["---", "| name | description | command | example |", "---"]; | ||
console.log(JSON.stringify(context, null, 2)); | ||
const configuration = await getConfig(context); | ||
for (const pluginArray of Object.values(configuration.plugins)) { | ||
for (const plugin of pluginArray) { | ||
comments.push(`| ${plugin.name} | ${plugin.description} | ${plugin.command} | ${plugin.example}`); | ||
} | ||
} | ||
await context.octokit.issues.createComment({ | ||
body: comments.join("\n"), | ||
issue_number: 0, | ||
owner: "", | ||
repo: "", | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { afterAll, afterEach, beforeAll, describe, it, mock } from "bun:test"; | ||
import { config } from "dotenv"; | ||
import { GitHubContext } from "../src/github/github-context"; | ||
import { GitHubEventHandler } from "../src/github/github-event-handler"; | ||
import issueCommentCreated from "../src/github/handlers/issue-comment-created"; | ||
import { server } from "./__mocks__/node"; | ||
import { WebhooksMocked } from "./__mocks__/webhooks"; | ||
|
||
void mock.module("@octokit/webhooks", () => ({ | ||
Webhooks: WebhooksMocked, | ||
})); | ||
|
||
config({ path: ".dev.vars" }); | ||
|
||
beforeAll(() => { | ||
server.listen(); | ||
}); | ||
afterEach(() => { | ||
server.resetHandlers(); | ||
}); | ||
afterAll(() => { | ||
server.close(); | ||
}); | ||
|
||
describe("Event related tests", () => { | ||
it("Should post the help menu when /help command is invoked", async () => { | ||
await issueCommentCreated({ | ||
id: "", | ||
key: "issue_comment.created", | ||
octokit: { | ||
rest: { | ||
repos: { | ||
getContent() { | ||
return { data: null }; | ||
}, | ||
}, | ||
}, | ||
}, | ||
eventHandler: {} as GitHubEventHandler, | ||
payload: { | ||
repository: { | ||
owner: { login: "ubiquity" }, | ||
name: "ubiquibot-kernel", | ||
}, | ||
comment: { | ||
body: "/help", | ||
}, | ||
} as unknown as GitHubContext<"issue_comment.created">["payload"], | ||
} as unknown as GitHubContext); | ||
}); | ||
}); |