Skip to content

Commit

Permalink
feat: Added rebase detection
Browse files Browse the repository at this point in the history
  • Loading branch information
samtrion committed Jan 10, 2024
1 parent 39f3791 commit 428f151
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 121 deletions.
117 changes: 116 additions & 1 deletion __tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ const { getInputs, state, validatePullRequest } = require('../src/utils')
// Mock for dependencies (in this case, for the GitHub "core" module)
jest.mock('@actions/core')

const basePullRequest = {
base: {
ref: ''
},
head:{

Check failure on line 11 in __tests__/utils.test.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `·`
ref: ''
}
}

const mockCompare = jest.fn()
mockCompare.mockReturnValue({
data: {
status: 'before',
'behind_by': 0

Check failure on line 20 in __tests__/utils.test.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `'behind_by'` with `behind_by`
}
})

const mockGetPullRequest = jest.fn()
mockGetPullRequest.mockReturnValue({
data: {
mergeable: true,

Check failure on line 27 in __tests__/utils.test.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `,`
}
})
// Mock for the object `github` that is passed to the action
const github = {
rest: {
Expand All @@ -12,7 +35,10 @@ const github = {
},
pulls: {
createReview: jest.fn(),
get: jest.fn()
get: mockGetPullRequest
},
repos: {
compare: mockCompare
}
}
}
Expand Down Expand Up @@ -315,9 +341,94 @@ describe('Tests for `validatePullRequest` function', () => {
'The pull-request is associated with a dependency group but the action is not configured to handle dependency groups.'
)
})

Check failure on line 344 in __tests__/utils.test.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `··`
test('should return `true` after compare commits', async () => {
mockCompare.mockReturnValueOnce({
data: {
status: 'behind',
'behind_by': 2

Check failure on line 349 in __tests__/utils.test.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `'behind_by'` with `behind_by`
}
})

Check failure on line 352 in __tests__/utils.test.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `····`
const pullRequest = {
...basePullRequest,
merged: false,
state: 'open',
draft: false,
user: {
login: 'dependabot[bot]'
},
mergeable: true,
mergeable_state: 'behind'
}

const config = {
inputs: {
approveOnly: false,
handleSubmodule: true,
handleDependencyGroup: true
},
metadata: {}
}

const result = await validatePullRequest(
github,
repository,
pullRequest,
config
)

expect(result.execute).toBe(true)
expect(result.body).toBe('@dependabot rebase')
expect(result.validationState).toBe(state.rebased)
expect(result.validationMessage).toBe('The pull request will be rebased.')
})

test('should return `true` when pull request has a mergeable state of `null`', async () => {
mockGetPullRequest.mockReturnValueOnce({
data: {
mergeable: null,
mergeable_state: 'behind'
}
})

const pullRequest = {
...basePullRequest,
merged: false,
state: 'open',
draft: false,
user: {
login: 'dependabot[bot]'
},
mergeable: null,
mergeable_state: 'behind'
}

const config = {
inputs: {
approveOnly: false,
handleSubmodule: true,
handleDependencyGroup: true
},
metadata: {}
}

const result = await validatePullRequest(
github,
repository,
pullRequest,
config
)

expect(result.execute).toBe(true)
expect(result.body).toBe('@dependabot rebase')
expect(result.validationState).toBe(state.rebased)
expect(result.validationMessage).toBe('The pull request will be rebased.')
}, 15000)

test('should return `true` when pull request has a mergeable state of `behind`', async () => {
const pullRequest = {
...basePullRequest,
merged: false,
state: 'open',
draft: false,
Expand Down Expand Up @@ -354,6 +465,7 @@ describe('Tests for `validatePullRequest` function', () => {
'should return `false` when pull request has a mergeable state of `%s`',
async mergeableState => {
const pullRequest = {
...basePullRequest,
merged: false,
state: 'open',
draft: false,
Expand Down Expand Up @@ -395,6 +507,7 @@ describe('Tests for `validatePullRequest` function', () => {
'should return `false` when pull request has a target `%s` and update type `%s`',
async (target, updateType) => {
const pullRequest = {
...basePullRequest,
merged: false,
state: 'open',
draft: false,
Expand Down Expand Up @@ -448,6 +561,7 @@ describe('Tests for `validatePullRequest` function', () => {
'should return `true` when pull request has a target `%s` and update type `%s` and command `%s`',
async (target, updateType, cmd) => {
const pullRequest = {
...basePullRequest,
merged: false,
state: 'open',
draft: false,
Expand Down Expand Up @@ -486,6 +600,7 @@ describe('Tests for `validatePullRequest` function', () => {

test('should return `true` when pull request has approve-only enabled', async () => {
const pullRequest = {
...basePullRequest,
merged: false,
state: 'open',
draft: false,
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 428f151

Please sign in to comment.