Repository Management
Overview
The Repository Management feature in WikiSmith allows users to manage their GitHub repositories effectively. This includes updating repository settings, managing sharing options, and triggering wiki generation. The feature aims to provide a seamless experience for users handling both public and private repositories.
User-facing behavior
- Dashboard Access: Users can access a dashboard displaying their connected repositories, including both public and private ones.
- Repository Settings: Users can update settings such as the tracked branch and auto-update preferences for their repositories.
- Sharing Options: Users can manage sharing settings, including making repositories public or enabling embed options.
- Wiki Generation: Users can trigger wiki generation for selected repositories with a single click.
- Status Tracking: Users can view the status of wiki generation, including states like "not generated," "generating," "ready," or "failed."
Architecture and data flow
- API Endpoints: The feature utilizes RESTful API endpoints to handle repository settings and sharing configurations.
- Settings Endpoint: Updates repository settings through a PATCH request to
/api/repos/[owner]/[repo]/settings. - Sharing Endpoint: Manages sharing settings via GET and PATCH requests to
/api/repos/[owner]/[repo]/sharing.
- Settings Endpoint: Updates repository settings through a PATCH request to
- Session Management: User authentication is managed through sessions, ensuring that only authorized users can access and modify their repositories.
- Data Validation: Input data is validated to ensure correctness before processing, preventing errors and ensuring data integrity.
Key implementation details
- Updating Repository Settings: The settings update process involves validating the input and ensuring that at least one setting is provided. The following code snippet demonstrates the validation logic:
if (!hasTrackedBranch && !hasAutoUpdate) {
return NextResponse.json(
{ error: 'At least one setting must be provided', code: 'NO_SETTINGS_PROVIDED' },
{ status: 400 },
);
}
- Sharing Settings Management: The sharing settings are managed similarly, with a focus on validating the request body to ensure it contains valid data. The following snippet shows how the request body is parsed and validated:
const bodyResult = apiContracts.repos.sharing.update.body.safeParse(rawBody);
if (!bodyResult.success) {
return jsonResponse(
apiContracts.repos.sharing.update.error,
{
error: 'At least one sharing setting must be provided',
code: 'INVALID_BODY',
},
{ status: 400 },
);
}
- Session Handling: The session is checked at the beginning of each request to ensure the user is authenticated. If not, an unauthenticated response is returned:
const session = await getSession();
if (!session) {
return unauthenticated();
}
- Error Handling: Errors are handled gracefully throughout the API, returning meaningful messages based on the type of error encountered. For instance:
if (error instanceof AppError) {
return jsonResponse(
apiContracts.repos.sharing.get.error,
{
error: error.message,
code: error.code,
},
{ status: error.statusCode },
);
}
Key files
apps/web/src/app/api/repos/[owner]/[repo]/settings/route.ts- Handles updates to repository settings, including validation and error handlingapps/web/src/app/api/repos/[owner]/[repo]/settings/route.ts:1-90.apps/web/src/app/api/repos/[owner]/[repo]/sharing/route.ts- Manages sharing settings for repositories, including fetching and updating settingsapps/web/src/app/api/repos/[owner]/[repo]/sharing/route.ts:1-90.apps/web/src/components/dashboard/repository-card-actions.tsx- Provides the UI components for repository actions, including settings management and wiki generation triggersapps/web/src/components/dashboard/repository-card-actions.tsx:1-100.features/repository-management-prd.md- Outlines the product requirements and user stories for the repository management feature, guiding development and implementationfeatures/repository-management-prd.md:1-50.