Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added contributors endpoint for github #441

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ NUXT_PUBLIC_SITE_URL=
# these are needed for the google calendar api
GOOGLE_CALENDAR_ID=
GOOGLE_SERVICE_ACCOUNT_CREDENTIALS_JSON=
# needed for the contributors endpoint
GITHUB_APP_KEY=
3 changes: 3 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export default defineNuxtConfig({
googleCalendarId: process.env.GOOGLE_CALENDAR_ID,
serviceAccountCredentialsJSON: process.env.GOOGLE_SERVICE_ACCOUNT_CREDENTIALS_JSON,
},
githubAPI: {
githubAppAPIKey: process.env.GITHUB_APP_KEY,
},
},

// route redirects
Expand Down
42 changes: 42 additions & 0 deletions server/api/contributors.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type {
GitHubUser,
RESTApiResponse,
} from '~/types'

/**
* API endpoint for fetching contributors.
* @example
* // Example usage:
* // GET /api/contributors
*/
export default defineEventHandler(async (event) => {
// we're going to use our key
const { githubAppAPIKey } = useRuntimeConfig(event).githubAPI

// and the api endpoint
const CONTRIBUTORS_ENDPOINT = 'https://api.github.com/repos/devedmonton/DES-Website/collaborators'

// make the request
try {
// await the collaborators endpoint from github using nitros fetch
const data: GitHubUser[] = await $fetch(CONTRIBUTORS_ENDPOINT, {
method: 'GET',
headers: {
Authorization: `Bearer ${githubAppAPIKey}`,
},
})
const response = <RESTApiResponse<GitHubUser[]>>{
statusCode: 200,
message: 'Contributors fetch successfully',
data,
}
return response
}
catch {
throw createError({
statusCode: 400,
statusMessage: 'Bad Request',
message: 'Error while fetching contributors.',
})
}
})
40 changes: 40 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,43 @@ export interface Sponsor {
link?: string
category: 'terabyte' | 'byte' | 'bit'
}

// Interfaces for contributor page.
export interface UserPermissions {
admin: boolean
maintain: boolean
push: boolean
triage: boolean
pull: boolean
}

export interface GitHubUser {
login: string
id: number
node_id: string
avatar_url: string
gravatar_id: string
url: string
html_url: string
followers_url: string
following_url: string
gists_url: string
starred_url: string
subscriptions_url: string
organizations_url: string
repos_url: string
events_url: string
received_events_url: string
type: string
user_view_type: string
site_admin: boolean
permissions: UserPermissions
role_name: string
}

// interface for the rest api response.
export interface RESTApiResponse<T> {
statusCode: number
message: string
data: T
}