Class: Apadmi::Grout::BitriseService
- Inherits:
-
Object
- Object
- Apadmi::Grout::BitriseService
- Defined in:
- lib/apadmi/grout/service/bitrise_service/bitrise_service.rb
Overview
Utility class for abstracting a some of the bitrise APIs
Instance Method Summary collapse
-
#download_artifacts(build_slug, output_dir) ⇒ Object
Download all artifacts from a given build to a specified directory.
-
#initialize(app_slug, network_service) ⇒ BitriseService
constructor
A new instance of BitriseService.
- #list_builds(pull_request_id, workflow) ⇒ Array<BitriseBuild>
- #retrieve_artifact_metadata(build_slug, artifact_slug) ⇒ Artifact
- #trigger_build(workflow, branch, dest, pull_request_id, pull_request_repo_url, commit_hash) ⇒ Object
Constructor Details
#initialize(app_slug, network_service) ⇒ BitriseService
Returns a new instance of BitriseService.
12 13 14 15 |
# File 'lib/apadmi/grout/service/bitrise_service/bitrise_service.rb', line 12 def initialize(app_slug, network_service) @app_slug = app_slug @network_service = network_service end |
Instance Method Details
#download_artifacts(build_slug, output_dir) ⇒ Object
Download all artifacts from a given build to a specified directory
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/apadmi/grout/service/bitrise_service/bitrise_service.rb', line 50 def download_artifacts(build_slug, output_dir) res = @network_service.do_get("/#{@app_slug}/builds/#{build_slug}/artifacts") parsed = JSON.parse(res.body) items = parsed["data"] artifacts = items.map do |item| (build_slug, item["slug"]) end FileUtils.mkdir_p output_dir artifacts.each do |item| File.open("#{output_dir}/#{item.title}", "wb") do |file| # rubocop:disable Security/Open file.write URI.open(item.download_url).read # rubocop:enable Security/Open end end artifacts end |
#list_builds(pull_request_id, workflow) ⇒ Array<BitriseBuild>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/apadmi/grout/service/bitrise_service/bitrise_service.rb', line 20 def list_builds(pull_request_id, workflow) res = @network_service.do_get("/#{@app_slug}/builds?pull_request_id=#{pull_request_id}&workflow=#{workflow}") parsed = JSON.parse(res.body) items = parsed["data"] return [] if items.nil? || items.empty? items.map do |item| BitriseBuild.new( item["triggered_at"], item["slug"], item["status"], item["commit_hash"] ) end end |
#retrieve_artifact_metadata(build_slug, artifact_slug) ⇒ Artifact
40 41 42 43 44 45 |
# File 'lib/apadmi/grout/service/bitrise_service/bitrise_service.rb', line 40 def (build_slug, artifact_slug) res = @network_service.do_get("/#{@app_slug}/builds/#{build_slug}/artifacts/#{artifact_slug}") parsed = JSON.parse(res.body) Artifact.new(parsed["data"]["title"], parsed["data"]["expiring_download_url"]) end |
#trigger_build(workflow, branch, dest, pull_request_id, pull_request_repo_url, commit_hash) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/apadmi/grout/service/bitrise_service/bitrise_service.rb', line 77 def trigger_build(workflow, branch, dest, pull_request_id, pull_request_repo_url, commit_hash) params = { workflow_id: workflow, branch: branch, commit_hash: commit_hash } params[:branch_dest] = dest unless dest.strip.blank? params[:pull_request_id] = pull_request_id unless pull_request_id.strip.blank? params[:pull_request_repository_url] = pull_request_repo_url unless pull_request_repo_url.strip.blank? payload = { hook_info: { type: "bitrise" }, build_params: params, triggered_by: "curl" } res = @network_service.do_post("/#{@app_slug}/builds", payload.to_json) parsed = JSON.parse(res.body) TriggeredBitriseBuild.from_json(parsed) end |