-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] get proper required status and output to console
- Loading branch information
1 parent
0b1ec30
commit 194d0e9
Showing
3 changed files
with
121 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
'use strict'; | ||
|
||
const parsePullRequest = require('../utils/parsePullRequest'); | ||
const runQuery = require('./runQuery'); | ||
|
||
module.exports = function filterPullRequest(response, argPr) { | ||
module.exports = async function filterPullRequest(response, params) { | ||
const parsedResponse = parsePullRequest(response); | ||
|
||
return argPr ? parsedResponse.filter((pr) => String(pr.number) === argPr) : parsedResponse; | ||
// If user is admin branchProtectionRule is returned | ||
if (parsedResponse[0]?.baseRef?.branchProtectionRule) { | ||
if (params.pr) { | ||
return parsedResponse.filter((pr) => String(pr.number) === params.pr); | ||
} | ||
return parsedResponse; | ||
} | ||
|
||
// If --pr is not specified run again to get isRequired | ||
const newParsedResponse = await Promise.all(parsedResponse.map(async (PR) => { | ||
const newParams = { ...params, pr: PR.number }; | ||
try { | ||
const newResponse = await runQuery(newParams); | ||
const responseWithRequiredChecks = parsePullRequest(newResponse); | ||
return responseWithRequiredChecks[0]; | ||
} catch (err) { | ||
throw err.message; | ||
} | ||
})); | ||
return newParsedResponse; | ||
}; |