-
Notifications
You must be signed in to change notification settings - Fork 47
Stars and forks widgets #46
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { Summary } from '~/components/shared/types/summary.types'; | ||
|
|
||
| export interface StarsData { | ||
| summary: Summary; | ||
| data: { | ||
| dateFrom: string; | ||
| dateTo: string; | ||
| stars: number; | ||
| }[]; | ||
| } | ||
|
|
||
| export interface ForksData { | ||
| summary: Summary; | ||
| data: { | ||
| dateFrom: string; | ||
| dateTo: string; | ||
| forks: number; | ||
| }[]; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { cumulative, newStars } from '~~/server/mocks/forks.mock'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Frontend expects the data to be in the following format: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * summary: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * current: number; // current value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * previous: number; // previous value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * percentageChange: number; // percentage change (return as actual percentage ex: 2.3 percent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * changeValue: number; // change value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * periodFrom: string; // period from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * periodTo: string; // period to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * dateFrom: string; // ISO 8601 date string - start of the bucket. Based on the interval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * dateTo: string; // ISO 8601 date string - end of the bucket. Based on the interval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * forks: number; // count of forks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * }[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Query params: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - type: 'cumulative' | 'new' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - project: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - repository: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - time-period: string // This is isn't defined yet, but we'll add '90d', '1y', '5y' for now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default defineEventHandler(async (event) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const query = getQuery(event); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (query.type === 'cumulative') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = cumulative; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = newStars; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add query parameter validation and error handling. The endpoint lacks validation for required query parameters and error handling for invalid inputs. Consider adding the following improvements:
export default defineEventHandler(async (event) => {
const query = getQuery(event);
+ const { type, project, repository } = query;
+
+ if (!type || !project || !repository) {
+ throw createError({
+ statusCode: 400,
+ message: 'Missing required query parameters: type, project, repository'
+ });
+ }
+
+ if (type !== 'cumulative' && type !== 'new') {
+ throw createError({
+ statusCode: 400,
+ message: 'Invalid type parameter. Must be either "cumulative" or "new"'
+ });
+ }
+
let data;
- if (query.type === 'cumulative') {
+ if (type === 'cumulative') {
data = cumulative;
} else {
- data = newStars;
+ data = newForks;
}
return data;
});📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { cumulative, newStars } from '~~/server/mocks/stars.mock'; | ||
|
|
||
| /** | ||
| * Frontend expects the data to be in the following format: | ||
| * { | ||
| * summary: { | ||
| * current: number; // current value | ||
| * previous: number; // previous value | ||
| * percentageChange: number; // percentage change (return as actual percentage ex: 2.3 percent) | ||
| * changeValue: number; // change value | ||
| * periodFrom: string; // period from | ||
| * periodTo: string; // period to | ||
| * }, | ||
| * data: { | ||
| * dateFrom: string; // ISO 8601 date string - start of the bucket. Based on the interval | ||
| * dateTo: string; // ISO 8601 date string - end of the bucket. Based on the interval | ||
| * stars: number; // count of stars | ||
| * }[]; | ||
| * } | ||
| */ | ||
| /** | ||
| * Query params: | ||
| * - type: 'cumulative' | 'new' | ||
| * - project: string | ||
| * - repository: string | ||
| * - time-period: string // This is isn't defined yet, but we'll add '90d', '1y', '5y' for now | ||
| */ | ||
| export default defineEventHandler(async (event) => { | ||
| const query = getQuery(event); | ||
| let data; | ||
|
|
||
| if (query.type === 'cumulative') { | ||
| data = cumulative; | ||
| } else { | ||
| data = newStars; | ||
| } | ||
|
|
||
| return data; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect mock data usage in the else block.
The else block is using
newStarsinstead ofnewForks, which appears to be a copy-paste error.📝 Committable suggestion