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

👍 Add last option to build command #28

Merged
merged 1 commit into from
Sep 23, 2019
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
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