Skip to content

Commit

Permalink
Merge pull request ubiquity-os#61 from gentlementlegen/fix/rename-file
Browse files Browse the repository at this point in the history
fix: renamed file to match kebab-case, updated ESLint rules
  • Loading branch information
gentlementlegen authored Jul 1, 2024
2 parents 3a7066b + 4abf7c5 commit eda131b
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 128 deletions.
53 changes: 0 additions & 53 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- uses: cloudflare/wrangler-action@v3
with:
wranglerVersion: '3.57.0'
wranglerVersion: "3.57.0"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/bun-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Run Bun testing suite
on:
workflow_dispatch:
pull_request:
types: [ opened, synchronize ]
types: [opened, synchronize]

env:
NODE_ENV: "test"
Expand All @@ -18,7 +18,7 @@ jobs:
- uses: oven-sh/setup-bun@v1
- uses: actions/setup-node@v4
with:
node-version: '20.10.0'
node-version: "20.10.0"
- uses: actions/checkout@master
with:
fetch-depth: 0
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/cspell.yml → .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Spell Check
name: Format Checks

on:
push:

jobs:
spellcheck:
name: Check for spelling errors
formatCheck:
name: Check for formatting issues
runs-on: ubuntu-latest

steps:
Expand All @@ -17,8 +17,10 @@ jobs:
with:
node-version: "20.10.0"

- name: Install bun & CSpell
run: npm i -g bun cspell
- uses: oven-sh/setup-bun@v1

- name: Run cspell
run: bun format:cspell
- name: Install deps
run: bun i

- name: Run checks
run: bun format
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# @ubiquity/ubiquibot-kernel

The kernel is designed to:
Expand All @@ -11,11 +10,11 @@ The kernel is designed to:
- **`PRIVATE_KEY`**
Obtain a private key from your GitHub App settings and convert it to the Public-Key Cryptography Standards #8 (PKCS#8) format. Use the following command to perform this conversion and append the result to your `.dev.vars` file:

```sh
echo "PRIVATE_KEY=\"$(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_PRIVATE_KEY.PEM | awk 'BEGIN{ORS="\\n"} 1')\"" >> .dev.vars
```
```sh
echo "PRIVATE_KEY=\"$(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_PRIVATE_KEY.PEM | awk 'BEGIN{ORS="\\n"} 1')\"" >> .dev.vars
```

**Note:** Replace `YOUR_PRIVATE_KEY.PEM` with the path to your actual PEM file when running the command.
**Note:** Replace `YOUR_PRIVATE_KEY.PEM` with the path to your actual PEM file when running the command.

