Skip to content

Commit

Permalink
Merge pull request #28 from unhappychoice/feature/lastBuild
Browse files Browse the repository at this point in the history
👍 Add last option to build command
  • Loading branch information
unhappychoice committed Sep 23, 2019
2 parents a4fa1d6 + b6c32eb commit b63c67e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/circleci/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def builds
desc 'build', 'show build description'
method_option :project, aliases: 'p', type: :string, banner: 'user/project'
method_option :build, aliases: 'n', type: :numeric, banner: 'build-number'
method_option :last, aliases: 'l', type: :boolean, banner: 'get last build'
def build
Command::BuildCommand.run(options)
end
Expand Down
20 changes: 18 additions & 2 deletions lib/circleci/cli/command/build_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ class << self
def run(options)
setup_token
username, reponame = project_name(options).split('/')
number = build_number(options)
build = Response::Build.get(username, reponame, number)
build =
if options.last
get_last_build(username, reponame)
else
get_build(username, reponame, options)
end
say Printer::StepPrinter.new(build.steps).to_s
end

private

def get_build(username, reponame, options)
number = build_number(options)
Response::Build.get(username, reponame, number)
end

def get_last_build(username, reponame)
builds = Response::Build.all(username, reponame)
Response::Build.get(username, reponame, builds.map(&:build_number).max)
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/circler/command/build_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@
it_behaves_like 'a command asks project name'
it_behaves_like 'a command show build information'
end

context 'with last option' do
let(:options) { OpenStruct.new(project: 'unhappychoice/Circler', branch: nil, last: true) }

it_behaves_like 'a command show build information'
end
end

0 comments on commit b63c67e

Please sign in to comment.