Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(release-please): update github-release call to new function #217

Merged
merged 1 commit into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main () {
releaseType,
defaultBranch
})
const releaseCreated = await gr.createRelease()
const releaseCreated = await gr.run()
if (releaseCreated) {
core.setOutput('release_created', true)
for (const key of Object.keys(releaseCreated)) {
Expand Down
179 changes: 107 additions & 72 deletions test/release-please.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,43 @@ describe('release-please-action', () => {
core.getInput = (name) => {
return input[name]
}
const createRelease = sinon.stub().returns({

let GithubReleaseStub = sinon.stub()
const githubReleaseRunStub = sinon.stub().returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
let ReleaseStub = sinon.stub()
action.getGitHubRelease = () => {
class Release {
createRelease () {}
class GithubRelease {
run () {}
}
ReleaseStub = sinon.spy(function () {
const instance = sinon.createStubInstance(Release)
instance.createRelease = createRelease
GithubReleaseStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubRelease)
instance.run = githubReleaseRunStub
return instance
})
return ReleaseStub
return GithubReleaseStub
}

let GithubReleasePRStub = sinon.stub()
const runStub = sinon.stub().returns(25)

const githubReleasePRRunStub = sinon.stub().returns(25)
action.getReleasePR = () => {
class GithubReleasePR {
run () {}
}
GithubReleasePRStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubReleasePR)
instance.run = runStub
instance.run = githubReleasePRRunStub
return instance
})
return GithubReleasePRStub
}

await action.main()

sinon.assert.calledOnce(createRelease)
sinon.assert.calledWith(ReleaseStub, sinon.match.hasOwn('defaultBranch', undefined))
sinon.assert.calledOnce(runStub)
sinon.assert.calledOnce(githubReleaseRunStub)
sinon.assert.calledWith(GithubReleaseStub, sinon.match.hasOwn('defaultBranch', undefined))
sinon.assert.calledOnce(githubReleasePRRunStub)
sinon.assert.calledWith(GithubReleasePRStub, sinon.match.hasOwn('defaultBranch', undefined))
assert.deepStrictEqual(output, {
release_created: true,
Expand All @@ -74,45 +74,45 @@ describe('release-please-action', () => {
core.getInput = (name) => {
return input[name]
}
const createRelease = sinon.stub().returns({

let GithubReleaseStub = sinon.stub()
const githubReleaseRunStub = sinon.stub().returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})

let ReleaseStub = sinon.stub()
action.getGitHubRelease = () => {
class Release {
createRelease () {}
class GithubRelease {
run () {}
}
ReleaseStub = sinon.spy(function () {
const instance = sinon.createStubInstance(Release)
instance.createRelease = createRelease
GithubReleaseStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubRelease)
instance.run = githubReleaseRunStub
return instance
})
return ReleaseStub
return GithubReleaseStub
}

let GithubReleasePRStub = sinon.stub()
const runStub = sinon.stub().returns(25)

const githubReleasePRRunStub = sinon.stub().returns(25)
action.getReleasePR = () => {
class GithubReleasePR {
run () {}
}
GithubReleasePRStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubReleasePR)
instance.run = runStub
instance.run = githubReleasePRRunStub
return instance
})
return GithubReleasePRStub
}

await action.main()

sinon.assert.calledOnce(createRelease)
sinon.assert.calledWith(ReleaseStub, sinon.match.hasOwn('defaultBranch', 'dev'))
sinon.assert.calledOnce(runStub)
sinon.assert.calledOnce(githubReleaseRunStub)
sinon.assert.calledWith(GithubReleaseStub, sinon.match.hasOwn('defaultBranch', 'dev'))
sinon.assert.calledOnce(githubReleasePRRunStub)
sinon.assert.calledWith(GithubReleasePRStub, sinon.match.hasOwn('defaultBranch', 'dev'))

assert.deepStrictEqual(output, {
release_created: true,
upload_url: 'http://example.com',
Expand All @@ -133,34 +133,41 @@ describe('release-please-action', () => {
core.getInput = (name) => {
return input[name]
}
const githubRelease = sinon.stub().returns({

let GithubReleaseStub = sinon.stub()
const githubReleaseRunStub = sinon.stub().returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
action.getGitHubRelease = () => {
class Release {}
Release.prototype.createRelease = githubRelease
return Release
class GithubRelease {
run () {}
}
GithubReleaseStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubRelease)
instance.run = githubReleaseRunStub
return instance
})
return GithubReleaseStub
}

let GithubReleasePRStub = sinon.stub()
const runStub = sinon.stub().returns(25)

const githubReleasePRRunStub = sinon.stub().returns(25)
action.getReleasePR = () => {
class GithubReleasePR {
run () {}
}
GithubReleasePRStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubReleasePR)
instance.run = runStub
instance.run = githubReleasePRRunStub
return instance
})
return GithubReleasePRStub
}

await action.main()
sinon.assert.notCalled(githubRelease)
sinon.assert.calledOnce(runStub)
sinon.assert.notCalled(githubReleaseRunStub)
sinon.assert.calledOnce(githubReleasePRRunStub)
})

it('only creates GitHub release, if command set to github-release', async () => {
Expand All @@ -175,28 +182,41 @@ describe('release-please-action', () => {
core.getInput = (name) => {
return input[name]
}
const githubRelease = sinon.stub().returns({

let GithubReleaseStub = sinon.stub()
const githubReleaseRunStub = sinon.stub().returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
action.getGitHubRelease = () => {
class Release {}
Release.prototype.createRelease = githubRelease
return Release
}
const releasePR = sinon.stub()
action.getReleasePRFactory = () => {
return {
buildStatic: () => {
return {
run: releasePR
}
}
class GithubRelease {
run () {}
}
GithubReleaseStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubRelease)
instance.run = githubReleaseRunStub
return instance
})
return GithubReleaseStub
}

let GithubReleasePRStub = sinon.stub()
const githubReleasePRRunStub = sinon.stub().returns(25)
action.getReleasePR = () => {
class GithubReleasePR {
run () {}
}
GithubReleasePRStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubReleasePR)
instance.run = githubReleasePRRunStub
return instance
})
return GithubReleasePRStub
}

await action.main()
sinon.assert.calledOnce(githubRelease)
sinon.assert.notCalled(releasePR)
sinon.assert.calledOnce(githubReleaseRunStub)
sinon.assert.notCalled(githubReleasePRRunStub)
})

it('sets approprite outputs when GitHub release created', async () => {
Expand All @@ -223,22 +243,35 @@ describe('release-please-action', () => {
core.getInput = (name) => {
return input[name]
}
const githubRelease = sinon.stub().returns(expected)

let GithubReleaseStub = sinon.stub()
const githubReleaseRunStub = sinon.stub().returns(expected)
action.getGitHubRelease = () => {
class Release {}
Release.prototype.createRelease = githubRelease
return Release
}
const releasePR = sinon.stub()
action.getReleasePRFactory = () => {
return {
buildStatic: () => {
return {
run: releasePR
}
}
class GithubRelease {
run () {}
}
GithubReleaseStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubRelease)
instance.run = githubReleaseRunStub
return instance
})
return GithubReleaseStub
}

let GithubReleasePRStub = sinon.stub()
const githubReleasePRRunStub = sinon.stub().returns(25)
action.getReleasePR = () => {
class GithubReleasePR {
run () {}
}
GithubReleasePRStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubReleasePR)
instance.run = githubReleasePRRunStub
return instance
})
return GithubReleasePRStub
}

