From 948e557bdddeb37d2aca4a09a2b842d9a5c83311 Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Sat, 13 Dec 2025 05:35:14 +0530 Subject: [PATCH] Utilize GitHub integration to fetch information about public issues/PRs (#10827) * fix: use github APIs to unfurl public gh issues/prs * fix: revert * fix: multiple gh accounts * fix: use replacements --- app/utils/mention.ts | 10 ++-------- plugins/github/server/github.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/utils/mention.ts b/app/utils/mention.ts index 40de276766..b72e450f35 100644 --- a/app/utils/mention.ts +++ b/app/utils/mention.ts @@ -14,20 +14,14 @@ export const isURLMentionable = ({ integration: Integration; }): boolean => { const { hostname, pathname } = url; - const pathParts = pathname.split("/"); switch (integration.service) { case IntegrationService.GitHub: { - const settings = - integration.settings as IntegrationSettings; - - return ( - hostname === "github.com" && - settings.github?.installation.account.name === pathParts[1] // ensure installed org/account name matches with the provided url. - ); + return hostname === "github.com"; } case IntegrationService.Linear: { + const pathParts = pathname.split("/"); const settings = integration.settings as IntegrationSettings; diff --git a/plugins/github/server/github.ts b/plugins/github/server/github.ts index 213625fc05..e31af7b284 100644 --- a/plugins/github/server/github.ts +++ b/plugins/github/server/github.ts @@ -4,6 +4,7 @@ import { type OAuthWebFlowAuthOptions, type InstallationAuthOptions, } from "@octokit/auth-app"; +import { Sequelize } from "sequelize"; import { Endpoints, OctokitResponse } from "@octokit/types"; import { Octokit } from "octokit"; import pluralize from "pluralize"; @@ -229,11 +230,22 @@ export class GitHub { return; } + // Find integration, prioritizing one where the installation account matches the resource owner const integration = (await Integration.findOne({ where: { service: IntegrationService.GitHub, teamId: actor.teamId, - "settings.github.installation.account.name": resource.owner, + }, + order: [ + [ + Sequelize.literal( + `CASE WHEN "settings"->'github'->'installation'->'account'->>'name' = :owner THEN 0 ELSE 1 END` + ), + "ASC", + ], + ], + replacements: { + owner: resource.owner, }, })) as Integration;