From 3e84f0e40f604c019920079184dd02a0bf770c9a Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 11 Jan 2021 19:24:11 +0100 Subject: [PATCH] Github repo for fetching project contributers. --- api/github.js | 33 +++++++++++++++++++++++++++++++++ api/router.js | 3 +++ 2 files changed, 36 insertions(+) create mode 100644 api/github.js diff --git a/api/github.js b/api/github.js new file mode 100644 index 0000000..b50ca84 --- /dev/null +++ b/api/github.js @@ -0,0 +1,33 @@ +const fetch = require('node-fetch') + +class Github { + constructor(apiToken) { + this.apiToken = apiToken; + this.hostname = "https://api.github.com" + } + + listRepositoryContributors() { + const headers = { + "Accept": "application/json", + "Authorization": `token ${ this.apiToken }` + }; + + const url = `${ this.hostname }/repos/KevinMidboe/vinlottis/contributors` + return fetch(url, { headers }) + .then(resp => resp.json()) + .then(contributors => + contributors.map(contributor => new Contributor(contributor)) + ); + } +} + +class Contributor { + constructor(contributorObject) { + this.name = contributorObject.login; + this.avatarUrl = contributorObject.avatar_url; + this.profileUrl = contributorObject.html_url; + this.projectContributions = contributorObject.contributions; + } +} + +module.exports = Github; \ No newline at end of file diff --git a/api/router.js b/api/router.js index 4d57057..c3822db 100644 --- a/api/router.js +++ b/api/router.js @@ -16,6 +16,7 @@ const virtualRegistrationApi = require(path.join( )); const lottery = require(path.join(__dirname, "/lottery")); const chatHistoryApi = require(path.join(__dirname, "/chatHistory")); +const githubController = require(path.join(__dirname, "/controllers/githubController")); const router = express.Router(); @@ -63,6 +64,8 @@ router.post('/winner/:id', virtualRegistrationApi.registerWinnerSelection); router.get('/chat/history', chatHistoryApi.getAllHistory) router.delete('/chat/history', mustBeAuthenticated, chatHistoryApi.deleteHistory) +router.get("/project/contributors", githubController.getProjectContributors); + router.post('/login', userApi.login); router.post('/register', mustBeAuthenticated, userApi.register); router.get('/logout', userApi.logout);