-
Notifications
You must be signed in to change notification settings - Fork 2
(SR-91) Fix Linear API error when viewing issue relationships - AI Generated #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dsayerdp
merged 8 commits into
DeskproApps:main
from
dane-h:fix/sr-91-linear-app-errors-linking-stories-claude
Jul 6, 2026
+173
−62
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f8c8c82
(SR-91) Fix Linear API error when viewing issue relationships
dane-h b17e160
Bump version to 1.0.25
dane-h a51e876
(SR-91) Address code review findings on useIssueRelationships
dane-h 1a5be63
(SR-91) Strengthen test assertions per Sourcery review
dane-h 69635c7
(SR-91) Restore inverse-relation discovery using Issue.inverseRelations
dane-h 5b65a1c
Escape dots in proxy URL patterns
dane-h 35bd1f4
(SR-91) Complete inverse-relation plumbing and model 'similar' relations
dane-h 8fb5416
(SR-91) Remove spurious pnpm-workspace.yaml build-script approvals
dane-h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { renderHook } from "@testing-library/react"; | ||
| import { useIssueRelationships } from "../useIssueRelationships"; | ||
| import type { Relation } from "../../services/linear/types"; | ||
|
|
||
| const makeRelation = (overrides: Partial<Relation>): Relation => | ||
| ({ id: "rel-1", type: "related", relatedIssue: { id: "issue-2" }, issue: null, ...overrides } as unknown as Relation); | ||
|
|
||
| describe("useIssueRelationships", () => { | ||
| test("returns forward relations unchanged", () => { | ||
| const forward: Relation[] = [makeRelation({ id: "rel-1", type: "blocks" })]; | ||
| const { result } = renderHook(() => useIssueRelationships(forward, [])); | ||
| expect(result.current.relationships).toHaveLength(1); | ||
| expect(result.current.relationships[0].type).toBe("blocks"); | ||
| }); | ||
|
|
||
| test("maps inverse relation types: blocks→blocked, duplicate→duplicated, related→related", () => { | ||
| const inverseRelations: Relation[] = [ | ||
| makeRelation({ id: "rel-a", type: "blocks", issue: { id: "issue-b", title: "B" } as Relation["issue"] }), | ||
| makeRelation({ id: "rel-b", type: "duplicate", issue: { id: "issue-c", title: "C" } as Relation["issue"] }), | ||
| makeRelation({ id: "rel-c", type: "related", issue: { id: "issue-d", title: "D" } as Relation["issue"] }), | ||
| ]; | ||
| const { result } = renderHook(() => useIssueRelationships([], inverseRelations)); | ||
| const types = result.current.relationships.map(r => r.type); | ||
| expect(types).toEqual(["blocked", "duplicated", "related"]); | ||
| }); | ||
|
|
||
| test("maps the symmetric 'similar' inverse relation to itself", () => { | ||
| const inverseRelations: Relation[] = [ | ||
| makeRelation({ id: "rel-s", type: "similar", issue: { id: "issue-s", title: "S" } as Relation["issue"] }), | ||
| ]; | ||
| const { result } = renderHook(() => useIssueRelationships([], inverseRelations)); | ||
| expect(result.current.relationships[0].type).toBe("similar"); | ||
| }); | ||
|
|
||
| test("uses issue field as relatedIssue for inverse relations", () => { | ||
| const otherIssue = { id: "issue-b", title: "Issue B" }; | ||
| const inv: Relation[] = [ | ||
| makeRelation({ id: "rel-1", type: "blocks", issue: otherIssue as Relation["issue"] }), | ||
| ]; | ||
| const { result } = renderHook(() => useIssueRelationships([], inv)); | ||
| expect(result.current.relationships[0].relatedIssue).toBe(otherIssue); | ||
| }); | ||
|
|
||
| test("deduplicates when a relation appears in both forward and inverse", () => { | ||
| const forward: Relation[] = [makeRelation({ id: "rel-shared", type: "related" })]; | ||
| const inverse: Relation[] = [makeRelation({ id: "rel-shared", type: "related" })]; | ||
| const { result } = renderHook(() => useIssueRelationships(forward, inverse)); | ||
| expect(result.current.relationships).toHaveLength(1); | ||
| }); | ||
|
|
||
| test("merges forward and inverse relations", () => { | ||
| const forward: Relation[] = [makeRelation({ id: "rel-1", type: "blocks" })]; | ||
| const inverse: Relation[] = [makeRelation({ id: "rel-2", type: "related" })]; | ||
| const { result } = renderHook(() => useIssueRelationships(forward, inverse)); | ||
| expect(result.current.relationships).toHaveLength(2); | ||
| }); | ||
|
|
||
| test("handles empty arrays gracefully", () => { | ||
| const { result } = renderHook(() => useIssueRelationships([], [])); | ||
| expect(result.current.relationships).toEqual([]); | ||
| expect(result.current.error).toBeNull(); | ||
| }); | ||
|
|
||
| test("handles undefined arguments gracefully", () => { | ||
| const { result } = renderHook(() => | ||
| useIssueRelationships(undefined as unknown as Relation[], undefined as unknown as Relation[]) | ||
| ); | ||
| expect(result.current.relationships).toEqual([]); | ||
| }); | ||
|
|
||
| test("relationships array is stable across rerenders when inputs are unchanged", () => { | ||
| const forward: Relation[] = [makeRelation({ id: "rel-1", type: "blocks" })]; | ||
| const inverse: Relation[] = []; | ||
| const { result, rerender } = renderHook( | ||
| ({ f, i }) => useIssueRelationships(f, i), | ||
| { initialProps: { f: forward, i: inverse } } | ||
| ); | ||
| const firstRelationships = result.current.relationships; | ||
| rerender({ f: forward, i: inverse }); | ||
| expect(result.current.relationships).toBe(firstRelationships); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,33 @@ | ||
| import { useState } from 'react'; | ||
| import { useDeskproAppClient, useInitialisedDeskproAppClient } from '@deskpro/app-sdk'; | ||
| import { getIssuesService } from '../services/linear'; | ||
| import { Issue, Relation } from '../services/linear/types'; | ||
| import { useMemo } from 'react'; | ||
| import { Relation } from '../services/linear/types'; | ||
|
|
||
| export function useIssueRelationships(originalRelationships: Relation[], issueID: string) { | ||
| const { client } = useDeskproAppClient(); | ||
| const [relationships, setRelationships] = useState<Relation[]>(originalRelationships); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const INVERSE_TYPE: Record<string, string> = { | ||
| blocks: 'blocked', | ||
| duplicate: 'duplicated', | ||
| related: 'related', | ||
| similar: 'similar', | ||
| }; | ||
|
|
||
| useInitialisedDeskproAppClient(client => { | ||
| getIssuesService(client, {}) | ||
| .then((issues: Issue[]) => { | ||
| const relatedIssues = issues | ||
| .filter(issue => issue.relations.some(relation => relation.type === 'related' && relation.relatedIssue.id === issueID)) | ||
| .map(relatedIssue => ({ | ||
| id: relatedIssue.id, | ||
| type: 'related', | ||
| relatedIssue: relatedIssue | ||
| })); | ||
| const blockedIssues = issues | ||
| .filter(issue => issue.relations.some(relation => relation.type === 'blocks' && relation.relatedIssue.id === issueID)) | ||
| .map(blockingIssue => ({ | ||
| id: blockingIssue.id, | ||
| type: 'blocked', | ||
| relatedIssue: blockingIssue | ||
| })); | ||
| const duplicatedIssues = issues | ||
| .filter(issue => issue.relations.some(relation => relation.type === 'duplicate' && relation.relatedIssue.id === issueID)) | ||
| .map(duplicateIssue => ({ | ||
| id: duplicateIssue.id, | ||
| type: 'duplicated', | ||
| relatedIssue: duplicateIssue | ||
| })); | ||
| const allRelationships = [ | ||
| ...originalRelationships, | ||
| ...relatedIssues, | ||
| ...blockedIssues, | ||
| ...duplicatedIssues | ||
| ]; | ||
| const uniqueRelationships = Array.from( | ||
| new Map( | ||
| allRelationships.map(relationship => [relationship.id, relationship] as [string, Relation]) | ||
| ).values() | ||
| ); | ||
| export function useIssueRelationships( | ||
| relations: Relation[] = [], | ||
| inverseRelations: Relation[] = [], | ||
| ) { | ||
| const relationships = useMemo(() => { | ||
| const inverseMapped = inverseRelations.map(rel => ({ | ||
| ...rel, | ||
| type: INVERSE_TYPE[rel.type] ?? rel.type, | ||
| relatedIssue: rel.issue, | ||
| })); | ||
|
|
||
| setRelationships(uniqueRelationships); | ||
| }) | ||
| .catch(error => { | ||
| setError(`error getting relationships: ${error.message}`); | ||
| }); | ||
| }, [client, issueID, originalRelationships]); | ||
| const all = [...relations, ...inverseMapped]; | ||
| const seen = new Set<string>(); | ||
| return all.filter(r => { | ||
| const key = r.id ?? (r.relatedIssue as { id?: string })?.id; | ||
|
dane-h marked this conversation as resolved.
|
||
| if (!key || seen.has(key)) return false; | ||
| seen.add(key); | ||
| return true; | ||
| }); | ||
| }, [relations, inverseRelations]); | ||
|
|
||
| return { relationships, error }; | ||
| }; | ||
| return { relationships, error: null }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.