jenkins2-api 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e066522b8efd20bd5b1f6a70d0d9b9f3e2ac48c4
4
- data.tar.gz: 2481dbf92e587438d66f036210234966d4969c13
3
+ metadata.gz: cf08bef0ebc99c4ee387ccd5c44140e0e88502ec
4
+ data.tar.gz: c6175c21f3bc45ef9ed6521cd234ba3770c094f1
5
5
  SHA512:
6
- metadata.gz: 74638d02bab0f644794e90004860ec502e40050dbd81af413d9642b0e9b052f14bdbfb45ee0eb161f5a56ef2322803c51611bc7013c52e748fabf4c3f8999b2d
7
- data.tar.gz: 05afbcf3189101deb7922d252d6113a2a13aecba2ebe097faad651b4c1b2418cbb725df16d3b55454713c2634eaec296e812a43221be3f4da205f4eb9e195f98
6
+ metadata.gz: d902bef434ed9fbff993448d4b06c6e3f30f6c89bcbc9677d38f95c32943f4530c45b5c24e987945eb584eeede6f905f856e0ccd81737412436fd8cd87c59edb
7
+ data.tar.gz: c8d76aa5459101bc30c9082d9b05f607d6ed6c3050034dcd5c5d72ea001386f5d9144799a6f6f854b8af9ce6a21f2df7ae394ab700fa38f84432eb67b644c152
data/lib/endpoints/job.rb CHANGED
@@ -19,6 +19,8 @@ module Jenkins2API
19
19
  def builds(name)
20
20
  @client.api_request(:get, "/job/#{name}")['builds']
21
21
  end
22
+
23
+ alias_method :get_builds, :builds
22
24
  end
23
25
  end
24
26
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Jenkins2API
2
2
  # Current version to publish
3
3
  # Gemspec also uses this constant
4
- VERSION = '1.0.4'.freeze
4
+ VERSION = '1.0.5'.freeze
5
5
  end
