Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/commands/ci/rerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Heroku from '@heroku-cli/schema'
import * as color from '@heroku/heroku-cli-util/color'
import {Args, ux} from '@oclif/core'

import {gitService} from '../../lib/ci/git.js'
import * as Kolkrabbi from '../../lib/ci/interfaces/kolkrabbi.js'
import {getPipeline} from '../../lib/ci/pipelines.js'
import {createSourceBlob} from '../../lib/ci/source.js'
Expand All @@ -25,6 +26,11 @@ export default class CiReRun extends Command {

async run() {
const {args, flags} = await this.parse(CiReRun)

if (!gitService.inGitRepo()) {
this.error('Not in a git repository. ci:rerun must be run from within your app\'s git repo.')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, new user facing text like this and those below should be CX reviewed prior to merge.

}

const pipeline = await getPipeline(flags, this.heroku)

let sourceTestRun: Heroku.TestRun
Expand Down
5 changes: 5 additions & 0 deletions src/commands/ci/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export default class CiRun extends Command {

async run() {
const {flags} = await this.parse(CiRun)

if (!gitService.inGitRepo()) {
this.error('Not in a git repository. ci:run must be run from within your app\'s git repo.')
}

const pipeline = await getPipeline(flags, this.heroku)
const commit = await gitService.readCommit('HEAD')

Expand Down
21 changes: 21 additions & 0 deletions test/unit/commands/ci/rerun.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ describe('ci:rerun', function () {
}
})

describe('when not in a git repository', function () {
let sandbox: ReturnType<typeof createSandbox>

beforeEach(function () {
sandbox = createSandbox()
sandbox.stub(gitService, 'inGitRepo').returns(false as any)
})

afterEach(function () {
sandbox.restore()
})

it('errors with a clear message', async function () {
const {error} = await runCommand(Cmd, ['--pipeline=my-pipeline'])
expect(error).to.exist
expect(error?.message).to.contain('Not in a git repository')
expect(error?.message).to.contain('ci:rerun must be run from within your app\'s git repo')
})
})

describe('when specifying a pipeline', function () {
const pipeline = {id: '14402644-c207-43aa-9bc1-974a34914010', name: 'pipeline'}
const ghRepository = {
Expand Down Expand Up @@ -58,6 +78,7 @@ describe('ci:rerun', function () {
sandbox = createSandbox()

// Stub gitService methods
sandbox.stub(gitService, 'inGitRepo').returns(true)
sandbox.stub(gitService, 'githubRepository').resolves({repo: ghRepository.repo, user: ghRepository.user} as any)
sandbox.stub(gitService, 'createArchive').resolves('new-archive.tgz')

Expand Down
21 changes: 21 additions & 0 deletions test/unit/commands/ci/run.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ describe('ci:run', function () {
}
})

describe('when not in a git repository', function () {
let sandbox: ReturnType<typeof createSandbox>

beforeEach(function () {
sandbox = createSandbox()
sandbox.stub(gitService, 'inGitRepo').returns(false as any)
})

afterEach(function () {
sandbox.restore()
})

it('errors with a clear message', async function () {
const {error} = await runCommand(Cmd, ['--pipeline=my-pipeline'])
expect(error).to.exist
expect(error?.message).to.contain('Not in a git repository')
expect(error?.message).to.contain('ci:run must be run from within your app\'s git repo')
})
})

describe('when specifying a pipeline', function () {
const pipeline = {id: '14402644-c207-43aa-9bc1-974a34914010', name: 'pipeline'}
const ghRepository = {
Expand All @@ -53,6 +73,7 @@ describe('ci:run', function () {
sandbox = createSandbox()

// Stub gitService methods
sandbox.stub(gitService, 'inGitRepo').returns(true)
sandbox.stub(gitService, 'readCommit').resolves({branch: ghRepository.branch, message: `pushed to ${ghRepository.branch}`, ref: ghRepository.ref})
sandbox.stub(gitService, 'githubRepository').resolves({repo: ghRepository.repo, user: ghRepository.user} as any)
sandbox.stub(gitService, 'createArchive').resolves('new-archive.tgz')
Expand Down
Loading