Skip to content

Commit

Permalink
Merge pull request #15 from Keyrxng/gg
Browse files Browse the repository at this point in the history
feat: `Hello-world` and template bump
  • Loading branch information
Keyrxng authored Jul 31, 2024
2 parents e72ed38 + 88af8a1 commit 7e699c3
Show file tree
Hide file tree
Showing 23 changed files with 599 additions and 299 deletions.
19 changes: 18 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "./src/adapters/supabase/**/**.ts"],
"useGitignore": true,
"language": "en",
"words": ["Nektos", "dataurl", "devpool", "outdir", "servedir", "Supabase", "SUPABASE", "typebox", "ubiquibot", "Smee"],
"words": [
"Nektos",
"dataurl",
"devpool",
"outdir",
"servedir",
"Supabase",
"SUPABASE",
"typebox",
"ubiquibot",
"Smee",
"typeguards",
"mswjs",
"Typeguards",
"sonarjs",
"knip",
"mischeck"
],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@
- Your plugin config should look similar to this:

```yml
- plugin: <plugin-org/owner>/<plugin-repo-name>:compute.yml@development
name: plugin-name
id: plugin-name-command
description: "Plugin description" # small description of what the plugin does
command: "<regex for command>" # if you are creating a plugin with a slash command
example: "<example usage>" # how to invoke the slash command
with: # these are the example settings, the kernel passes these to the plugin.
disabledCommands: []
timers:
reviewDelayTolerance: 86000
taskStaleTimeoutDuration: 2580000
miscellaneous:
maxConcurrentTasks: 3
labels:
time: []
priority: []
plugins:
- name: hello-world
id: hello-world
uses:
- plugin: http://localhost:4000
with:
# Define configurable items here and the kernel will pass these to the plugin.
configurableResponse: "Hello, is it me you are looking for?"
```
###### At this stage, your plugin will fire on your defined events with the required settings passed in from the kernel. You can now start writing your plugin's logic.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ts-template",
"description": "ts-template for Ubiquibot plugins.",
"ubiquity:listeners": [ "issue_comment.created" ],
"ubiquity:listeners": ["issue_comment.created"],
"commands": {
"command1": {
"ubiquity:example": "/command1 argument",
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@octokit/rest": "20.1.1",
"@octokit/webhooks": "13.2.7",
"@sinclair/typebox": "0.32.33",
"@supabase/supabase-js": "2.43.5",
"@ubiquity-dao/ubiquibot-logger": "^1.3.0",
"dotenv": "16.4.5",
"typebox-validators": "0.3.5"
},
Expand All @@ -45,6 +45,7 @@
"@eslint/js": "9.5.0",
"@jest/globals": "29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "^29.5.12",
"@types/node": "20.14.5",
"cspell": "8.9.0",
"eslint": "9.5.0",
Expand Down Expand Up @@ -79,5 +80,6 @@
"extends": [
"@commitlint/config-conventional"
]
}
},
"packageManager": "[email protected]"
}
17 changes: 0 additions & 17 deletions src/adapters/index.ts

This file was deleted.

49 changes: 0 additions & 49 deletions src/adapters/supabase/helpers/access.ts

This file was deleted.

52 changes: 0 additions & 52 deletions src/adapters/supabase/helpers/label.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/adapters/supabase/helpers/supabase.ts

This file was deleted.

84 changes: 0 additions & 84 deletions src/adapters/supabase/helpers/user.ts

This file was deleted.

59 changes: 59 additions & 0 deletions src/handlers/hello-world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Context } from "../types";

/**
* NOTICE: Remove this file or use it as a template for your own plugins.
*
* This encapsulates the logic for a plugin if the only thing it does is say "Hello, world!".
*
* Try it out by running your local kernel worker and running the `yarn worker` command.
* Comment on an issue in a repository where your GitHub App is installed and see the magic happen!
*
* Logger examples are provided to show how to log different types of data.
*/
export async function helloWorld(context: Context) {
const {
logger,
payload,
octokit,
config: { configurableResponse },
} = context;

const sender = payload.comment.user?.login;
const repo = payload.repository.name;
const issueNumber = payload.issue.number;
const owner = payload.repository.owner.login;
const body = payload.comment.body;

if (!body.match(/hello/i)) {
logger.error(`Invalid use of slash command, use "/hello".`, { body });
return;
}

logger.info("Hello, world!");
logger.debug(`Executing helloWorld:`, { sender, repo, issueNumber, owner });

try {
await octokit.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: configurableResponse,
});
} catch (error) {
/**
* logger.fatal should not be used in 9/10 cases. Use logger.error instead.
*
* Below are examples of passing error objects to the logger, only one is needed.
*/
if (error instanceof Error) {
logger.error(`Error creating comment:`, { error: error, stack: error.stack });
throw error;
} else {
logger.error(`Error creating comment:`, { err: error, error: new Error() });
throw error;
}
}

logger.ok(`Successfully created comment!`);
logger.verbose(`Exiting helloWorld`);
}
Loading

0 comments on commit 7e699c3

Please sign in to comment.