-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Github Project Syncronization
- Loading branch information
1 parent
3285edb
commit 2ff089e
Showing
4 changed files
with
122 additions
and
40 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { TeamProjectFirebase } from '@/types/firebase'; | ||
import { Repository } from '@octokit/webhooks-types'; | ||
import * as admin from 'firebase-admin'; | ||
|
||
export const projectSync = async (project: Repository) => { | ||
const db = admin.database(); | ||
const userRef = db.ref( | ||
`data/team-projects/sensors/github/values/${project.id}` | ||
); | ||
|
||
const snapshot = await userRef.once('value'); | ||
const projectData = snapshot.val() as TeamProjectFirebase; | ||
|
||
if (projectData) { | ||
await userRef.update({ | ||
...projectData, | ||
frequency: projectData.frequency + 1, | ||
lastUpdated: Date.now(), | ||
}); | ||
} else { | ||
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(), | ||
}); | ||
} | ||
}; |