- **`WEBHOOK_SECRET`**
Set this value in both your GitHub App settings and here.
Expand All @@ -26,7 +25,6 @@ The kernel is designed to:
- **`WEBHOOK_PROXY_URL` (only for development)**
Obtain a webhook URL at [smee.io](https://smee.io/) and set it in your GitHub App settings.


### Quick Start

```bash
Expand All @@ -39,31 +37,38 @@ bun dev
### Deploying to Cloudflare Workers

1. **Install Dependencies:**

- Execute `bun install` to install the required dependencies.

2. **Create a Github App:**

- Generate a Github App and configure its settings.
- Navigate to app settings and click `Permissions & events`.
- Ensure the app is subscribed to all events with the following permissions:

Repository permissions:

- Actions: Read & Write
- Contents: Read & Write
- Issues: Read & Write
- Pull Requests: Read & Write

Organization permissions:

- Members: Read only

3. **Cloudflare Account Setup:**

- If not done already, create a Cloudflare account.
- Run `npx wrangler login` to log in.

4. **Create a KV Namespace:**

- Generate a KV namespace using `npx wrangler kv:namespace create PLUGIN_CHAIN_STATE`.
- Copy the generated ID and paste it under `[env.dev]` in `wrangler.toml`.

5. **Manage Secrets:**

- Add (env) secrets using `npx wrangler secret put <KEY> --env dev`.
- For the private key, execute the following (replace `YOUR_PRIVATE_KEY.PEM` with the actual PEM file path):

Expand Down Expand Up @@ -97,7 +102,9 @@ Example usage:
const input: PluginInput = {
stateId: "abc123",
eventName: "issue_comment.created",
eventPayload: { /* ... */ },
eventPayload: {
/* ... */
},
settings: '{ "key": "value" }',
authToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
ref: "refs/heads/main",
Expand Down Expand Up @@ -129,13 +136,16 @@ const output: PluginOutput = {
## Plugin Quick Start
The kernel supports 2 types of plugins:
1. Github actions ([wiki](https://github.com/ubiquity/ubiquibot-kernel/wiki/How-it-works))
2. Cloudflare Workers (which are simple backend servers with a single API route)
How to run a "hello-world" plugin the Cloudflare way:
1. Run `bun dev` to spin up the kernel
2. Run `bun plugin:hello-world` to spin up a local server for the "hello-world" plugin
3. Update the bot's config file in the repository where you use the bot (`OWNER/REPOSITORY/.github/.ubiquibot-config.yml`):
```
plugins:
'issue_comment.created':
Expand All @@ -151,12 +161,14 @@ plugins:
with:
response: world
```
4. Post a `/hello` comment in any issue
5. The bot should respond with the `world` message ([example](https://github.com/rndquu-org/test-repo/issues/54#issuecomment-2149313139))
How it works:
1. When you post the `/hello` command the kernel receives the `issue_comment.created` event
2. The kernel matches the `/hello` command to the plugin that should be executed (i.e. the API method that should be called)
2. The kernel matches the `/hello` command to the plugin that should be executed (i.e. the API method that should be called)
3. The kernel passes github event payload, bot's access token and plugin settings (from `.ubiquibot-config.yml`) to the plugin endpoint
4. The plugin performs all of the required actions and returns the result
Expand Down
Binary file modified bun.lockb
Binary file not shown.
File renamed without changes.
126 changes: 126 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// @ts-check
import tsEslint from "typescript-eslint";
import eslint from "@eslint/js";
import sonarjs from "eslint-plugin-sonarjs";
import checkFile from "eslint-plugin-check-file";

export default tsEslint.config({
plugins: {
"@typescript-eslint": tsEslint.plugin,
"check-file": checkFile,
},
ignores: [".github/knip.ts", "**/.wrangler/**"],
extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended],
languageOptions: {
parser: tsEslint.parser,
parserOptions: {
project: ["./tsconfig.json"],
},
},
rules: {
"check-file/filename-naming-convention": [
"error",
{
"**/*.{js,ts}": "+([-.a-z0-9])",
},
],
"prefer-arrow-callback": [
"warn",
{
allowNamedFunctions: true,
},
],
"func-style": [
"warn",
"declaration",
{
allowArrowFunctions: false,
},
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"constructor-super": "error",
"no-invalid-this": "off",
"@typescript-eslint/no-invalid-this": ["error"],
"no-restricted-syntax": ["error", "ForInStatement"],
"use-isnan": "error",
"no-unneeded-ternary": "error",
"no-nested-ternary": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "after-used",
ignoreRestSiblings: true,
vars: "all",
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
},
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"sonarjs/no-all-duplicated-branches": "error",
"sonarjs/no-collection-size-mischeck": "error",
"sonarjs/no-duplicated-branches": "error",
"sonarjs/no-element-overwrite": "error",
"sonarjs/no-identical-conditions": "error",
"sonarjs/no-identical-expressions": "error",
"@typescript-eslint/naming-convention": [
"error",
{
selector: "interface",
format: ["StrictPascalCase"],
custom: {
regex: "^I[A-Z]",
match: false,
},
},
{
selector: "memberLike",
modifiers: ["private"],
format: ["strictCamelCase"],
leadingUnderscore: "require",
},
{
selector: "typeLike",
format: ["StrictPascalCase"],
},
{
selector: "typeParameter",
format: ["StrictPascalCase"],
prefix: ["T"],
},
{
selector: "variable",
format: ["strictCamelCase", "UPPER_CASE"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "variable",
format: ["strictCamelCase"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "variable",
modifiers: ["destructured"],
format: null,
},
{
selector: "variable",
types: ["boolean"],
format: ["StrictPascalCase"],
prefix: ["is", "should", "has", "can", "did", "will", "does"],
},
{
selector: "variableLike",
format: ["strictCamelCase"],
},
{
selector: ["function", "variable"],
format: ["strictCamelCase"],
},
],
},
});
Loading

0 comments on commit eda131b

Please sign in to comment.