-
Notifications
You must be signed in to change notification settings - Fork 264
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
Changes from 1 commit
0595fe0
960f9d6
2a1d53e
5d616fd
cddeed0
4152827
f9ea2a0
c5f36de
cae714a
7f0714b
157ba58
5c8a473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
const logger = require('../utils/logger') | ||
const fetch = require('../lib/fetch') | ||
// const getGithubId = require('../utils/getGithubId') | ||
const config = require('../config') | ||
const { fetchUser } = require('../models/users') | ||
const { getNames } = require('../lib/getNames') | ||
|
||
/** | ||
* Fetches the pull requests in Real-Dev-Squad by user | ||
* | ||
* @param req {Object} - Express request object | ||
* @param res {Object} - Express response object | ||
*/ | ||
|
||
const pullRequests = async (req, res) => { | ||
try { | ||
const BASE_URL = 'https://api.github.com' | ||
const { user } = await fetchUser(req.params.id) | ||
const url = `${BASE_URL}/search/issues?q=org:Real-Dev-Squad+author:${user.github_id}+type:pr` | ||
const url = `${config.baseUrl}/search/issues?q=org:${config.org}+author:${user.github_id}+type:pr` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use check the rate limit rules and also pass the client secret and client Id. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added authorization via personal access token They have not mentioned how to authorize using client id and client secret |
||
const { data } = await fetch(url) | ||
|
||
const getNames = (arrayOfObjects, key) => { | ||
const names = [] | ||
arrayOfObjects.forEach((object) => { | ||
names.push(object[key]) | ||
}) | ||
return names | ||
} | ||
if (data.total_count) { | ||
const allPRs = [] | ||
data.items.forEach(({ title, html_url: htmlUrl, state, created_at: createdAt, updated_at: updatedAt, draft, labels, assignees }) => { | ||
|
@@ -38,7 +38,7 @@ const pullRequests = async (req, res) => { | |
return res.json('No pull requests found!') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should send an empty array in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with requested changes |
||
} catch (err) { | ||
logger.error(`Error while fetching pull requests: ${err}`) | ||
return res.boom.serverUnavailable('Something went wrong please contact admin') | ||
return res.boom.badImplementation('Something went wrong please contact admin') | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the library
'config'
, do not read from the file. Refer in other files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should solve the failing CI problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool