Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/api/github/events/projects/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { initializeFirebase } from '@/server/firebase/server';
import { projectSync } from '@/server/github/syncs';
import {
projectSync,
validateGithubProjectInputs,
} from '@/server/github/syncs';
import { verifyGitHubRequest } from '@/server/security';
import { createError } from '@/utils/error-handling';
import {
Expand Down Expand Up @@ -36,6 +39,7 @@ export const POST = async (req: NextRequest) => {
initializeFirebase();

if (event !== 'ping' && 'repository' in body) {
validateGithubProjectInputs(body.repository as Repository);
await projectSync(body.repository as Repository);
}

Expand Down
13 changes: 11 additions & 2 deletions server/github/syncs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { TeamProjectFirebase } from '@/types/firebase';
import { createError } from '@/utils/error-handling';
import { Repository } from '@octokit/webhooks-types';
import * as admin from 'firebase-admin';

export const validateGithubProjectInputs = (project: Repository) => {
if (!project.name) {
throw createError({
title: 'Invalid Slack event',
message: 'Event user or channel is invalid',
cause: 'Slack',
});
}
};

export const projectSync = async (project: Repository) => {
const db = admin.database();
const userRef = db.ref(
Expand All @@ -21,8 +32,6 @@ export const projectSync = async (project: Repository) => {
await userRef.set({
title: project.name,
logo: `https://github.com/${project.owner.id}/${project.id}/pinned-icon.svg`,
defaulBranch: project.default_branch,
masterBranch: project.master_branch,
frequency: 1,
lastUpdated: Date.now(),
});
Expand Down
1 change: 0 additions & 1 deletion server/slack/syncs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const validateMessageSlackEvent = (event: MessageEvent) => {
) ||
typeof event.channel !== 'string'
) {
console.log(event);
throw createError({
title: 'Invalid Slack event',
message: 'Event user or channel is invalid',
Expand Down