mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
fix: Fallback to any Linear integration (#10458)
* Fallback to any integration * fix: Cannot unfurl Linear links without creator
This commit is contained in:
@@ -13,6 +13,8 @@ import { UnfurlIssueOrPR, UnfurlSignature } from "@server/types";
|
||||
import { LinearUtils } from "../shared/LinearUtils";
|
||||
import env from "./env";
|
||||
import { Minute } from "@shared/utils/time";
|
||||
import { opts } from "@server/utils/i18n";
|
||||
import { t } from "i18next";
|
||||
|
||||
const AccessTokenResponseSchema = z.object({
|
||||
access_token: z.string(),
|
||||
@@ -111,18 +113,25 @@ export class Linear {
|
||||
return;
|
||||
}
|
||||
|
||||
const integration = (await Integration.scope("withAuthentication").findOne({
|
||||
where: {
|
||||
service: IntegrationService.Linear,
|
||||
teamId: actor.teamId,
|
||||
"settings.linear.workspace.key": resource.workspaceKey,
|
||||
},
|
||||
})) as Integration<IntegrationType.Embed>;
|
||||
const integrations = (await Integration.scope("withAuthentication").findAll(
|
||||
{
|
||||
where: {
|
||||
service: IntegrationService.Linear,
|
||||
teamId: actor.teamId,
|
||||
},
|
||||
}
|
||||
)) as Integration<IntegrationType.Embed>[];
|
||||
|
||||
if (!integration) {
|
||||
if (integrations.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prefer integration with matching workspaceKey, otherwise pick the first one
|
||||
const integration =
|
||||
integrations.find(
|
||||
(int) => int.settings.linear?.workspace.key === resource.workspaceKey
|
||||
) ?? integrations[0];
|
||||
|
||||
try {
|
||||
const accessToken = await integration.authentication.refreshTokenIfNeeded(
|
||||
async (refreshToken: string) => Linear.refreshToken(refreshToken),
|
||||
@@ -142,7 +151,7 @@ export class Linear {
|
||||
issue.paginate(issue.labels, {}),
|
||||
]);
|
||||
|
||||
if (!author || !state || !labels) {
|
||||
if (!state || !labels) {
|
||||
return { error: "Failed to fetch auxiliary data from Linear" };
|
||||
}
|
||||
|
||||
@@ -159,8 +168,12 @@ export class Linear {
|
||||
title: issue.title,
|
||||
description: issue.description ?? null,
|
||||
author: {
|
||||
name: author.name,
|
||||
avatarUrl: author.avatarUrl ?? "",
|
||||
name:
|
||||
author?.name ??
|
||||
issue.botActor?.userDisplayName ??
|
||||
issue.botActor?.name ??
|
||||
t("Unknown", opts(actor)),
|
||||
avatarUrl: author?.avatarUrl ?? "",
|
||||
},
|
||||
labels: labels.map((label) => ({
|
||||
name: label.name,
|
||||
|
||||
Reference in New Issue
Block a user