diff --git a/src/handlers/shared/start.ts b/src/handlers/shared/start.ts index f8629c0..4159c66 100644 --- a/src/handlers/shared/start.ts +++ b/src/handlers/shared/start.ts @@ -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) { diff --git a/src/handlers/user-start-stop.ts b/src/handlers/user-start-stop.ts index 28567b8..a50d192 100644 --- a/src/handlers/user-start-stop.ts +++ b/src/handlers/user-start-stop.ts @@ -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 }; } @@ -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 { +export async function userUnassigned(context: Context<"issues.unassigned">): Promise { 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." }; } diff --git a/src/plugin.ts b/src/plugin.ts index 2ca86e6..6a24644 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -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}`); } diff --git a/tests/main.test.ts b/tests/main.test.ts index 25451d2..6eb001b 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -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)", + }, }); }); }); @@ -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: { diff --git a/wrangler.toml b/wrangler.toml index ef7f8cd..b81ff79 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -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]