generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from github/update-base-branch-improvements
Update Base Branch Improvements
- Loading branch information
Showing
13 changed files
with
596 additions
and
100 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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import * as core from '@actions/core' | ||
import {isOutdated} from '../../src/functions/outdated-check' | ||
|
||
const debugMock = jest.spyOn(core, 'debug') | ||
|
||
var context | ||
var octokit | ||
var data | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
jest.spyOn(core, 'info').mockImplementation(() => {}) | ||
jest.spyOn(core, 'debug').mockImplementation(() => {}) | ||
jest.spyOn(core, 'warning').mockImplementation(() => {}) | ||
|
||
data = { | ||
outdated_mode: 'strict', | ||
mergeStateStatus: 'CLEAN', | ||
stableBaseBranch: { | ||
data: { | ||
commit: {sha: 'beefdead'}, | ||
name: 'stable-branch' | ||
}, | ||
status: 200 | ||
}, | ||
baseBranch: { | ||
data: { | ||
commit: {sha: 'deadbeef'}, | ||
name: 'test-branch' | ||
}, | ||
status: 200 | ||
}, | ||
pr: { | ||
data: { | ||
head: { | ||
ref: 'test-ref', | ||
sha: 'abc123' | ||
}, | ||
base: { | ||
ref: 'base-ref' | ||
} | ||
}, | ||
status: 200 | ||
} | ||
} | ||
|
||
context = { | ||
repo: { | ||
owner: 'corp', | ||
repo: 'test' | ||
} | ||
} | ||
|
||
octokit = { | ||
rest: { | ||
repos: { | ||
compareCommits: jest | ||
.fn() | ||
.mockReturnValue({data: {behind_by: 0}, status: 200}) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
test('checks if the branch is out-of-date via commit comparison and finds that it is not', async () => { | ||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'test-branch|stable-branch', | ||
outdated: false | ||
}) | ||
}) | ||
|
||
test('checks if the branch is out-of-date via commit comparison and finds that it is not, when the stable branch and base branch are the same (i.e a PR to main)', async () => { | ||
data.baseBranch = data.stableBaseBranch | ||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'stable-branch|stable-branch', | ||
outdated: false | ||
}) | ||
}) | ||
|
||
test('checks if the branch is out-of-date via commit comparison and finds that it is, when the stable branch and base branch are the same (i.e a PR to main)', async () => { | ||
data.baseBranch = data.stableBaseBranch | ||
|
||
octokit.rest.repos.compareCommits = jest | ||
.fn() | ||
.mockReturnValue({data: {behind_by: 1}, status: 200}) | ||
|
||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'stable-branch', | ||
outdated: true | ||
}) | ||
}) | ||
|
||
test('checks if the branch is out-of-date via commit comparison and finds that it is not using outdated_mode pr_base', async () => { | ||
data.outdated_mode = 'pr_base' | ||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'test-branch', | ||
outdated: false | ||
}) | ||
expect(debugMock).toHaveBeenCalledWith( | ||
'checking isOutdated with pr_base mode' | ||
) | ||
}) | ||
|
||
test('checks if the branch is out-of-date via commit comparison and finds that it is not using outdated_mode default_branch', async () => { | ||
data.outdated_mode = 'default_branch' | ||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'stable-branch', | ||
outdated: false | ||
}) | ||
expect(debugMock).toHaveBeenCalledWith( | ||
'checking isOutdated with default_branch mode' | ||
) | ||
}) | ||
|
||
test('checks if the branch is out-of-date via commit comparison and finds that it is', async () => { | ||
octokit.rest.repos.compareCommits = jest | ||
.fn() | ||
.mockReturnValue({data: {behind_by: 1}, status: 200}) | ||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'test-branch', | ||
outdated: true | ||
}) | ||
expect(debugMock).toHaveBeenCalledWith('checking isOutdated with strict mode') | ||
}) | ||
|
||
test('checks if the branch is out-of-date via commit comparison and finds that it is only behind the stable branch', async () => { | ||
octokit.rest.repos.compareCommits = jest | ||
.fn() | ||
.mockImplementationOnce(() => | ||
Promise.resolve({data: {behind_by: 0}, status: 200}) | ||
) | ||
.mockImplementationOnce(() => | ||
Promise.resolve({data: {behind_by: 1}, status: 200}) | ||
) | ||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'stable-branch', | ||
outdated: true | ||
}) | ||
expect(debugMock).toHaveBeenCalledWith('checking isOutdated with strict mode') | ||
}) | ||
|
||
test('checks the mergeStateStatus and finds that it is BEHIND', async () => { | ||
data.mergeStateStatus = 'BEHIND' | ||
expect(await isOutdated(context, octokit, data)).toStrictEqual({ | ||
branch: 'test-branch', | ||
outdated: true | ||
}) | ||
expect(debugMock).toHaveBeenCalledWith( | ||
'mergeStateStatus is BEHIND - exiting isOutdated logic early' | ||
) | ||
}) |
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
Oops, something went wrong.