-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
428e369
commit 62f242e
Showing
5 changed files
with
271 additions
and
96 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/canyon-platform/app/api/project/[id]/chart/route.ts
This file contains 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,41 @@ | ||
import prisma from "@/lib/prisma"; | ||
|
||
import { NextRequest } from "next/server"; | ||
import { percent } from "canyon-data"; | ||
|
||
export async function GET(request: NextRequest) { | ||
const { pathname } = request.nextUrl; | ||
const id = pathname.split("/")[3]; | ||
|
||
const coverages = await prisma.coverage | ||
.findMany({ | ||
where: { | ||
projectID: id, | ||
covType: "all", | ||
}, | ||
select: { | ||
sha: true, | ||
projectID: true, | ||
statementsCovered: true, | ||
statementsTotal: true, | ||
updatedAt: true, | ||
branch: true, | ||
}, | ||
orderBy: { | ||
updatedAt: "desc", | ||
}, | ||
}) | ||
.then((r) => { | ||
return r.map((item) => { | ||
return { | ||
sha: item.sha, | ||
projectID: item.projectID, | ||
statements: percent(item.statementsCovered, item.statementsTotal), | ||
branch: item.branch, | ||
lastReportTime: item.updatedAt, | ||
}; | ||
}); | ||
}); | ||
|
||
return Response.json(coverages); | ||
} |
69 changes: 69 additions & 0 deletions
69
packages/canyon-platform/app/api/project/[id]/compartment/route.ts
This file contains 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,69 @@ | ||
import prisma from "@/lib/prisma"; | ||
|
||
import { NextRequest } from "next/server"; | ||
import { percent } from "canyon-data"; | ||
import dayjs from "dayjs"; | ||
|
||
export async function GET(request: NextRequest) { | ||
const { pathname } = request.nextUrl; | ||
|
||
const id = pathname.split("/")[3]; | ||
|
||
const coverages = await prisma.coverage | ||
.findMany({ | ||
where: { | ||
projectID: id, | ||
}, | ||
select: { | ||
sha: true, | ||
projectID: true, | ||
statementsCovered: true, | ||
statementsTotal: true, | ||
updatedAt: true, | ||
branch: true, | ||
covType: true, | ||
}, | ||
orderBy: { | ||
updatedAt: "desc", | ||
}, | ||
}) | ||
.then((r) => { | ||
return r.map((item) => { | ||
return { | ||
sha: item.sha, | ||
projectID: item.projectID, | ||
statements: percent(item.statementsCovered, item.statementsTotal), | ||
branch: item.branch, | ||
lastReportTime: item.updatedAt, | ||
covType: item.covType, | ||
}; | ||
}); | ||
}); | ||
|
||
const maxCoverage = Math.max( | ||
...coverages | ||
.filter((item) => item.covType === "all") | ||
.map((item) => item.statements), | ||
); | ||
const totalTimes = coverages.filter((item) => item.covType === "all").length; | ||
|
||
const latest = coverages.filter((item) => item.covType === "agg")[0]; | ||
return Response.json([ | ||
{ | ||
label: "projects.total_times", | ||
value: String(totalTimes), | ||
}, | ||
{ | ||
label: "projects.max_coverage", | ||
value: maxCoverage + "%", | ||
}, | ||
{ | ||
label: "projects.latest_report_time", | ||
value: dayjs(latest.lastReportTime).format("MM-DD HH:mm"), | ||
}, | ||
{ | ||
label: "projects.latest_report_coverage", | ||
value: latest.statements + "%", | ||
}, | ||
]); | ||
} |
This file contains 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 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,10 +1,4 @@ | ||
// import Image from "next/image"; | ||
import { Button } from "antd"; | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<Button>按我</Button> | ||
</div> | ||
); | ||
import { redirect } from "next/navigation"; | ||
export default function Page() { | ||
redirect("/projects"); | ||
} |
Oops, something went wrong.