bitrise-client 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: ba17bd32401a009fcfce53e1aea475ab478fcb3409facfe3f5ea60a1473b4703
4
- data.tar.gz: e3cefe0df76ca123b9978ac4935cad2df085f78e421c801507b367facefc7f83
3
+ metadata.gz: bea45506fb22cbcf82ac88de924ee3bbd72fac3f9e8e541f8a3e58a7ff9efca2
4
+ data.tar.gz: a9ef13c2d000307505b1bf3b7060d0998eccee62828796a2455d1710ddbd4164
5
5
  SHA512:
6
- metadata.gz: f9a93ee147c25b5fa3951691f262dd826dbc4c7bb8897ca581d654196dc563b0c8ff47544c489eb38acaa9fbfeed8f2a0cbd5e13947d6b225e9ff980b6a2a4cf
7
- data.tar.gz: 9bbff68c08ae6ee968560a17be4f258c24b4946271274eed9439862472d72d37bb6013d7d90b848be1995d735994fddef98d739d61018558cb7b9413940b813b
6
+ metadata.gz: f2fe332714ef892a3047f047d24697315461a8a3917826edb37a53ed19d57d20764f5b934597e6a240f5f6c7ad0d848177cc7a23a6da66273efac18c06b54c06
7
+ data.tar.gz: 80cf9f62e6ffe79a0f0740276031a967e786946f0f3062bc509ec11270491eae9d79c2283ae4d254fd78f4ae03548f47e3612c5f4c2fed41f243bde4f70e88c4
@@ -0,0 +1,27 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "**"
7
+
8
+ concurrency:
9
+ group: ${{ github.ref }}
10
+ cancel-in-progress: true
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ ruby-version: [head, 3.0, 2.7]
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ bundler-cache: true
25
+ - name: Run tests
26
+ run: |
27
+ bundle exec rspec
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
 
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
+
15
+ .ruby-version
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## v0.2.0
2
+
3
+ Changed to use the [Bitrise v0.1 API](https://devcenter.bitrise.io/en/api.html), so you need to change to specify an access token to bitrise-client initialization. See: https://github.com/mataku/bitrise-client#usage
4
+
5
+ - Support endpoint for triggering a build
6
+ - Support aborting a build
7
+ - Support listing registered test devices of all members of a specified Bitrise app
8
+
9
+ ## v0.1.0
10
+
11
+ Released.
12
+
13
+ - Support triggering a build
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A ruby client for [Bitrise API](https://devcenter.bitrise.io/#bitrise-api).
4
4
 
5
- Now supports [Build Trigger API](https://devcenter.bitrise.io/api/build-trigger/) only.
5
+ Now supports v0.1 [Build Trigger API](https://devcenter.bitrise.io/api/build-trigger/) and [Test Devices](https://devcenter.bitrise.io/en/api/api-reference.html#operations-tag-test-devices) only.
6
6
 
7
7
  ## Installation
8
8
 
@@ -25,19 +25,52 @@ Or install it yourself as:
25
25
  ```ruby
26
26
  require 'bitrise'
27
27
 
28
- client = Bitrise::Client.new
29
- client.trigger_build(
30
- app_slug = 'your_app_slug', # required
31
- build_trigger_token = 'your_build_trigger_token', # required
28
+ # Access token required to use bitrise v0.1 API. See: https://devcenter.bitrise.io/en/api/authenticating-with-the-bitrise-api.html
29
+ client = Bitrise::Client.new(access_token: 'your access token')
30
+
31
+ # Trigger a build
32
+ result = client.trigger_build(
33
+ app_slug: 'your_app_slug', # Required
32
34
  build_params: {
33
- # A tag, branch or workflow_id parameter required
35
+ # At least a tag, branch or workflow_id parameter required so that Bitrise can identify which workflow to run
34
36
  branch: 'branch',
35
37
  tag: 'tag',
36
38
  workflow_id: 'workflow_id'
37
39
  }
38
40
  )
41
+
42
+ p result.build_url # => "https://app.bitrise.io/build/1234abcd5678efgh"
43
+
44
+ # Abort a build
45
+ client.abort_build(
46
+ # Required
47
+ app_slug: 'your_app_slug',
48
+ # Required
49
+ build_slug: 'build slug to abort',
50
+
51
+ # Optional
52
+ options: {
53
+ abort_reason: 'wanna relax', # You can set a reason
54
+ abort_with_success: true, # Set true if you want to treat as a successful
55
+ skip_notifications: true # Set true if you want to receive notification even if your notification setting in app is off
56
+ }
57
+ )
58
+
59
+ # List registered test devices of all members of a specified Bitrise app
60
+ devices = client.test_devices(
61
+ # Required
62
+ app_slug: 'your_app_slug'
63
+ )
64
+ devices.each do |device|
65
+ p device.device_id
66
+ p device.device_type
67
+ p device.owner
68
+ end
39
69
  ```
40
70
 
71
+ ## Changelog
72
+
73
+ See [/CHANGELOG.md]
41
74
 
42
75
  ## License
43
76
 
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "bitrise/client"
4
+ require "bitrise"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ["lib"]
37
37
 
38
- spec.add_runtime_dependency 'faraday', '~> 0.9'
38
+ spec.add_runtime_dependency 'faraday'
39
39
 
40
40
  spec.add_development_dependency "bundler"
41
41
  spec.add_development_dependency "irb"
@@ -0,0 +1,15 @@
1
+ module Bitrise
2
+ class BuildTriggerResult
3
+ attr_accessor :build_number, :build_slug, :build_url, :message, :service, :slug, :status, :triggered_workflow
4
+ def initialize(attrs = {})
5
+ @build_number = attrs['build_number']
6
+ @build_slug = attrs['build_slug']
7
+ @build_url = attrs['build_url']
8
+ @message = attrs['message']
9
+ @service = attrs['service']
10
+ @slug = attrs['slug']
11
+ @status = attrs['status']
12
+ @triggered_workflow = attrs['triggered_workflow']
13
+ end
14
+ end
15
+ end
@@ -1,43 +1,58 @@
1
+ require 'bitrise/build_trigger_result'
1
2
  require 'json'
2
3
 
3
4
  module Bitrise
4
5
  class Client
5
6
  module Build
6
-
7
7
  # Trigger a build of your bitrise app
8
8
  #
9
9
  # @param app_slug [String] Your bitrise app slug
10
- # @param build_trigger_token [String] Build Trigger token of your app
11
- #
12
- # See: https://devcenter.bitrise.io/api/build-trigger/
13
- def trigger_build(app_slug = nil, build_trigger_token = nil, options = {})
14
- @app_slug = app_slug || raise('App slug required.')
15
- @build_trigger_token = build_trigger_token || raise('Build trigger token required.')
10
+ # @param build_params [Hash] Bulld params so that Bitrise can identify which workflow to run. Specify a branch or tag or workflow_id at least.
11
+ #
12
+ # @return [Bitrise::BuildTriggerResult]
13
+ #
14
+ # See: https://devcenter.bitrise.io/en/api/triggering-and-aborting-builds.html#triggering-a-new-build-with-the-api
15
+ def trigger_build(app_slug: nil, build_params: {})
16
+ raise ArgumentError, 'App slug required. You must specify by \'app_slug:\'' unless app_slug
17
+ raise ArgumentError, 'No value found for \'branch\' or \'tag\' or \'workflow_id\'' if build_params.empty?
16
18
 
17
19
  response = client.post do |request|
18
- request.url "/app/#{@app_slug}/build/start.json"
20
+ request.url "/v0.1/apps/#{app_slug}/builds"
19
21
  request.headers['Content-Type'] = 'application/json'
20
22
  request.body = {
21
23
  hook_info: {
22
- type: 'bitrise',
23
- build_trigger_token: @build_trigger_token
24
+ type: 'bitrise'
24
25
  },
25
- build_params: options[:build_params]
26
+ build_params: build_params
26
27
  }.to_json
27
28
  end
28
29
 
29
- check_http_status(response)
30
-
31
- JSON.parse(response.body)
30
+ result = JSON.parse(response.body)
31
+ BuildTriggerResult.new(result)
32
32
  end
33
+ end
33
34
 
34
- def check_http_status(response)
35
- case response.status
36
- when 200..299 then
37
- return
38
- else
39
- raise JSON.parse(response.body)['message']
40
- end
35
+ # Abort a build of your bitrise app
36
+ #
37
+ # @param app_slug [String] Your bitrise app slug
38
+ # @param build_slug [String] Bitrise build slug which you want to abort
39
+ #
40
+ # @param options [Hash]
41
+ # @option opts [String] :abort_reason A reason for aborting the build
42
+ # @option opts [Boolean] :abort_with_success Treat as a successful or not
43
+ # @option opts [Boolean] :skip_notifications Set true if you want to send email notifications about aborting by Bitrise
44
+ #
45
+ # @return [Bitrise::BuildTriggerResult]
46
+ #
47
+ # See: https://devcenter.bitrise.io/en/api/triggering-and-aborting-builds.html#aborting-a-build
48
+ def abort_build(app_slug: nil, build_slug: nil, options: {})
49
+ raise ArgumentError, 'App slug required. You must specify by \'app_slug:\'' unless app_slug
50
+ raise ArgumentError, 'Build slug required. You must specify by \'build_slug:\'' unless build_slug
51
+
52
+ client.post do |request|
53
+ request.url "/v0.1/apps/#{app_slug}/builds/#{build_slug}/abort"
54
+ request.headers['Content-Type'] = 'application/json'
55
+ request.body = options.to_json
41
56
  end
42
57
  end
43
58
  end
@@ -0,0 +1,20 @@
1
+ require 'faraday'
2
+ require 'bitrise/error'
3
+
4
+ module Bitrise
5
+ class Client
6
+ module Middleware
7
+
8
+ class ErrorHandler < Faraday::Response::Middleware
9
+
10
+ # @param [Faraday::Response]
11
+ def on_complete(response)
12
+ case response.status
13
+ when 400..599
14
+ raise Bitrise::Error.new(JSON.parse(response.body)['message'])
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'bitrise/test_device'
2
+ require 'json'
3
+
4
+
5
+ module Bitrise
6
+ class Client
7
+ module TestDevice
8
+
9
+ # List registered test devices of all members of a specified Bitrise app
10
+ #
11
+ # @param app_slug [String] Your bitrise app slug
12
+ #
13
+ # @return [Array<Bitrise::TestDevice>
14
+ def test_devices(app_slug: nil)
15
+ raise ArgumentError, 'App slug required. You must specify by \'app_slug:\'' unless app_slug
16
+
17
+ response = client.get do |request|
18
+ request.url "/v0.1/apps/#{app_slug}/test-devices"
19
+ request.headers['Content-Type'] = 'application/json'
20
+ end
21
+
22
+ JSON.parse(response.body)['data'].map do |device|
23
+ Bitrise::TestDevice.new(device)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module Bitrise
2
2
  class Client
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,14 +1,23 @@
1
- require 'bitrise/client/build'
2
- require 'faraday'
1
+ %w(
2
+ bitrise/client/build
3
+ bitrise/client/test_device
4
+ bitrise/client/middleware/error_handler
5
+ faraday
6
+ ).each do |lib|
7
+ require lib
8
+ end
3
9
 
4
10
  module Bitrise
5
11
  class Client
6
12
  include Bitrise::Client::Build
13
+ include Bitrise::Client::TestDevice
7
14
 
8
- def initialize(options = {})
9
- @api_host = options[:host] || 'https://app.bitrise.io'
15
+ def initialize(access_token: nil, options: {})
16
+ raise ArgumentError.new('You must specify Bitrise access token by `access_token:`.') unless access_token
17
+ @api_host = options[:host] || 'https://api.bitrise.io'
10
18
  @timeout = options[:timeout] || 30
11
19
  @open_timeout = options[:open_timeout] || 30
20
+ @access_token = access_token
12
21
  end
13
22
 
14
23
  def client
@@ -16,7 +25,9 @@ module Bitrise
16
25
  faraday.options.timeout = @timeout
17
26
  faraday.options.open_timeout = @open_timeout
18
27
  faraday.options.params_encoder = Faraday::FlatParamsEncoder
28
+ faraday.use Bitrise::Client::Middleware::ErrorHandler
19
29
  faraday.response :logger if ENV['DEBUG']
30
+ faraday.headers['Authorization'] = @access_token
20
31
 
21
32
  faraday.adapter Faraday.default_adapter
22
33
  end
@@ -0,0 +1,5 @@
1
+ module Bitrise
2
+ class Error < StandardError
3
+
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Bitrise
2
+ class TestDevice
3
+ attr_accessor :device_id, :device_type, :owner
4
+
5
+ def initialize(attrs = {})
6
+ @device_id = attrs['device_id']
7
+ @device_type = attrs['device_type']
8
+ @owner = attrs['owner']
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitrise-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mataku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-27 00:00:00.000000000 Z
11
+ date: 2021-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.9'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,9 +87,10 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/test.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
- - ".travis.yml"
93
+ - CHANGELOG.md
93
94
  - Gemfile
94
95
  - LICENSE.txt
95
96
  - README.md
@@ -98,16 +99,21 @@ files:
98
99
  - bin/setup
99
100
  - bitrise-client.gemspec
100
101
  - lib/bitrise.rb
102
+ - lib/bitrise/build_trigger_result.rb
101
103
  - lib/bitrise/client.rb
102
104
  - lib/bitrise/client/build.rb
105
+ - lib/bitrise/client/middleware/error_handler.rb
106
+ - lib/bitrise/client/test_device.rb
103
107
  - lib/bitrise/client/version.rb
108
+ - lib/bitrise/error.rb
109
+ - lib/bitrise/test_device.rb
104
110
  homepage: https://github.com/mataku/bitrise-client
105
111
  licenses:
106
112
  - MIT
107
113
  metadata:
108
114
  homepage_uri: https://github.com/mataku/bitrise-client
109
115
  source_code_uri: https://github.com/mataku/bitrise-client
110
- post_install_message:
116
+ post_install_message:
111
117
  rdoc_options: []
112
118
  require_paths:
113
119
  - lib
@@ -122,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
128
  - !ruby/object:Gem::Version
123
129
  version: '0'
124
130
  requirements: []
125
- rubygems_version: 3.0.1
126
- signing_key:
131
+ rubygems_version: 3.2.32
132
+ signing_key:
127
133
  specification_version: 4
128
134
  summary: A ruby clent for Bitrise API
129
135
  test_files: []
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.0
7
- script:
8
- - bundle exec rspec spec