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

Merge development into main #88

Merged
merged 8 commits into from
Nov 18, 2024
13 changes: 8 additions & 5 deletions src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export async function start(

if (requiredLabelsToStart.length && !requiredLabelsToStart.some((label) => issueLabels.includes(label))) {
// The "Priority" label must reflect a business priority, not a development one.
throw logger.error("This task does not reflect a business priority at the moment and cannot be started. This will be reassessed in the coming weeks.", {
requiredLabelsToStart,
issueLabels,
issue: issue.html_url,
});
throw logger.error(
`This task does not reflect a business priority at the moment. You may start tasks with one of the following labels: ${requiredLabelsToStart.join(", ")}`,
{
requiredLabelsToStart,
issueLabels,
issue: issue.html_url,
}
);
}

if (!sender) {
Expand Down
19 changes: 14 additions & 5 deletions src/handlers/user-start-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ export async function userSelfAssign(context: Context<"issues.assigned">): Promi
const { issue } = payload;
const deadline = getDeadline(issue.labels);

if (!deadline) {
context.logger.debug("Skipping deadline posting message because no deadline has been set.");
// We avoid posting a message if the bot is the actor to avoid double posting
if (!deadline || payload.sender.type === "Bot") {
context.logger.debug("Skipping deadline posting message.", {
senderType: payload.sender.type,
deadline: deadline,
});
return { status: HttpStatusCode.NOT_MODIFIED };
}

Expand Down Expand Up @@ -91,13 +95,18 @@ export async function userPullRequest(context: Context<"pull_request.opened" | "
return { status: HttpStatusCode.NOT_MODIFIED };
}

export async function userUnassigned(context: Context): Promise<Result> {
export async function userUnassigned(context: Context<"issues.unassigned">): Promise<Result> {
if (!("issue" in context.payload)) {
context.logger.debug("Payload does not contain an issue, skipping issues.unassigned event.");
return { status: HttpStatusCode.NOT_MODIFIED };
}
const { payload } = context;
const { issue, sender, repository } = payload;
await closePullRequestForAnIssue(context, issue.number, repository, sender.login);
const { issue, repository, assignee } = payload;
// 'assignee' is the user that actually got un-assigned during this event. Since it can theoretically be null,
// we display an error if none is found in the payload.
if (!assignee) {
throw context.logger.fatal("No assignee found in payload, failed to close pull-requests.");
}
await closePullRequestForAnIssue(context, issue.number, repository, assignee?.login);
return { status: HttpStatusCode.OK, content: "Linked pull-requests closed." };
}
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function startStopTask(inputs: PluginInputs, env: Env) {
case "pull_request.edited":
return await userPullRequest(context as Context<"pull_request.edited">);
case "issues.unassigned":
return await userUnassigned(context);
return await userUnassigned(context as Context<"issues.unassigned">);
default:
context.logger.error(`Unsupported event: ${context.eventName}`);
}
Expand Down
7 changes: 6 additions & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ describe("User start/stop", () => {
context.adapters = createAdapters(getSupabase(), context);

await expect(userStartStop(context)).rejects.toMatchObject({
logMessage: { raw: "This task does not reflect a business priority at the moment and cannot be started. This will be reassessed in the coming weeks." },
logMessage: {
raw: "This task does not reflect a business priority at the moment. You may start tasks with one of the following labels: Priority: 3 (High), Priority: 4 (Urgent), Priority: 5 (Emergency)",
},
});
});
});
Expand Down Expand Up @@ -670,6 +672,9 @@ export function createContext(
action: "created",
installation: { id: 1 } as unknown as Context["payload"]["installation"],
organization: { login: "ubiquity" } as unknown as Context["payload"]["organization"],
assignee: {
...sender,
},
} as Context["payload"],
logger: new Logs("debug"),
config: {
Expand Down
4 changes: 2 additions & 2 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ubiquity-os-command-start-stop"
main = "src/worker.ts"
compatibility_date = "2024-05-23"
node_compat = true
compatibility_date = "2024-09-23"
compatibility_flags = [ "nodejs_compat" ]
[env.dev]
[env.prod]

Expand Down
Loading