-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambdaGetGithubData.mjs
More file actions
45 lines (39 loc) · 1.11 KB
/
Copy pathlambdaGetGithubData.mjs
File metadata and controls
45 lines (39 loc) · 1.11 KB
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
import {Octokit} from '@octokit/core';
export const handler = async (event) => {
try {
const apiKey = process.env.GITHUB_API_KEY;
// all other api stuff
const octokit = new Octokit({
auth: apiKey
});
const response = await octokit.request('GET /user/repos', {
visibility: 'public',
headers: {
'User-Agent': 'Personal-WebPage',
'X-GitHub-Api-Version': '2022-11-28'
}
});
// filter to only contain fields I want to use in my app
const filteredData = response.data.map(repo =>({
name: repo.name,
description: repo.description,
url: repo.html_url,
language: repo.language,
pushedAt: repo.pushed_at,
}));
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "OPTIONS, POST, GET",
"Access-Control-Allow-Credentials": true,
},
body: JSON.stringify(filteredData),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({error: error.message}),
};
}
};