generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from gentlementlegen/feat/schema-validation
feat: schema validation
- Loading branch information
Showing
7 changed files
with
149 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: "Update Configuration" | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
|
||
jobs: | ||
update: | ||
name: "Update Configuration in manifest.json" | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.10.0" | ||
|
||
- name: Install deps and run configuration update | ||
run: | | ||
yarn install --immutable --immutable-cache --check-cache | ||
yarn tsc --noCheck --project tsconfig.json | ||
- name: Update manifest configuration using GitHub Script | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { pluginSettingsSchema } = require('./src/types'); | ||
const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); | ||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); | ||
const configuration = JSON.stringify(pluginSettingsSchema); | ||
manifest["configuration"] = JSON.parse(configuration); | ||
const updatedManifest = JSON.stringify(manifest, null, 2) | ||
console.log('Updated manifest:', updatedManifest); | ||
fs.writeFileSync(manifestPath, updatedManifest); | ||
- name: Commit and Push generated types | ||
run: | | ||
git config --global user.name 'ubiquity-os[bot]' | ||
git config --global user.email 'ubiquity-os[bot]@users.noreply.github.com' | ||
git add ./manifest.json | ||
if [ -n "$(git diff-index --cached --name-only HEAD)" ]; then | ||
git commit -m "chore: updated generated configuration" || echo "Lint-staged check failed" | ||
git push origin HEAD:${{ github.ref_name }} | ||
else | ||
echo "No changes to commit" | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
@@ -1,5 +1,36 @@ | ||
{ | ||
"name": "Generate vector embeddings", | ||
"description": "Enables the storage, updating, and deletion of issue comment embeddings.", | ||
"ubiquity:listeners": ["issue_comment.created", "issue_comment.edited", "issue_comment.deleted", "issues.opened", "issues.edited", "issues.deleted", "issues.labeled"] | ||
} | ||
"ubiquity:listeners": [ | ||
"issue_comment.created", | ||
"issue_comment.edited", | ||
"issue_comment.deleted", | ||
"issues.opened", | ||
"issues.edited", | ||
"issues.deleted", | ||
"issues.labeled" | ||
], | ||
"configuration": { | ||
"default": {}, | ||
"type": "object", | ||
"properties": { | ||
"matchThreshold": { | ||
"default": 0.95, | ||
"type": "number" | ||
}, | ||
"warningThreshold": { | ||
"default": 0.75, | ||
"type": "number" | ||
}, | ||
"jobMatchingThreshold": { | ||
"default": 0.75, | ||
"type": "number" | ||
} | ||
}, | ||
"required": [ | ||
"matchThreshold", | ||
"warningThreshold", | ||
"jobMatchingThreshold" | ||
] | ||
} | ||
} |
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,36 @@ | ||
import { TransformDecodeCheckError, TransformDecodeError, Value, ValueError } from "@sinclair/typebox/value"; | ||
import { Env, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types"; | ||
|
||
export function validateAndDecodeSchemas(env: Env, rawSettings: object) { | ||
const errors: ValueError[] = []; | ||
const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; | ||
|
||
if (!pluginSettingsValidator.test(settings)) { | ||
for (const error of pluginSettingsValidator.errors(settings)) { | ||
console.error(error); | ||
errors.push(error); | ||
} | ||
} | ||
|
||
if (!envValidator.test(env)) { | ||
for (const error of envValidator.errors(env)) { | ||
console.error(error); | ||
errors.push(error); | ||
} | ||
} | ||
|
||
if (errors.length) { | ||
throw { errors }; | ||
} | ||
|
||
try { | ||
const decodedEnv = Value.Decode(envValidator.schema, env); | ||
const decodedSettings = Value.Decode(pluginSettingsSchema, settings); | ||
return { decodedEnv, decodedSettings }; | ||
} catch (e) { | ||
if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { | ||
throw { errors: [e.error] }; | ||
} | ||
throw e; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -6656,10 +6656,10 @@ [email protected]: | |
"@typescript-eslint/parser" "7.13.1" | ||
"@typescript-eslint/utils" "7.13.1" | ||
|
||
typescript@5.4.5: | ||
version "5.4.5" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" | ||
integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== | ||
typescript@5.6.2: | ||
version "5.6.2" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0" | ||
integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== | ||
|
||
uc.micro@^2.0.0, uc.micro@^2.1.0: | ||
version "2.1.0" | ||
|