capistrano-strategy-jenkins_artifact 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a5db36572a0cb054e66d71245118d6daa2aa93b
4
- data.tar.gz: b8b8d7af57076fdc8a497934478ad52d4d70a2b4
3
+ metadata.gz: 735fcaef2ef6c36ee11f1cbe77b41d8c6d65651e
4
+ data.tar.gz: 5b4a9cdd23177d053c78fe239ae49be6c3446436
5
5
  SHA512:
6
- metadata.gz: afb7ace0e506779442a5c0cccdc8abffbfa3f277c1195e48129c0578984a8384fb29e63ae0f607b5451559119abcd157a28aef8b888c65a0b7eea36ea57f7f5c
7
- data.tar.gz: 92c4db0b7d0419254396df95be93f67bc7d9cc04d983dc80562340f88628396810f613bedb0f16d62580943ffcb7619aa426d7e9a0546362f908158a9c81800c
6
+ metadata.gz: ab11f0e76ba394e7db82a20ed3af0578938a221ed7b4d860fc03c3dc3994554bd70913f394243443493a38eb42f7f55603670abbb3ac77b964d4c167a2563a66
7
+ data.tar.gz: '08c7002716da41011cbe0a2c99aa7341a7e7d4fd00c2d8dfb5699e2ffb17f26e0bf8830f24d2d2a0b2f1350b089fb13e39edd51089e128c8c8368b6d32a1a5e2'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Capistrano::Strategy::JenkinsArtifact [![Build Status][travis-badge]][travis-url]
1
+ # Capistrano::Strategy::JenkinsArtifact [![Build Status][travis-badge]][travis-url] [![Gem Version](https://badge.fury.io/rb/capistrano-strategy-jenkins_artifact.svg)](https://badge.fury.io/rb/capistrano-strategy-jenkins_artifact)
2
2
 
3
3
  Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
4
4
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "capistrano-strategy-jenkins_artifact"
4
- spec.version = "0.3.0"
4
+ spec.version = "0.4.0"
5
5
  spec.authors = ["aereal"]
6
6
  spec.email = ["aereal@aereal.org"]
7
7
 
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
16
  spec.require_paths = ["lib"]
17
17
 
18
- spec.add_runtime_dependency "jenkins_api_client"
18
+ spec.add_runtime_dependency "json"
19
19
  spec.add_development_dependency "capistrano", "< 3.0.0"
20
20
  spec.add_development_dependency "bundler", "~> 1.11"
21
21
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,26 +1,40 @@
1
1
  require 'uri'
2
+ require 'net/https'
2
3
 
3
4
  require 'capistrano/recipes/deploy/strategy/base'
4
- require 'jenkins_api_client'
5
5
 
6
- class ::JenkinsApi::Client::Job
7
- def self.get_artifact_url_by_build(build, &finder)
8
- finder ||= ->(_) { true }
9
- matched_artifact = build['artifacts'].find(&finder)
10
- raise 'Specified artifact not found in current build !!' unless matched_artifact
11
- relative_build_path = matched_artifact['relativePath']
12
- jenkins_path = build['url']
13
- artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_build_path}")
14
- return artifact_path
6
+ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::Strategy::Base
7
+ module ApiClient
8
+ # jenkins_origin: URI
9
+ # => Maybe[$parsed_body: Hash]
10
+ def self.get_last_successful_build(jenkins_origin, dir_name)
11
+ uri = jenkins_origin.clone
12
+ uri.path += "/job/#{URI.encode_www_form_component(dir_name)}/lastSuccessfulBuild/api/json"
13
+ req = Net::HTTP::Get.new(uri.path)
14
+ res = Net::HTTP.start(uri.host, uri.port) {|session|
15
+ session.use_ssl = uri.scheme == 'https'
16
+ session.request(req)
17
+ }
18
+ case res
19
+ when Net::HTTPSuccess
20
+ if /\Aapplication\/json\b/ === (res.content_type || '')
21
+ JSON.parse(res.body)
22
+ end
23
+ end
24
+ end
15
25
  end
16
26
 
17
- def get_last_successful_build(job_name)
18
- @logger.info "Obtaining last successful build number of #{job_name}"
19
- @client.api_get_request("/job/#{path_encode(job_name)}/lastSuccessfulBuild")
27
+ module Helpers
28
+ def self.get_artifact_url_by_build(build, &finder)
29
+ finder ||= ->(_) { true }
30
+ matched_artifact = build['artifacts'].find(&finder)
31
+ raise 'Specified artifact not found in current build !!' unless matched_artifact
32
+ relative_build_path = matched_artifact['relativePath']
33
+ jenkins_path = build['url']
34
+ artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_build_path}")
35
+ return artifact_path
36
+ end
20
37
  end
21
- end
22
-
23
- class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::Strategy::Base
24
38
 
25
39
  def _guess_compression_type(filename)
26
40
  case filename.downcase
@@ -56,16 +70,14 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
56
70
  end
57
71
 
58
72
  jenkins_origin = fetch(:jenkins_origin) or abort ":jenkins_origin configuration must be defined"
59
- client = JenkinsApi::Client.new(server_url: jenkins_origin.to_s)
60
-
61
- last_successful_build = client.job.get_last_successful_build(dir_name)
73
+ last_successful_build = ApiClient.get_last_successful_build(jenkins_origin, dir_name)
62
74
  build_at = Time.at(last_successful_build['timestamp'] / 1000)
63
75
 
64
76
  set(:artifact_url) do
65
77
  artifact_finder = exists?(:artifact_relative_path) ?
66
78
  ->(artifact) { artifact['relativePath'] == fetch(:artifact_relative_path) } :
67
79
  ->(artifact) { true }
68
- uri = JenkinsApi::Client::Job.get_artifact_url_by_build(last_successful_build, &artifact_finder)
80
+ uri = Helpers.get_artifact_url_by_build(last_successful_build, &artifact_finder)
69
81
  abort "No artifact found for #{dir_name}" if uri.empty?
70
82
  URI.parse(uri).tap {|uri|
71
83
  uri.scheme = jenkins_origin.scheme
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-strategy-jenkins_artifact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aereal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-25 00:00:00.000000000 Z
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jenkins_api_client
14
+ name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.5.2
132
+ rubygems_version: 2.6.11
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.