forked from samarth777/BrainSpark
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.ts
54 lines (47 loc) · 1.64 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import express from 'express';
import axios from 'axios';
import { Client } from '@notionhq/client';
import dotenv from 'dotenv';
dotenv.config(); // Load environment variables from .env
// Notion and GitHub setup
const notion = new Client({ auth: process.env.NOTION_TOKEN });
const notionDatabaseId = process.env.NOTION_DATABASE_ID;
const githubApi = axios.create({
baseURL: 'https://api.github.com/',
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
Accept: 'application/vnd.github.v3+json',
},
});
// Initialize Express app
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware for serving static files
app.use(express.static('public'));
// Route to serve the homepage
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
// Route to fetch GitHub issues and sync with Notion
app.get('/sync-github-notion', async (req, res) => {
try {
const issues = await githubApi.get(`/repos/${process.env.GITHUB_REPO_OWNER}/${process.env.GITHUB_REPO_NAME}/issues`);
for (const issue of issues.data) {
await notion.pages.create({
parent: { database_id: notionDatabaseId! },
properties: {
Name: { title: [{ text: { content: issue.title } }] },
Description: { rich_text: [{ text: { content: issue.body || 'No description' } }] },
},
});
}
res.send('GitHub issues synced to Notion successfully!');
} catch (error) {
console.error('Error syncing:', error);
res.status(500).send('Error syncing with Notion');
}
});
// Start server
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});