Skip to content

Commit

Permalink
Update @octokit/types to 6.1.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Dec 5, 2020
1 parent b3c386a commit a3f33b4
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 162 deletions.
2 changes: 1 addition & 1 deletion __tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const commit = 'deadbeefcafebabedeadbeefcafebabedeadbeef'
describe('relevantReviewsForCommit', () => {
it('returns the latest relevant review for each author who is a member or owner', () => {
expect(
relevantReviewsForCommit(reviews, reviewAuthorAssociations, commit).map(r => [r.user.login, r.state])
relevantReviewsForCommit(reviews, reviewAuthorAssociations, commit).map(r => [r.user?.login, r.state])
).toStrictEqual([
['member1', 'CHANGES_REQUESTED'],
['reitermarkus', 'CHANGES_REQUESTED'],
Expand Down
229 changes: 122 additions & 107 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/licenses.txt

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

89 changes: 50 additions & 39 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0"
"@actions/github": "^4.0.0",
"ts-is-present": "^1.1.5"
},
"devDependencies": {
"@octokit/types": "^5.5.0",
"@octokit/types": "^6.1.1",
"@types/jest": "^26.0.16",
"@types/node": "^14.14.10",
"@typescript-eslint/eslint-plugin": "^4.9.0",
Expand Down
3 changes: 2 additions & 1 deletion src/automerge-action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import { isPresent } from 'ts-is-present'

import { Input } from './input'
import {
Expand Down Expand Up @@ -112,7 +113,7 @@ export class AutomergeAction {
return false
}

const labels = pullRequest.labels.map(({ name }) => name)
const labels = pullRequest.labels.map(({ name }) => name).filter(isPresent)
const doNotMergeLabels = labels.filter(label => this.input.isDoNotMergeLabel(label))
if (doNotMergeLabels.length > 0) {
core.info(
Expand Down
19 changes: 16 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function isApprovedByAllowedAuthor(review: Review, reviewAuthorAssociatio

if (!isAuthorAllowed(review, reviewAuthorAssociations)) {
core.debug(
`Review ${review.id} is approved, however author @${review.user.login} ` +
`Review ${review.id} is approved, however author @${review.user?.login} ` +
`is ${review.author_association} but must be one of the following:` +
`${reviewAuthorAssociations.join(', ')}`
)
Expand All @@ -54,9 +54,22 @@ export function relevantReviewsForCommit(
(isApproved(review) || isChangesRequested(review)) &&
isAuthorAllowed(review, reviewAuthorAssociations)
)
.sort((a, b) => Date.parse(b.submitted_at) - Date.parse(a.submitted_at))
.sort((a, b) => {
const submittedA = a.submitted_at
const submittedB = b.submitted_at

return submittedA && submittedB ? Date.parse(submittedB) - Date.parse(submittedA) : 0
})
.reduce(
(acc: Review[], review) => (acc.some(r => r.user.login === review.user.login) ? acc : [...acc, review]),
(acc: Review[], review) =>
acc.some(r => {
const loginA = r.user?.login
const loginB = review.user?.login

return loginA && loginB && loginA === loginB
})
? acc
: [...acc, review],
[]
)
.reverse()
Expand Down
22 changes: 14 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import * as github from '@actions/github'
import { ActionsListWorkflowRunsResponseData, PullsGetResponseData } from '@octokit/types'
import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types'

export type Octokit = ReturnType<typeof github.getOctokit>
export type PullRequest = PullsGetResponseData
export type WorkflowRun = ActionsListWorkflowRunsResponseData['workflow_runs'][0]
export interface Review {
state: string
author_association?: string

export type WorkflowRun = GetResponseDataTypeFromEndpointMethod<
Octokit['actions']['listWorkflowRuns']
>['workflow_runs'][0]

export type PullRequest = GetResponseDataTypeFromEndpointMethod<Octokit['pulls']['get']>

export type Review = {
id: number
user: { login: string }
user: { login: string } | null
state: string
submitted_at?: string
commit_id: string
submitted_at: string
author_association?: string // https://github.com/octokit/types.ts/issues/221
}

export type MergeMethod = 'merge' | 'squash' | 'rebase' | undefined

0 comments on commit a3f33b4

Please sign in to comment.