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

Add pullrequests/:id route to fetch PRs of a given id of user using GitHub API #90

Merged
merged 12 commits into from
Dec 3, 2020
Merged
Prev Previous commit
Next Next commit
file linking fixed
  • Loading branch information
swarajpure committed Nov 29, 2020
commit 41528278da9a2a72d018042ab2893d29400c018a
2 changes: 1 addition & 1 deletion controllers/pullRequestsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { fetchUser } = require('../models/users')
const getPullRequests = async (req, res) => {
try {
const { user } = await fetchUser(req.params.id)
const url = `${config.baseUrl}/search/issues?q=org:${config.org}+author:${user.github_id}+type:pr`
const url = `${config.githubApi.baseUrl}/search/issues?q=org:${config.githubApi.org}+author:${user.github_id}+type:pr`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As used elsewhere, use config.get('')

const { data } = await githubService.fetch(url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the fetch function moved to githubService?
As per we discussed, we were to move it to /utils directory.

Also, the API call should be made from githubService file as per mentioned in the comment: #90 (comment)

The controller should handle any response modifications and error handling.


if (data.total_count) {
Expand Down
4 changes: 2 additions & 2 deletions routes/pullrequests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express')
const router = express.Router()
const pullRequestController = require('../controllers/pullRequestsController.js')
const pullRequestController = require('../controllers/pullRequestsController')

/**
* @swagger
Expand All @@ -24,6 +24,6 @@ const pullRequestController = require('../controllers/pullRequestsController.js'
* $ref: '#/components/schemas/errors/badImplementation'
*/

router.get('/:id', pullRequestController.pullRequests)
router.get('/:id', pullRequestController.getPullRequests)

module.exports = router
2 changes: 1 addition & 1 deletion services/githubService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const axios = require('axios')
const logger = require('./logger')
const logger = require('../utils/logger')

/**
* Used for network calls
Expand Down