await action.main()
assert.deepStrictEqual(output, expected)
})
Expand All @@ -255,20 +288,21 @@ describe('release-please-action', () => {
core.getInput = (name) => {
return input[name]
}
let GithubReleasePRStub = sinon.stub()
const runStub = sinon.stub().returns(95)

let GithubReleasePRStub = sinon.stub()
const githubReleasePRRunStub = sinon.stub().returns(95)
action.getReleasePR = () => {
class GithubReleasePR {
run () {}
}
GithubReleasePRStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubReleasePR)
instance.run = runStub
instance.run = githubReleasePRRunStub
return instance
})
return GithubReleasePRStub
}

await action.main()
assert.strictEqual(output.pr, 95)
})
Expand All @@ -285,20 +319,21 @@ describe('release-please-action', () => {
core.getInput = (name) => {
return input[name]
}
let GithubReleasePRStub = sinon.stub()
const runStub = sinon.stub().returns(undefined)

let GithubReleasePRStub = sinon.stub()
const githubReleasePRRunStub = sinon.stub().returns(undefined)
action.getReleasePR = () => {
class GithubReleasePR {
run () {}
}
GithubReleasePRStub = sinon.spy(function () {
const instance = sinon.createStubInstance(GithubReleasePR)
instance.run = runStub
instance.run = githubReleasePRRunStub
return instance
})
return GithubReleasePRStub
}

await action.main()
assert.strictEqual(Object.hasOwnProperty.call(output, 'pr'), false)
})
Expand Down