Skip to content

Commit

Permalink
Merge pull request #188 from Tyrael/list_jobs_with_details
Browse files Browse the repository at this point in the history
add a list_jobs_with_details() method for listing jobs for a given view with details
  • Loading branch information
arangamani committed Oct 25, 2015
2 parents 542e6e3 + 426e86a commit 230863e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/jenkins_api_client/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ def list_jobs(view_name)
job_names
end

# List jobs in view along with their details
#
# @param [String] view_name
#
# @return [Array<Hash>] the details of jobs in the specified view
#
def list_jobs_with_details(view_name)
@logger.info "Obtaining the jobs present in view '#{view_name}'"
raise "The view #{view_name} doesn't exists on the server"\
unless exists?(view_name)
response_json = @client.api_get_request("/view/#{path_encode view_name}")
response_json["jobs"]
end

# Add a job to view
#
# @param [String] view_name
Expand Down
18 changes: 18 additions & 0 deletions spec/unit_tests/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@
end
end

describe "#list_jobs_with_details" do
it "lists all jobs with details in the given view" do
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("/view/test_view").and_return(
@sample_view_json)
response = @view.list_jobs_with_details("test_view")
response.class.should == Array
response.size.should == @sample_view_json["jobs"].size
end

it "raises an error if called on a non-existent view" do
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
expect(
lambda { @view.list_jobs_with_details("i_am_not_there") }
).to raise_error
end
end

describe "#add_job" do
it "adds the specified job to the specified view" do
@client.should_receive(:api_post_request)
Expand Down

0 comments on commit 230863e

Please sign in to comment.