@@ -0,0 +1,32 @@
1
+ require 'jenkins2-api'
2
+ require 'net/http'
3
+
4
+ RSpec.describe Jenkins2API::Endpoint::Job, '#latest' do
5
+ context 'get the latest build for a job' do
6
+ it 'returns with the build' do
7
+ build = @client.build.latest('sample-job-pipeline')
8
+
9
+ expect(build['id']).to eq('144')
10
+ expect(build['displayName']).to eq('#144')
11
+ end
12
+ end
13
+ end
14
+
15
+ RSpec.describe Jenkins2API::Endpoint::Job, '#get' do
16
+ context 'get a specific build for a job' do
17
+ it 'returns with the build' do
18
+ build = @client.build.get('sample-job-pipeline', 144)
19
+
20
+ expect(build['id']).to eq('144')
21
+ expect(build['displayName']).to eq('#144')
22
+ end
23
+ end
24
+
25
+ context 'get an invalid build for a job' do
26
+ it 'returns with the build' do
27
+ expect do
28
+ @client.build.get('sample-job-pipeline', 135)
29
+ end.to raise_error(Net::HTTPServerException, /Not Found/)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'jenkins2-api'
2
+
3
+ RSpec.describe Jenkins2API::Client, '#initialize' do
4
+ context 'connect without credentials' do
5
+ it 'throws an error' do
6
+ expect do
7
+ Jenkins2API::Client.new
8
+ end.to raise_error(ArgumentError)
9
+ end
10
+ end
11
+
12
+ context 'connect with credentials' do
13
+ it 'does not throw an error' do
14
+ expect do
15
+ Jenkins2API::Client.new(
16
+ username: 'myuser',
17
+ password: 'mytoken'
18
+ )
19
+ end.not_to raise_error
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'jenkins2-api'
2
+
3
+ RSpec.describe Jenkins2API::Endpoint::Job, '#list' do
4
+ context 'get the list of available jobs' do
5
+ it 'returns an array of two jobs' do
6
+ jobs = @client.job.list
7
+ expect(jobs.length).to eq(2)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ require 'webmock/rspec'
2
+ require 'support/fake_jenkins.rb'
3
+ require 'jenkins2-api'
4
+
5
+ WebMock.disable_net_connect!(allow_localhost: true)
6
+
7
+ def create_new_client
8
+ Jenkins2API::Client.new(
9
+ server: 'http://example.jenkins2.com',
10
+ username: 'myuser',
11
+ password: 'mytoken'
12
+ )
13
+ end
14
+
15
+ RSpec.configure do |config|
16
+ config.expect_with :rspec do |expectations|
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ config.mock_with :rspec do |mocks|
21
+ mocks.verify_partial_doubles = true
22
+ end
23
+
24
+ config.before(:each) do
25
+ @client = create_new_client
26
+ stub_request(:any, /example.jenkins2.com/).to_rack(FakeJenkins)
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ require 'sinatra/base'
2
+
3
+ # Fake Jenkins server for rspec
4
+ class FakeJenkins < Sinatra::Base
5
+ get '/api/json' do
6
+ json_response 200, 'job_list.json'
7
+ end
8
+
9
+ get '/job/sample-job-pipeline/144/api/json' do
10
+ json_response 200, 'latest_build.json'
11
+ end
12
+
13
+ get '/job/sample-job-pipeline/lastBuild/api/json' do
14
+ json_response 200, 'latest_build.json'
15
+ end
16
+
17
+ def json_response(response_code, file_name)
18
+ content_type :json
19
+ status response_code
20
+ File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ {
2
+ "_class" : "hudson.model.Hudson",
3
+ "assignedLabels" : [{}],
4
+ "mode" : "NORMAL",
5
+ "nodeDescription" : "the master Jenkins node",
6
+ "nodeName" : "",
7
+ "numExecutors" : 0,
8
+ "description" : null,
9
+ "jobs": [
10
+ {
11
+ "_class" : "hudson.model.FreeStyleProject",
12
+ "name" : "sample-job-freestyle",
13
+ "url" : "http://example.jenkins2.com/job/sample-job-freestyle/",
14
+ "color" : "red"
15
+ },
16
+ {
17
+ "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowJob",
18
+ "name" : "sample-job-pipeline",
19
+ "url" : "http://example.jenkins2.com/job/sample-job-pipeline/",
20
+ "color" : "blue"
21
+ }
22
+ ],
23
+ "overallLoad" : { },
24
+ "primaryView" : {
25
+ "_class" : "hudson.model.AllView",
26
+ "name" : "All",
27
+ "url" : "http://example.jenkins2.com/"
28
+ },
29
+ "quietingDown" : false,
30
+ "slaveAgentPort" : 0,
31
+ "unlabeledLoad" : {
32
+ "_class" : "jenkins.model.UnlabeledLoadStatistics"
33
+ },
34
+ "useCrumbs" : false,
35
+ "useSecurity" : true,
36
+ "views" : [
37
+ {
38
+ "_class" : "hudson.model.AllView",
39
+ "name" : "All",
40
+ "url" : "http://example.jenkins2.com/"
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,126 @@
1
+ {
2
+ "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowRun",
3
+ "actions" : [
4
+ {
5
+ "_class" : "hudson.model.CauseAction",
6
+ "causes" : [
7
+ {
8
+ "_class" : "hudson.triggers.TimerTrigger$TimerTriggerCause",
9
+ "shortDescription" : "Started by timer"
10
+ }
11
+ ]
12
+ },
13
+ {
14
+ "_class" : "jenkins.metrics.impl.TimeInQueueAction"
15
+ },
16
+ {
17
+ "_class" : "hudson.plugins.git.util.BuildData",
18
+ "buildsByBranchName" : {
19
+ "origin/master" : {
20
+ "_class" : "hudson.plugins.git.util.Build",
21
+ "buildNumber" : 144,
22
+ "buildResult" : null,
23
+ "marked" : {
24
+ "SHA1" : "9e94b394e214cb89681023c3e47791fb1b8e0ffe",
25
+ "branch" : [
26
+ {
27
+ "SHA1" : "9e94b394e214cb89681023c3e47791fb1b8e0ffe",
28
+ "name" : "origin/master"
29
+ }
30
+ ]
31
+ },
32
+ "revision" : {
33
+ "SHA1" : "9e94b394e214cb89681023c3e47791fb1b8e0ffe",
34
+ "branch" : [
35
+ {
36
+ "SHA1" : "9e94b394e214cb89681023c3e47791fb1b8e0ffe",
37
+ "name" : "origin/master"
38
+ }
39
+ ]
40
+ }
41
+ },
42
+ "refs/remotes/origin/master" : {
43
+ "_class" : "hudson.plugins.git.util.Build",
44
+ "buildNumber" : 111,
45
+ "buildResult" : null,
46
+ "marked" : {
47
+ "SHA1" : "c9a33c0e591ed88919df0abecb26ab20bc926516",
48
+ "branch" : [
49
+ {
50
+ "SHA1" : "c9a33c0e591ed88919df0abecb26ab20bc926516",
51
+ "name" : "refs/remotes/origin/master"
52
+ }
53
+ ]
54
+ },
55
+ "revision" : {
56
+ "SHA1" : "c9a33c0e591ed88919df0abecb26ab20bc926516",
57
+ "branch" : [
58
+ {
59
+ "SHA1" : "c9a33c0e591ed88919df0abecb26ab20bc926516",
60
+ "name" : "refs/remotes/origin/master"
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ },
66
+ "lastBuiltRevision" : {
67
+ "SHA1" : "9e94b394e214cb89681023c3e47791fb1b8e0ffe",
68
+ "branch" : [
69
+ {
70
+ "SHA1" : "9e94b394e214cb89681023c3e47791fb1b8e0ffe",
71
+ "name" : "origin/master"
72
+ }
73
+ ]
74
+ },
75
+ "remoteUrls" : [
76
+ "git@github.com:yitsushi/sample-project.git"
77
+ ],
78
+ "scmName" : ""
79
+ },
80
+ {
81
+ "_class" : "hudson.plugins.git.GitTagAction"
82
+ },
83
+ { },
84
+ { },
85
+ { },
86
+ {
87
+ "_class" : "hudson.tasks.junit.TestResultAction",
88
+ "failCount" : 3,
89
+ "skipCount" : 0,
90
+ "totalCount" : 69,
91
+ "urlName" : "testReport"
92
+ },
93
+ { },
94
+ { },
95
+ { },
96
+ { },
97
+ { },
98
+ {
99
+ "_class" : "org.jenkinsci.plugins.workflow.job.views.FlowGraphAction"
100
+ },
101
+ { },
102
+ { }
103
+ ],
104
+ "artifacts" : [ ],
105
+ "building" : false,
106
+ "description" : null,
107
+ "displayName" : "#144",
108
+ "duration" : 3467090,
109
+ "estimatedDuration" : 3589668,
110
+ "executor" : null,
111
+ "fullDisplayName" : "sample-job-pipeline #144",
112
+ "id" : "144",
113
+ "keepLog" : false,
114
+ "number" : 144,
115
+ "queueId" : 19243,
116
+ "result" : "UNSTABLE",
117
+ "timestamp" : 1492499520931,
118
+ "url" : "http://example.jenkins2.com/job/sample-job-pipeline/144/",
119
+ "changeSets" : [
120
+ ],
121
+ "nextBuild" : null,
122
+ "previousBuild" : {
123
+ "number" : 143,
124
+ "url" : "http://example.jenkins2.com/job/sample-job-pipeline/143/"
125
+ }
126
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins2-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balazs Nadasdi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -130,6 +130,13 @@ files:
130
130
  - lib/jenkins2-api.rb
131
131
  - lib/thor_command.rb
132
132
  - lib/version.rb
133
+ - spec/features/build_spec.rb
134
+ - spec/features/client_spec.rb
135
+ - spec/features/job_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/support/fake_jenkins.rb
138
+ - spec/support/fixtures/job_list.json
139
+ - spec/support/fixtures/latest_build.json
133
140
  homepage: https://yitsushi.github.io/jenkins2-api/
134
141
  licenses:
135
142
  - MIT
@@ -154,4 +161,11 @@ rubygems_version: 2.6.11
154
161
  signing_key:
155
162
  specification_version: 4
156
163
  summary: API client for Jenkins 2.
157
- test_files: []
164
+ test_files:
165
+ - spec/features/build_spec.rb
166
+ - spec/features/client_spec.rb
167
+ - spec/features/job_spec.rb
168
+ - spec/spec_helper.rb
169
+ - spec/support/fake_jenkins.rb
170
+ - spec/support/fixtures/job_list.json
171
+ - spec/support/fixtures/latest_build.json