[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 user selection to default to false

+28 -9
+10 -5
Readme.md
··· 30 30 31 31 3. set environment variable `GITHUB_TOKEN` to the personal access token you created in step 1 32 32 33 - 4. get the url of the deployed function and use it in your application, by sending a GET request to the url (if no user is given, returns the data of the user that owns the token): 33 + 4. get the url of the deployed function and use it in your application, by sending a GET request to the url (if no user is given, returns the data of the user that owns the token, user selection by default is disabled, see below how to enable it): 34 34 35 - ``` 36 - https://<your-deployment-url>/api/github-data?user=<github-username> 35 + ```http 36 + // get data of user that owns the token 37 + https://<your-deployment-url>/api/github-data 38 + 39 + // get data of a specific user (disabled by default, see below how to enable it) 40 + https://<your-deployment-url>/api/github-data?user=<username> 37 41 ``` 38 42 39 43 5. simple example using fetch: ··· 47 51 48 52 7. it's recommended to remove data points you don't need, to reduce the size of the response and speed up the request 49 53 50 - 8. if you want to disallow querying users other than yourself, change line 9 in `api/github-data.ts` to: 54 + 8. if you want to allow querying users other than yourself, change line 9 in `api/github-data.ts` to: 51 55 52 56 ```ts 53 - const allowUserSelection = false; 57 + const allowUserSelection = true; 54 58 ``` 55 59 56 60 ## development ··· 87 91 export type GitHubResponse = { 88 92 user: { 89 93 login: string; 94 + avatarUrl: string; 90 95 contributionsCollection: { 91 96 totalCommitContributions: number; 92 97 totalIssueContributions: number;
+18 -4
api/github-data.ts
··· 6 6 } 7 7 8 8 export async function GET(req: NextRequest) { 9 - const allowUserSelection = true; 9 + const allowUserSelection = false; 10 10 11 11 const { searchParams } = new URL(req.url); 12 - const login = searchParams.get('user') ?? 'flo-bit' 12 + const login = searchParams.get('user'); 13 13 14 14 if(login && !allowUserSelection) { 15 15 return new Response('User selection is disabled', { status: 400 }); 16 16 } 17 17 18 - const query = ` 18 + const query = (login && allowUserSelection ? ` 19 19 query($login: String!) { 20 20 user(login: $login) { 21 + ` : ` 22 + query { 23 + viewer { 24 + `) + ` 21 25 login 22 26 avatarUrl 23 27 contributionsCollection { ··· 131 135 if(!data.data) { 132 136 return cors(req, new Response(`Error fetching data from GitHub: ${data.message}`, { status: 500 })); 133 137 } 134 - 138 + 139 + // change from data.data.viewer to data.data.user if necessary 140 + if(data.data.viewer) { 141 + data.data.user = data.data.viewer; 142 + 143 + delete data.data.viewer; 144 + 145 + console.log('Changed viewer to user'); 146 + } 147 + 148 + 135 149 return cors(req, new Response(JSON.stringify(data.data), { 136 150 headers: { 'Content-Type': 'application/json' }, 137 151 }));