Skip to content

Commit

Permalink
chore: init repo
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jul 2, 2024
1 parent 5a87d32 commit 579042d
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@

./** @gentlementlegen
9 changes: 3 additions & 6 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ on:
ref:
description: "Ref"

concurrency:
group: ${{ github.workflow }}

jobs:
compute:
name: "plugin name"
runs-on: ubuntu-latest
permissions: write-all
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}

steps:
- uses: actions/checkout@v4
Expand All @@ -39,6 +39,3 @@ jobs:
- name: execute directive
run: npx tsx ./src/main.ts
id: plugin-name
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
- uses: googleapis/release-please-action@v4
with:
release-type: simple
target-branch: main
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `@ubiquibot/plugin-template`
# `@ubiquibot/automated-merging`

## Prerequisites

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "plugin-template",
"name": "@ubiquibot/automated-merging",
"version": "1.0.0",
"description": "Ubiquibot plugin template repository with TypeScript support.",
"author": "Ubiquity DAO",
Expand Down Expand Up @@ -33,6 +33,7 @@
"@octokit/webhooks": "13.2.7",
"@sinclair/typebox": "0.32.33",
"@supabase/supabase-js": "2.43.5",
"@ubiquity-dao/ubiquibot-logger": "1.1.2",
"dotenv": "16.4.5",
"typebox-validators": "0.3.5"
},
Expand Down
10 changes: 10 additions & 0 deletions src/handlers/github-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { parseGitHubUrl } from "../helpers/github-url";
import { Context } from "../types";
import { GitHubTimelineEvent } from "../types/github-types";

export type IssueParams = ReturnType<typeof parseGitHubUrl>;

export async function getAllTimelineEvents({ octokit }: Context, issueParams: IssueParams): Promise<GitHubTimelineEvent[]> {
const options = octokit.issues.listEventsForTimeline.endpoint.merge(issueParams);
return await octokit.paginate(options);
}
11 changes: 11 additions & 0 deletions src/helpers/github-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function parseGitHubUrl(url: string): { owner: string; repo: string; issue_number: number } {
const path = new URL(url).pathname.split("/");
if (path.length !== 5) {
throw new Error(`[parseGitHubUrl] Invalid url: [${url}]`);
}
return {
owner: path[1],
repo: path[2],
issue_number: Number(path[4]),
};
}
21 changes: 3 additions & 18 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Octokit } from "@octokit/rest";
import { createClient } from "@supabase/supabase-js";
import { Logs } from "@ubiquity-dao/ubiquibot-logger";
import { createAdapters } from "./adapters";
import { Env, PluginInputs } from "./types";
import { Context } from "./types";
Expand All @@ -17,29 +18,13 @@ export async function plugin(inputs: PluginInputs, env: Env) {
config: inputs.settings,
octokit,
env,
logger: {
debug(message: unknown, ...optionalParams: unknown[]) {
console.debug(message, ...optionalParams);
},
info(message: unknown, ...optionalParams: unknown[]) {
console.log(message, ...optionalParams);
},
warn(message: unknown, ...optionalParams: unknown[]) {
console.warn(message, ...optionalParams);
},
error(message: unknown, ...optionalParams: unknown[]) {
console.error(message, ...optionalParams);
},
fatal(message: unknown, ...optionalParams: unknown[]) {
console.error(message, ...optionalParams);
},
},
logger: new Logs("debug"),
adapters: {} as ReturnType<typeof createAdapters>,
};

context.adapters = createAdapters(supabase, context);

if (context.eventName === "issue_comment.created") {
if (context.eventName === "pull_request.opened") {
// do something
} else {
context.logger.error(`Unsupported event: ${context.eventName}`);
Expand Down
11 changes: 3 additions & 8 deletions src/types/context.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Octokit } from "@octokit/rest";
import { EmitterWebhookEvent as WebhookEvent, EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks";
import { Logs } from "@ubiquity-dao/ubiquibot-logger";
import { createAdapters } from "../adapters";
import { Env } from "./env";
import { PluginSettings } from "./plugin-inputs";

export type SupportedEventsU = "issue_comment.created"; // Add more events here
export type SupportedEventsU = "pull_request.opened" | "pull_request.reopened" | "pull_request.closed";

export type SupportedEvents = {
[K in SupportedEventsU]: K extends WebhookEventName ? WebhookEvent<K> : never;
Expand All @@ -17,11 +18,5 @@ export interface Context<T extends SupportedEventsU = SupportedEventsU, TU exten
adapters: ReturnType<typeof createAdapters>;
config: PluginSettings;
env: Env;
logger: {
fatal: (message: unknown, ...optionalParams: unknown[]) => void;
error: (message: unknown, ...optionalParams: unknown[]) => void;
warn: (message: unknown, ...optionalParams: unknown[]) => void;
info: (message: unknown, ...optionalParams: unknown[]) => void;
debug: (message: unknown, ...optionalParams: unknown[]) => void;
};
logger: Logs;
}
3 changes: 3 additions & 0 deletions src/types/github-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RestEndpointMethodTypes } from "@octokit/rest";

export type GitHubTimelineEvent = RestEndpointMethodTypes["issues"]["listEventsForTimeline"]["response"]["data"][0];
7 changes: 6 additions & 1 deletion src/types/plugin-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export interface PluginInputs<T extends SupportedEventsU = SupportedEventsU, TU
* The kernel will extract those and pass them to the plugin,
* which are built into the context object from setup().
*/
export const pluginSettingsSchema = T.Object({});
export const pluginSettingsSchema = T.Object({
collaboratorMinimumApprovalsRequired: T.Number({ default: 0 }),
contributorMinimumApprovalsRequired: T.Number({ default: 1 }),
collaboratorMergeTimeout: T.String({ default: "3.5 days" }),
contributorMergeTimeout: T.String({ default: "7 days" }),
});
export const pluginSettingsValidator = new StandardValidator(pluginSettingsSchema);

export type PluginSettings = StaticDecode<typeof pluginSettingsSchema>;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,11 @@
"@typescript-eslint/types" "7.13.1"
eslint-visitor-keys "^3.4.3"

"@ubiquity-dao/ubiquibot-logger@1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@ubiquity-dao/ubiquibot-logger/-/ubiquibot-logger-1.1.2.tgz#d614ebde407517489756b6f2c1c91850c308d8fb"
integrity sha512-91XwVKsG47jNUV0b/usNFZi0lwPnDp+ci2BDhkF5KQkkKU0Lct91EyF9FQmnXmOARb76vbOwbPozDyyq7nLI/w==

JSONStream@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down

0 comments on commit 579042d

Please sign in to comment.