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
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## 1.0.0 (2025-02-16)


### Bug Fixes

* only administrators are able to start a demo ([b7c604f](https://github.com/ubiquity-os/command-demo/commit/b7c604ff326c292cf18a261561c7fda54e03622e))
* the user now has its own octokit instance ([52d7b12](https://github.com/ubiquity-os/command-demo/commit/52d7b125ac892a68d382478387ac14224f55bf82))
56 changes: 16 additions & 40 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"type": "object",
"properties": {}
},
"homepage_url": "https://ubiquity-os-plugin-demo-development.ubiquity.workers.dev"
"homepage_url": "https://ubiquity-os-command-demo-development.ubiquity.workers.dev"
}
56 changes: 13 additions & 43 deletions src/handlers/run-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ async function isUserAdmin({ payload, octokit, logger }: Context) {
}
}

async function setLabels({ payload, octokit }: Context) {
const repo = payload.repository.name;
const issueNumber = payload.issue.number;
const owner = payload.repository.owner.login;
await octokit.rest.issues.removeAllLabels({
owner,
repo,
issue_number: issueNumber,
});
await octokit.rest.issues.addLabels({
owner,
repo,
issue_number: issueNumber,
labels: ["Priority: 1 (Normal)", "Time: <1 Hour"],
});
}

async function openIssue({ octokit, payload }: Context): Promise<void> {
const repo = payload.repository.name;
const issueNumber = payload.issue.number;
Expand Down Expand Up @@ -106,40 +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 are not an organization member thus cannot start a demo.");
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);
await setLabels(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,
Expand All @@ -150,9 +114,15 @@ export async function handleLabel(context: Context<"issues.labeled">) {
owner,
repo,
issue_number: issueNumber,
body: "/ask Can you help me solving this task by showing the code I should change?",
body: "/ask can you help me solving this task by showing the code I should change?",
});
} 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,
});
} else {
logger.info("Ignoring label change", { label, assignee: payload.issue.assignee });
}
}
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;
Expand All @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
4 changes: 0 additions & 4 deletions src/types/typeguards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
4 changes: 2 additions & 2 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "ubiquity-os-plugin-demo"
name = "ubiquity-os-command-demo"
main = "src/worker.ts"
compatibility_date = "2024-09-23"
compatibility_flags = [ "nodejs_compat" ]
Expand All @@ -9,4 +9,4 @@ compatibility_flags = [ "nodejs_compat" ]
enabled = true

[version_metadata]
binding = "CLOUDFLARE_VERSION_METADATA"
binding = "CLOUDFLARE_VERSION_METADATA"