Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(development): release 1.0.0 #2

Open
wants to merge 16 commits into
base: development
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions src/handlers/run-demo.ts
Original file line number Diff line number Diff line change
@@ -89,39 +89,21 @@ async function createPullRequest({ payload, logger, userOctokit, userName }: Con
}

export async function handleComment(context: Context<"issue_comment.created">) {
const { payload, logger, octokit, userName } = context;
const { payload, logger, octokit, userName, userOctokit } = context;

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

if (body.trim().startsWith("/demo")) {
if (!(await isUserAdmin(context))) {
throw logger.error("You do not have permissions to start the demo. You can set up your own instance at demo.ubq.fi");
}
logger.info("Processing /demo command");
await openIssue(context);
} else if (body.includes("ubiquity-os-command-start-stop") && body.includes(userName)) {
logger.info("Processing ubiquity-os-command-start-stop post comment");
const pr = await createPullRequest(context);
await octokit.rest.pulls.merge({
owner,
repo,
pull_number: pr.data.number,
});
}
}

export async function handleLabel(context: Context<"issues.labeled">) {
const { payload, userOctokit, logger, userName } = context;

const repo = payload.repository.name;
const issueNumber = payload.issue.number;
const owner = payload.repository.owner.login;
const label = payload.label;

if (label?.name.startsWith("Price") && payload.issue.assignee?.login === userName) {
logger.info("Handle pricing label set", { label });
// Create initial comments
await userOctokit.rest.issues.createComment({
owner,
repo,
@@ -134,7 +116,13 @@ export async function handleLabel(context: Context<"issues.labeled">) {
issue_number: issueNumber,
body: "/ask can you help me solving this task by showing the code I should change?",
});
} else {
logger.info("Ignoring label change", { label, assignee: payload.issue.assignee });
} else if (body.includes("ubiquity-os-command-start-stop") && body.includes(userName)) {
logger.info("Processing ubiquity-os-command-start-stop post comment");
const pr = await createPullRequest(context);
await octokit.rest.pulls.merge({
owner,
repo,
pull_number: pr.data.number,
});
}
}
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { customOctokit } from "@ubiquity-os/plugin-sdk/octokit";
import { handleComment, handleLabel } from "./handlers/run-demo";
import { handleComment } from "./handlers/run-demo";
import { Context } from "./types";
import { isCommentEvent, isLabelEvent } from "./types/typeguards";
import { isCommentEvent } from "./types/typeguards";

export async function runPlugin(context: Context) {
const { logger, eventName } = context;
@@ -13,8 +13,6 @@ export async function runPlugin(context: Context) {
context.userName = user.login;
if (isCommentEvent(context)) {
return await handleComment(context);
} else if (isLabelEvent(context)) {
return await handleLabel(context);
}

logger.error(`Unsupported event: ${eventName}`);
2 changes: 1 addition & 1 deletion src/types/context.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { customOctokit } from "@ubiquity-os/plugin-sdk/octokit";
import { Env } from "./env";
import { PluginSettings } from "./plugin-input";

export type SupportedEvents = "issue_comment.created" | "issues.labeled";
export type SupportedEvents = "issue_comment.created";

export type Context<T extends SupportedEvents = SupportedEvents> = PluginContext<PluginSettings, Env, null, T> & {
userOctokit: InstanceType<typeof customOctokit>;
4 changes: 0 additions & 4 deletions src/types/typeguards.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,3 @@ import { Context } from "./context";
export function isCommentEvent(context: Context): context is Context<"issue_comment.created"> {
return context.eventName === "issue_comment.created";
}

export function isLabelEvent(context: Context): context is Context<"issues.labeled"> {
return context.eventName === "issues.labeled";
}