Module: Wassup::Helpers::CircleCI
- Defined in:
- lib/wassup/helpers/circleci.rb,
lib/wassup/helpers/circleci.rb
Defined Under Namespace
Modules: Formatter
Class Method Summary collapse
Class Method Details
.workflows(vcs:, org:, repo:, limit_days: nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wassup/helpers/circleci.rb', line 4 def self.workflows(vcs:, org:, repo:, limit_days: nil) require 'json' require 'rest-client' resp = RestClient::Request.execute( method: :get, url: "https://circleci.com/api/v2/project/#{vcs}/#{org}/#{repo}/pipeline", headers: { "Circle-Token": ENV["WASSUP_CIRCLE_CI_API_TOKEN"] } ) json = JSON.parse(resp) return json["items"].select do |item| if !limit_days.nil? date = Time.parse(item["updated_at"]) days = (Time.now - date).to_i / (24 * 60 * 60) days < limit_days else true end end.map do |pipeline| id = pipeline["id"] resp = RestClient::Request.execute( method: :get, url: "https://circleci.com/api/v2/pipeline/#{id}/workflow", headers: { "Circle-Token": ENV["WASSUP_CIRCLE_CI_API_TOKEN"] } ) json = JSON.parse(resp) workflow = json["items"].first if workflow workflow["pipeline"] = pipeline end workflow end.compact end |