Skip to content

Commit b93d543

Browse files
committed
Created functionality for sidebar (diffbar) - Using the logic of the projectlist-sidebar.
Created diff/route.ts to handle GET, run oasdiff and return JSON. Created DiffContent.tsx - fetches the data, compares the branches and show the data. - Finds the fromBranch based of baseRef and toBranch is chosen based id - Handles if same branch is chosen in to and from - non comparable - Components to display data. baseRef to Version if a PR exist for that branch
1 parent dd24356 commit b93d543

File tree

23 files changed

+766
-169
lines changed

23 files changed

+766
-169
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
"@types/node": "^24.0.8",
5858
"@types/nprogress": "^0.2.3",
5959
"@types/pg": "^8.15.2",
60-
"@typescript-eslint/eslint-plugin": "^8.35.1",
6160
"@types/react": "^19.1.9",
6261
"@types/react-dom": "^19.1.7",
62+
"@typescript-eslint/eslint-plugin": "^8.35.1",
6363
"@typescript-eslint/parser": "^8.31.1",
6464
"eslint": "^9.30.0",
6565
"eslint-config-next": "^15.3.4",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { NextRequest, NextResponse } from "next/server"
2+
import { session, userGitHubClient } from "@/composition"
3+
import { makeUnauthenticatedAPIErrorResponse } from "@/common"
4+
import { execSync } from "child_process"
5+
6+
interface GetDiffParams {
7+
owner: string
8+
repository: string
9+
path: [string]
10+
}
11+
12+
export async function GET(req: NextRequest, { params }: { params: Promise<GetDiffParams> }) {
13+
const isAuthenticated = await session.getIsAuthenticated()
14+
if (!isAuthenticated) {
15+
return makeUnauthenticatedAPIErrorResponse()
16+
}
17+
18+
const { path: paramsPath, owner, repository } = await params
19+
const path = paramsPath.join("/")
20+
21+
const fromRef = req.nextUrl.searchParams.get("from")
22+
const toRef = req.nextUrl.searchParams.get("to")
23+
24+
if (!fromRef || !toRef) {
25+
return NextResponse.json({ error: "Missing from/to parameters" }, { status: 400 })
26+
}
27+
28+
const fullRepositoryName = repository + "-openapi"
29+
30+
const spec1 = await userGitHubClient.getRepositoryContent({
31+
repositoryOwner: owner,
32+
repositoryName: fullRepositoryName,
33+
path: path,
34+
ref: fromRef
35+
})
36+
37+
const spec2 = await userGitHubClient.getRepositoryContent({
38+
repositoryOwner: owner,
39+
repositoryName: fullRepositoryName,
40+
path: path,
41+
ref: toRef
42+
})
43+
44+
const result = execSync(`oasdiff changelog --format json "${spec1.downloadURL}" "${spec2.downloadURL}"`, { encoding: 'utf8' })
45+
46+
console.log(result)
47+
48+
49+
const diffData = JSON.parse(result)
50+
51+
return NextResponse.json({
52+
from: fromRef,
53+
to: toRef,
54+
changes: diffData
55+
})
56+
}

src/common/ui/SpacedList.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ const SpacedList = ({
1212
}) => {
1313
return (
1414
<List disablePadding sx={{ ...sx }}>
15-
{React.Children.map(children, (child, idx) => (
16-
<Box sx={{
17-
marginBottom: idx < React.Children.count(children) - 1 ? itemSpacing : 0
18-
}}>
19-
{child}
20-
</Box>
21-
))}
15+
{React.Children.map(children, (child, idx) => {
16+
const baseKey = (child as any)?.key ?? "idx";
17+
const key = `${String(baseKey)}-${idx}`;
18+
return (
19+
<Box
20+
key={key}
21+
sx={{
22+
marginBottom:
23+
idx < React.Children.count(children) - 1 ? itemSpacing : 0,
24+
}}
25+
>
26+
{child}
27+
</Box>
28+
);
29+
})}
2230
</List>
2331
)
2432
}

src/features/projects/data/GitHubProjectDataSource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
140140
name: ref.name,
141141
specifications: specifications,
142142
url: `https://github.com/${ownerName}/${repositoryName}/tree/${ref.name}`,
143-
isDefault: isDefaultRef || false
143+
isDefault: isDefaultRef || false,
144+
baseRef: ref.baseRef,
144145
}
145146
}
146147

0 commit comments

Comments
 (0)