@@ -66,6 +66,7 @@ export function getTeamKey(): string | undefined {
6666 */
6767export async function getIssueIdentifier (
6868 providedId ?: string ,
69+ fallbackTeamKey ?: string ,
6970) : Promise < string | undefined > {
7071 if ( providedId ) {
7172 const normalizedIdentifier = normalizeIssueIdentifier ( providedId )
@@ -75,13 +76,13 @@ export async function getIssueIdentifier(
7576 }
7677
7778 if ( providedId && / ^ [ 1 - 9 ] [ 0 - 9 ] * $ / . test ( providedId ) ) {
78- const teamId = getTeamKey ( )
79+ const teamId = fallbackTeamKey || getTeamKey ( )
7980 if ( teamId ) {
8081 return normalizeIssueIdentifier ( `${ teamId } -${ providedId } ` )
8182 }
8283
8384 throw new Error (
84- "an integer id was provided, but no team is set. run `linear configure`" ,
85+ "an integer id was provided, but no team is set. pass --team or run `linear configure`" ,
8586 )
8687 }
8788
@@ -1231,6 +1232,87 @@ export async function getTeamIdByKey(
12311232 return data . teams ?. nodes [ 0 ] ?. id
12321233}
12331234
1235+ // deno-lint-ignore no-explicit-any
1236+ function prosemirrorToMarkdown ( node : any ) : string {
1237+ if ( ! node ) return ""
1238+ if ( typeof node === "string" ) return node
1239+
1240+ if ( node . type === "text" ) {
1241+ let text = node . text || ""
1242+ if ( node . marks ) {
1243+ for ( const mark of node . marks ) {
1244+ if ( mark . type === "strong" ) text = `**${ text } **`
1245+ else if ( mark . type === "em" ) text = `*${ text } *`
1246+ else if ( mark . type === "code" ) text = `\`${ text } \``
1247+ }
1248+ }
1249+ return text
1250+ }
1251+
1252+ if ( Array . isArray ( node . content ) ) {
1253+ const children = node . content . map ( prosemirrorToMarkdown ) . join ( "" )
1254+
1255+ switch ( node . type ) {
1256+ case "doc" :
1257+ return children
1258+ case "paragraph" :
1259+ return children + "\n\n"
1260+ case "heading" : {
1261+ const level = node . attrs ?. level || 1
1262+ return `${ "#" . repeat ( level ) } ${ children } \n\n`
1263+ }
1264+ case "bulletList" :
1265+ // deno-lint-ignore no-explicit-any
1266+ return node . content . map ( ( item : any ) =>
1267+ `- ${ prosemirrorToMarkdown ( item ) . trim ( ) } `
1268+ ) . join ( "\n" ) + "\n\n"
1269+ case "orderedList" :
1270+ // deno-lint-ignore no-explicit-any
1271+ return node . content . map ( ( item : any , i : number ) =>
1272+ `${ i + 1 } . ${ prosemirrorToMarkdown ( item ) . trim ( ) } `
1273+ ) . join ( "\n" ) + "\n\n"
1274+ case "listItem" :
1275+ return children
1276+ case "codeBlock" :
1277+ return `\`\`\`\n${ children } \n\`\`\`\n\n`
1278+ case "blockquote" :
1279+ return `> ${ children } \n\n`
1280+ default :
1281+ return children
1282+ }
1283+ }
1284+
1285+ return ""
1286+ }
1287+
1288+ export async function getDefaultIssueTemplateDescription (
1289+ teamId : string ,
1290+ ) : Promise < string | undefined > {
1291+ const client = getGraphQLClient ( )
1292+ const query = gql ( /* GraphQL */ `
1293+ query GetDefaultIssueTemplate($teamId: String!) {
1294+ team(id: $teamId) {
1295+ defaultTemplateForMembers {
1296+ templateData
1297+ }
1298+ }
1299+ }
1300+ ` )
1301+ const data = await client . request ( query , { teamId } )
1302+ const templateData = data . team ?. defaultTemplateForMembers ?. templateData
1303+ if ( templateData == null ) return undefined
1304+
1305+ // templateData is a JSON object; the descriptionData field contains the ProseMirror document
1306+ const parsed = typeof templateData === "string"
1307+ ? JSON . parse ( templateData )
1308+ : templateData
1309+
1310+ if ( ! parsed ?. descriptionData ) return undefined
1311+
1312+ const description = prosemirrorToMarkdown ( parsed . descriptionData )
1313+ return description . trim ( ) . length > 0 ? description . trim ( ) : undefined
1314+ }
1315+
12341316export async function searchTeamsByKeySubstring (
12351317 keySubstring : string ,
12361318) : Promise < Record < string , string > > {
0 commit comments