From 0e67823577bb08c2a3dca8082150b662861ba410 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <70131915+Saurabhkmr98@users.noreply.github.com> Date: Tue, 2 Sep 2025 19:20:35 +0530 Subject: [PATCH] [SILO-495] fix: Work item mark as done not marking linked github issue as done (#4073) * fix work item mark done update issue as closed * move wi to open if not in completed state --- .../plane/event-handlers/issue.handler.ts | 12 ++++++++++- .../etl/src/github/etl/transform-to-github.ts | 20 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/silo/src/apps/github/workers/plane/event-handlers/issue.handler.ts b/apps/silo/src/apps/github/workers/plane/event-handlers/issue.handler.ts index df651b14f5..3166b460a1 100644 --- a/apps/silo/src/apps/github/workers/plane/event-handlers/issue.handler.ts +++ b/apps/silo/src/apps/github/workers/plane/event-handlers/issue.handler.ts @@ -132,7 +132,17 @@ const createOrUpdateGitHubIssue = async ( const repo = (entityConnection.entity_slug ?? "").split("/")[1]; const issueImagePrefix = imagePrefix + workspaceConnection.workspace_id + "/" + credentials.user_id; - const transformedGithubIssue = await transformPlaneIssue(issue, issueImagePrefix, labels, owner, repo, userMap); + const transformedGithubIssue = await transformPlaneIssue( + issue, + issueImagePrefix, + labels, + owner, + repo, + userMap, + planeClient, + entityConnection.workspace_slug, + entityConnection.project_id ?? "" + ); // Find the credentials for the user const [userCredential] = await apiClient.workspaceCredential.listWorkspaceCredentials({ diff --git a/packages/etl/src/github/etl/transform-to-github.ts b/packages/etl/src/github/etl/transform-to-github.ts index 825bafc3af..e08c2f5817 100644 --- a/packages/etl/src/github/etl/transform-to-github.ts +++ b/packages/etl/src/github/etl/transform-to-github.ts @@ -1,4 +1,4 @@ -import { ExCycle, ExIssueLabel, ExIssue as PlaneIssue } from "@plane/sdk"; +import { Client, ExCycle, ExIssueLabel, ExIssue as PlaneIssue } from "@plane/sdk"; import { GithubIssue, WebhookGitHubLabel, WebhookGitHubMilestone, WebhookGitHubUser } from "../types"; import { ContentParser } from "../helpers/content-parser"; @@ -8,7 +8,10 @@ export const transformPlaneIssue = async ( labels: ExIssueLabel[], owner: string, repo: string, - userMap: Record + userMap: Record, + planeClient: Client, + workspaceSlug: string, + projectId: string ): Promise> => { const githubIssueNumber = issue.links ?.find((link) => link.name === "Linked GitHub Issue") @@ -38,6 +41,17 @@ export const transformPlaneIssue = async ( // Convert the cleaned HTML to GitHub markdown using our ContentParser const githubBody = ContentParser.toMarkdown(cleanHtml, imgSrcPrefix); + let targetState: string | undefined = undefined; + if (issue.state) { + const states = (await planeClient.state.list(workspaceSlug, projectId)).results; + const issueState = states.find((state) => state.id === issue.state); + if (issueState?.group === "completed") { + targetState = "CLOSED"; + } else { + targetState = "OPEN"; + } + } + return { id: parseInt(issue.external_id || "0"), number: parseInt(githubIssueNumber || "0"), @@ -45,7 +59,7 @@ export const transformPlaneIssue = async ( body: githubBody, owner: owner, repo: repo, - state: issue.state === "Done" ? "CLOSED" : "OPEN", + state: targetState, created_at: issue.created_at, assignees: assignees as string[], labels: ghLabels,