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.
- Loading branch information
1 parent
bb001cf
commit 2dbe73b
Showing
18 changed files
with
1,049 additions
and
294 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 |
---|---|---|
|
@@ -14,4 +14,5 @@ coverage | |
junit.xml | ||
cypress/screenshots | ||
script.ts | ||
.wrangler | ||
.wrangler | ||
test-dashboard.md |
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,45 @@ | ||
import * as github from "@actions/github"; | ||
import { Octokit } from "@octokit/rest"; | ||
import { Value } from "@sinclair/typebox/value"; | ||
import { plugin } from "./plugin"; | ||
import { envSchema, PluginInputs, pluginSettingsSchema, pluginSettingsValidator } from "./types"; | ||
|
||
/** | ||
* How a GitHub action executes the plugin. | ||
*/ | ||
export async function run() { | ||
const payload = github.context.payload.inputs; | ||
|
||
const env = Value.Decode(envSchema, payload.env); | ||
const settings = Value.Decode(pluginSettingsSchema, Value.Default(pluginSettingsSchema, JSON.parse(payload.settings))); | ||
|
||
if (!pluginSettingsValidator.test(settings)) { | ||
throw new Error("Invalid settings provided"); | ||
} | ||
|
||
const inputs: PluginInputs = { | ||
stateId: payload.stateId, | ||
eventName: payload.eventName, | ||
eventPayload: JSON.parse(payload.eventPayload), | ||
settings, | ||
authToken: payload.authToken, | ||
ref: payload.ref, | ||
}; | ||
|
||
await plugin(inputs, env); | ||
|
||
return returnDataToKernel(inputs.authToken, inputs.stateId, {}); | ||
} | ||
|
||
async function returnDataToKernel(repoToken: string, stateId: string, output: object) { | ||
const octokit = new Octokit({ auth: repoToken }); | ||
return octokit.repos.createDispatchEvent({ | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
event_type: "return_data_to_ubiquibot_kernel", | ||
client_payload: { | ||
state_id: stateId, | ||
output: JSON.stringify(output), | ||
}, | ||
}); | ||
} |
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,17 +1,11 @@ | ||
import { SupabaseClient } from "@supabase/supabase-js"; | ||
import { Context } from "../types/context"; | ||
import { Access } from "./supabase/helpers/access"; | ||
import { User } from "./supabase/helpers/user"; | ||
import { Label } from "./supabase/helpers/label"; | ||
import { Super } from "./supabase/helpers/supabase"; | ||
import { DataSource } from "typeorm"; | ||
import { Context } from "../types"; | ||
import { PullRequestAdapter } from "./sqlite/helpers/pull-request-adapter"; | ||
|
||
export function createAdapters(supabaseClient: SupabaseClient, context: Context) { | ||
export function createAdapters(sqlClient: DataSource, context: Context) { | ||
return { | ||
supabase: { | ||
access: new Access(supabaseClient, context), | ||
user: new User(supabaseClient, context), | ||
label: new Label(supabaseClient, context), | ||
super: new Super(supabaseClient, context), | ||
sqlite: { | ||
pullRequest: new PullRequestAdapter(sqlClient, context), | ||
}, | ||
}; | ||
} |
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,15 @@ | ||
import { DataSource } from "typeorm"; | ||
import { PullRequest } from "./entities/pull-request"; | ||
|
||
export async function initializeDataSource(databaseUrl: string) { | ||
const dataSource = new DataSource({ | ||
type: "sqlite", | ||
database: databaseUrl, | ||
synchronize: true, | ||
logging: true, | ||
entities: [PullRequest], | ||
subscribers: [], | ||
migrations: [], | ||
}); | ||
return dataSource.initialize(); | ||
} |
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,10 @@ | ||
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm"; | ||
|
||
@Entity() | ||
export class PullRequest extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ unique: true }) | ||
url: string; | ||
} |
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,9 @@ | ||
import { DataSource } from "typeorm"; | ||
import { Context } from "../../../types"; | ||
import { Super } from "./sqlite"; | ||
|
||
export class PullRequestAdapter extends Super { | ||
constructor(sqlite: DataSource, context: Context) { | ||
super(sqlite, context); | ||
} | ||
} |
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,12 @@ | ||
import { DataSource } from "typeorm"; | ||
import { Context } from "../../../types"; | ||
|
||
export class Super { | ||
protected sqlite: DataSource; | ||
protected context: Context; | ||
|
||
constructor(sqlite: DataSource, context: Context) { | ||
this.sqlite = sqlite; | ||
this.context = context; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.