bitrise-client 0.1.0 → 0.3.1

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: b7821748e7f74345830c188a95a15773c11d839e6b2d66357f6d1d581e3beb5d
4
+ data.tar.gz: 595fc5c50c502a0918a48f4687efceb24614e5a82245dad71df149a3754ac9bf
5
5
  SHA512:
6
- metadata.gz: f9a93ee147c25b5fa3951691f262dd826dbc4c7bb8897ca581d654196dc563b0c8ff47544c489eb38acaa9fbfeed8f2a0cbd5e13947d6b225e9ff980b6a2a4cf
7
- data.tar.gz: 9bbff68c08ae6ee968560a17be4f258c24b4946271274eed9439862472d72d37bb6013d7d90b848be1995d735994fddef98d739d61018558cb7b9413940b813b
6
+ metadata.gz: 8f6ae368b2311fbebb562524c70ff98e264325281d3eceb7e9bc9da1e4969667f5f0cff52996d980ee4a00d2a657752261eef445b50a0c75924e2804264a2eb6
7
+ data.tar.gz: cee9d446ca68da58390492ba316734e4f626638204497ccbda6ae7481b77d75e99569536b42056a67e0c6f5cbbb99f7f4f9efbea86fc894bea9adf17f9f8c69c
@@ -0,0 +1,28 @@
1
+ name: Test
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - develop
8
+
9
+ concurrency:
10
+ group: ${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby-version: [head, 3.0, 2.7]
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ bundler-cache: true
26
+ - name: Run tests
27
+ run: |
28
+ 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/.rspec CHANGED
@@ -1,3 +1,2 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## v0.3.1
2
+
3
+ Add GET apps. - [@tomorrowkey](https://github.com/tomorrowkey) [#6](https://github.com/mataku/bitrise-client/pull/6)
4
+
5
+ ## v0.3.0
6
+
7
+ Lock faraday version to 1.X because `Faraday::Response::Middleware` is deleted in faraday 2. - [@tomorrowkey](https://github.com/tomorrowkey) [#5](https://github.com/mataku/bitrise-client/pull/5)
8
+
9
+ ## v0.2.0
10
+
11
+ 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
12
+
13
+ - Support endpoint for triggering a build
14
+ - Support aborting a build
15
+ - Support listing registered test devices of all members of a specified Bitrise app
16
+
17
+ ## v0.1.0
18
+
19
+ Released.
20
+
21
+ - Support triggering a build
data/README.md CHANGED
@@ -2,7 +2,11 @@
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 following APIs.
6
+
7
+ - [Build Trigger](https://devcenter.bitrise.io/api/build-trigger/)
8
+ - [Get Test Devices](https://devcenter.bitrise.io/en/api/api-reference.html#operations-tag-test-devices)
9
+ - [Get Apps](https://devcenter.bitrise.io/en/api/api-reference.html)
6
10
 
7
11
  ## Installation
8
12
 
@@ -25,19 +29,52 @@ Or install it yourself as:
25
29
  ```ruby
26
30
  require 'bitrise'
27
31
 
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
32
+ # Access token required to use bitrise v0.1 API. See: https://devcenter.bitrise.io/en/api/authenticating-with-the-bitrise-api.html
33
+ client = Bitrise::Client.new(access_token: 'your access token')
34
+
35
+ # Trigger a build
36
+ result = client.trigger_build(
37
+ app_slug: 'your_app_slug', # Required
32
38
  build_params: {
33
- # A tag, branch or workflow_id parameter required
39
+ # At least a tag, branch or workflow_id parameter required so that Bitrise can identify which workflow to run
34
40
  branch: 'branch',
35
41
  tag: 'tag',
36
42
  workflow_id: 'workflow_id'
37
43
  }
38
44
  )
45
+
46
+ p result.build_url # => "https://app.bitrise.io/build/1234abcd5678efgh"
47
+
48
+ # Abort a build
49
+ client.abort_build(
50
+ # Required
51
+ app_slug: 'your_app_slug',
52
+ # Required
53
+ build_slug: 'build slug to abort',
54
+
55
+ # Optional
56
+ options: {
57
+ abort_reason: 'wanna relax', # You can set a reason
58
+ abort_with_success: true, # Set true if you want to treat as a successful
59
+ skip_notifications: true # Set true if you want to receive notification even if your notification setting in app is off
60
+ }
61
+ )
62
+
63
+ # List registered test devices of all members of a specified Bitrise app
64
+ devices = client.test_devices(
65
+ # Required
66
+ app_slug: 'your_app_slug'
67
+ )
68
+ devices.each do |device|
69
+ p device.device_id
70
+ p device.device_type
71
+ p device.owner
72
+ end
39
73
  ```
40
74
 
75
+ ## Changelog
76
+
77
+ See [CHANGELOG.md](/CHANGELOG.md)
41
78
 
42
79
  ## License
43
80
 
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,10 +35,11 @@ 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', '~> 1'
39
39
 
40
40
  spec.add_development_dependency "bundler"
41
41
  spec.add_development_dependency "irb"
42
42
  spec.add_development_dependency "rake"
43
43
  spec.add_development_dependency "rspec"
44
+ spec.add_development_dependency "webmock"
44
45
  end
@@ -0,0 +1,34 @@
1
+ require "bitrise/response"
2
+ require "bitrise/app_owner"
3
+
4
+ module Bitrise
5
+ class AppResponse < Response
6
+ include Pagination
7
+
8
+ def data
9
+ @json.fetch("data")&.map do |raw|
10
+ App.new(raw)
11
+ end
12
+ end
13
+ end
14
+
15
+ class App
16
+ attr_reader :slug, :title, :project_type, :provider, :repo_owner, :repo_url, :repo_slug, :is_disabled, :status, :is_public, :is_github_checks_enabled, :owner, :avatar_url
17
+
18
+ def initialize(attrs = {})
19
+ @slug = attrs['slug']
20
+ @title = attrs['title']
21
+ @project_type = attrs['project_type']
22
+ @provider = attrs['provider']
23
+ @repo_owner = attrs['repo_owner']
24
+ @repo_url = attrs['repo_url']
25
+ @repo_slug = attrs['repo_slug']
26
+ @is_disabled = attrs['is_disabled']
27
+ @status = attrs['status']
28
+ @is_public = attrs['is_public']
29
+ @is_github_checks_enabled = attrs['is_github_checks_enabled']
30
+ @owner = AppOwner.new(attrs['owner'])
31
+ @avatar_url = attrs['avatar_url']
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module Bitrise
2
+ class AppOwner
3
+ attr_reader :account_type, :name, :slug
4
+
5
+ def initialize(attrs = {})
6
+ @account_type = attrs['account_type']
7
+ @name = attrs['name']
8
+ @slug = attrs['slug']
9
+ end
10
+ end
11
+ end
@@ -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
@@ -0,0 +1,32 @@
1
+ require 'bitrise/app'
2
+ require 'json'
3
+
4
+ module Bitrise
5
+ class Client
6
+ module App
7
+
8
+ # List all the apps available for the authenticated account, including those that are owned by other users or Organizations.
9
+ #
10
+ # @param sort_by [String] Order of the applications: sort them based on when they were created or the time of their last build
11
+ # Available values : last_build_at, created_at
12
+ # @param next [String] Slug of the first app in the response
13
+ # @param limit [Integer] Max number of elements per page (default: 50)
14
+ #
15
+ # @return [App]
16
+ def apps(sort_by: nil, _next: nil, limit: nil)
17
+ response = client.get do |request|
18
+ request.url "/v0.1/apps"
19
+ request.params = {
20
+ sort_by: sort_by,
21
+ next: _next,
22
+ limit: limit,
23
+ }.compact
24
+ request.headers['Content-Type'] = 'application/json'
25
+ end
26
+
27
+ result = JSON.parse(response.body)
28
+ AppResponse.new(result)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,43 +1,56 @@
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
+ # See: https://devcenter.bitrise.io/en/api/triggering-and-aborting-builds.html#aborting-a-build
46
+ def abort_build(app_slug: nil, build_slug: nil, options: {})
47
+ raise ArgumentError, 'App slug required. You must specify by \'app_slug:\'' unless app_slug
48
+ raise ArgumentError, 'Build slug required. You must specify by \'build_slug:\'' unless build_slug
49
+
50
+ client.post do |request|
51
+ request.url "/v0.1/apps/#{app_slug}/builds/#{build_slug}/abort"
52
+ request.headers['Content-Type'] = 'application/json'
53
+ request.body = options.to_json
41
54
  end
42
55
  end
43
56
  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.3.1"
4
4
  end
5
5
  end
@@ -1,14 +1,25 @@
1
- require 'bitrise/client/build'
2
- require 'faraday'
1
+ %w(
2
+ bitrise/client/app
3
+ bitrise/client/build
4
+ bitrise/client/test_device
5
+ bitrise/client/middleware/error_handler
6
+ faraday
7
+ ).each do |lib|
8
+ require lib
9
+ end
3
10
 
4
11
  module Bitrise
5
12
  class Client
13
+ include Bitrise::Client::App
6
14
  include Bitrise::Client::Build
15
+ include Bitrise::Client::TestDevice
7
16
 
8
- def initialize(options = {})
9
- @api_host = options[:host] || 'https://app.bitrise.io'
17
+ def initialize(access_token: nil, options: {})
18
+ raise ArgumentError.new('You must specify Bitrise access token by `access_token:`.') unless access_token
19
+ @api_host = options[:host] || 'https://api.bitrise.io'
10
20
  @timeout = options[:timeout] || 30
11
21
  @open_timeout = options[:open_timeout] || 30
22
+ @access_token = access_token
12
23
  end
13
24
 
14
25
  def client
@@ -16,7 +27,9 @@ module Bitrise
16
27
  faraday.options.timeout = @timeout
17
28
  faraday.options.open_timeout = @open_timeout
18
29
  faraday.options.params_encoder = Faraday::FlatParamsEncoder
30
+ faraday.use Bitrise::Client::Middleware::ErrorHandler
19
31
  faraday.response :logger if ENV['DEBUG']
32
+ faraday.headers['Authorization'] = @access_token
20
33
 
21
34
  faraday.adapter Faraday.default_adapter
22
35
  end
@@ -0,0 +1,5 @@
1
+ module Bitrise
2
+ class Error < StandardError
3
+
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ module Bitrise
2
+ class Response
3
+ def initialize(json)
4
+ @json = json
5
+ end
6
+ end
7
+
8
+ class Paging
9
+ attr_reader :total_item_count, :page_item_limit, :next
10
+
11
+ def initialize(attrs = {})
12
+ @total_item_count = attrs['total_item_count']
13
+ @page_item_limit = attrs['page_item_limit']
14
+ @next = attrs['next']
15
+ end
16
+ end
17
+
18
+ module Pagination
19
+ def paging
20
+ ::Bitrise::Paging.new(@json["paging"])
21
+ end
22
+ end
23
+ 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,14 +1,14 @@
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.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mataku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-27 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
19
+ version: '1'
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: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: A ruby client for Bitrise API
84
98
  email:
85
99
  - nagomimatcha@gmail.com
@@ -87,9 +101,10 @@ executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
104
+ - ".github/workflows/test.yml"
90
105
  - ".gitignore"
91
106
  - ".rspec"
92
- - ".travis.yml"
107
+ - CHANGELOG.md
93
108
  - Gemfile
94
109
  - LICENSE.txt
95
110
  - README.md
@@ -98,9 +113,18 @@ files:
98
113
  - bin/setup
99
114
  - bitrise-client.gemspec
100
115
  - lib/bitrise.rb
116
+ - lib/bitrise/app.rb
117
+ - lib/bitrise/app_owner.rb
118
+ - lib/bitrise/build_trigger_result.rb
101
119
  - lib/bitrise/client.rb
120
+ - lib/bitrise/client/app.rb
102
121
  - lib/bitrise/client/build.rb
122
+ - lib/bitrise/client/middleware/error_handler.rb
123
+ - lib/bitrise/client/test_device.rb
103
124
  - lib/bitrise/client/version.rb
125
+ - lib/bitrise/error.rb
126
+ - lib/bitrise/response.rb
127
+ - lib/bitrise/test_device.rb
104
128
  homepage: https://github.com/mataku/bitrise-client
105
129
  licenses:
106
130
  - MIT
@@ -122,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
146
  - !ruby/object:Gem::Version
123
147
  version: '0'
124
148
  requirements: []
125
- rubygems_version: 3.0.1
149
+ rubygems_version: 3.1.6
126
150
  signing_key:
127
151
  specification_version: 4
128
152
  summary: A ruby clent for Bitrise API
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