class Ciflows::Project

Constants

BASE_URL

Attributes

branch[RW]
branch_name[R]
build[RW]
build_name[R]
job_name[R]
latest_workflows[RW]
projects[RW]
repo[RW]
repo_name[R]

Public Class Methods

new(repo_name, branch_name, build_name, job_name) click to toggle source
# File lib/ciflows/project.rb, line 17
def initialize(repo_name, branch_name, build_name, job_name)
  @branch_name = CGI.escape(branch_name)
  @repo_name = repo_name
  @build_name = build_name
  @job_name = job_name
end

Public Instance Methods

approve_workflow() click to toggle source
# File lib/ciflows/project.rb, line 36
def approve_workflow
  graphql_client.get_workflow
  graphql_client.approve_job
end
failed_jobs() click to toggle source
# File lib/ciflows/project.rb, line 46
def failed_jobs
  graphql_client.get_workflow
  graphql_client.get_jobs('FAILED')
end
get_workflow() click to toggle source
# File lib/ciflows/project.rb, line 32
def get_workflow
  graphql_client.get_workflow
end
process() click to toggle source
# File lib/ciflows/project.rb, line 24
def process
  find_projects
  find_repo
  find_branch
  find_latest_workflows
  find_build
end
rerun_workflow_from(from) click to toggle source
# File lib/ciflows/project.rb, line 41
def rerun_workflow_from(from)
  graphql_client.get_workflow
  graphql_client.rerun_workflow_from(from)
end

Private Instance Methods

find_branch() click to toggle source
# File lib/ciflows/project.rb, line 70
def find_branch
  @branch ||= @repo['branches'][branch_name]
end
find_build() click to toggle source
# File lib/ciflows/project.rb, line 78
def find_build
  @build ||= begin
    if build_name
      latest_workflows[build_name]
    else
      build_name = latest_workflows.max_by { |_, data| data[:created_at] }[0]
      latest_workflows[build_name]
    end
  end
end
find_latest_workflows() click to toggle source
# File lib/ciflows/project.rb, line 74
def find_latest_workflows
  @latest_workflows ||= branch['latest_workflows']
end
find_projects() click to toggle source
# File lib/ciflows/project.rb, line 57
def find_projects
  res = RestClient.get(BASE_URL,
                       'Circle-Token' => Ciflows::CI_TOKEN,
                       content_type: :json,
                       accept: :json)

  @projects = JSON.parse(res.body)
end
find_repo() click to toggle source
# File lib/ciflows/project.rb, line 66
def find_repo
  @repo ||= projects.detect { |proj| proj['reponame'] == repo_name }
end
graphql_client() click to toggle source
# File lib/ciflows/project.rb, line 53
def graphql_client
  @graphql_client ||= Graphql.new(build['id'], job_name)
end