[READ-ONLY] Mirror of https://github.com/flo-bit/edge-function-github-contribution. edge-function-github-contribution.vercel.app
0

Configure Feed

Select the types of activity you want to include in your feed.

update

+20 -9
+12 -5
Readme.md
··· 2 2 3 3 vercel edge function that returns some infos of a github account as a json (contributions, repositories, followers, following, issues, prs, status). 4 4 5 - can be called from any frontend application, including static sites. 6 - 7 5 detailed infos: 8 6 9 7 - contributions of the last year total, and split by day ··· 24 22 25 23 1. create a personal access token on github, go to `settings` -> `developer settings` -> `personal access tokens (classic)` -> `generate new token (classic)`, set expiration date to "No expiration" and add the `public_repo` scope. 26 24 25 + 2. if using in browser, set cors options in `github-data.ts:8-10` 26 + 27 + ```ts 28 + // set your domain here 29 + const corsOptions = { 30 + origin: ['https://blento.app', 'https://www.blento.app'], 31 + }; 32 + ``` 33 + 27 34 2. deploy to vercel 28 35 29 36 [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fflo-bit%2Fedge-function-github-contribution&env=GITHUB_TOKEN) ··· 36 43 // get data of user that owns the token 37 44 https://<your-deployment-url>/api/github-data 38 45 39 - // get data of a specific user (disabled by default, see below how to enable it) 46 + // get data of a specific user (to disable see below) 40 47 https://<your-deployment-url>/api/github-data?user=<username> 41 48 ``` 42 49 ··· 51 58 52 59 7. it's recommended to remove data points you don't need, to reduce the size of the response and speed up the request 53 60 54 - 8. if you want to allow querying users other than yourself, change line 9 in `api/github-data.ts` to: 61 + 8. if you dont want to allow querying users other than yourself, change line 9 in `api/github-data.ts` to: 55 62 56 63 ```ts 57 - const allowUserSelection = true; 64 + const allowUserSelection = false; 58 65 ``` 59 66 60 67 ## development
+8 -4
api/github-data.ts
··· 5 5 runtime: 'edge', 6 6 } 7 7 8 + const corsOptions = { 9 + origin: ['https://blento.app', 'https://www.blento.app'], 10 + }; 11 + 8 12 export async function GET(req: NextRequest) { 9 - const allowUserSelection = false; 13 + const allowUserSelection = true; 10 14 11 15 const { searchParams } = new URL(req.url); 12 16 const login = searchParams.get('user'); ··· 127 131 }); 128 132 129 133 if (!response.ok) { 130 - return cors(req, new Response(`Error fetching data from GitHub: ${response.statusText}`, { status: 500 })); 134 + return cors(req, new Response(`Error fetching data from GitHub: ${response.statusText}`, { status: 500 }), corsOptions); 131 135 } 132 136 133 137 const data = await response.json(); 134 138 135 139 if(!data.data) { 136 - return cors(req, new Response(`Error fetching data from GitHub: ${data.message}`, { status: 500 })); 140 + return cors(req, new Response(`Error fetching data from GitHub: ${data.message}`, { status: 500 }), corsOptions); 137 141 } 138 142 139 143 // change from data.data.viewer to data.data.user if necessary ··· 148 152 149 153 return cors(req, new Response(JSON.stringify(data.data), { 150 154 headers: { 'Content-Type': 'application/json' }, 151 - })); 155 + }), corsOptions); 152 156 }