Skip to content

Commit

Permalink
feat: add support for PRs with more than 30 reviews (#21)
Browse files Browse the repository at this point in the history
* add copy specifically for avant.

* get ALL reviews before checking.

* fix packaging.
  • Loading branch information
ekimia authored Dec 29, 2023
1 parent 648b988 commit 6ff2b03
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 59 deletions.
37 changes: 28 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 111 additions & 0 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dist/types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/types.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 37 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 44 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ type TeamApprovalStatus = {
actuallCount: number
}

async function getAllReviews(

Check failure on line 20 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Missing return type on function
owner: string,
repo: string,
pullNumber: number,
GITHUB_TOKEN: string
) {
let allReviews: Review[] = []
let page = 1
let perPage = 100

Check failure on line 28 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'perPage' is never reassigned. Use 'const' instead

while (true) {

Check failure on line 30 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Unexpected constant condition
const reviewsResponse = await axios.get(
`https://api.github.com/repos/${owner}/${repo}/pulls/${pullNumber}/reviews`,
{
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${GITHUB_TOKEN}`
},
params: {
page: page,

Check failure on line 39 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
per_page: perPage
}
}
)

allReviews = allReviews.concat(reviewsResponse.data)
if (reviewsResponse.data.length < perPage) {
break
}
page++
}

return allReviews
}

/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
Expand All @@ -31,23 +66,19 @@ export async function run(): Promise<void> {
?.number as number
const GITHUB_TOKEN: string = core.getInput('github-token')

const response = await axios.get(
`https://api.github.com/repos/${owner}/${repo}/pulls/${pullNumber}/reviews`,
{
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${GITHUB_TOKEN}`
}
}
const allReviews = await getAllReviews(
owner,
repo,
pullNumber,
GITHUB_TOKEN
)

if (response.data.length === 0) {
core.setFailed(
'There are no reviews for this pull request yet. Or the url is incorrect.'
)
if (allReviews.length === 0) {
core.setFailed('There are no reviews for this pull request yet.')
return
}

const approvedReviews = response.data.filter(
const approvedReviews = allReviews.filter(
(review: Review) => review.state === 'APPROVED'
)

Expand Down

0 comments on commit 6ff2b03

Please sign in to comment.