Class: Ciflows::Graphql

Inherits:
Object
  • Object
show all
Defined in:
lib/ciflows/graphql.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_id, job_name) ⇒ Graphql

Returns a new instance of Graphql.



12
13
14
15
16
17
18
19
20
# File 'lib/ciflows/graphql.rb', line 12

def initialize(workflow_id, job_name)
  @workflow_id = workflow_id
  @job_name = job_name
  @client = Graphlient::Client.new(BASE_URL,
                                   headers: {
                                     'Authorization' => Ciflows::CI_TOKEN,
                                   })
  @schema = @client.schema
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/ciflows/graphql.rb', line 9

def client
  @client
end

#failed_jobsObject

Returns the value of attribute failed_jobs.



10
11
12
# File 'lib/ciflows/graphql.rb', line 10

def failed_jobs
  @failed_jobs
end

#jobObject

Returns the value of attribute job.



10
11
12
# File 'lib/ciflows/graphql.rb', line 10

def job
  @job
end

#job_nameObject (readonly)

Returns the value of attribute job_name.



9
10
11
# File 'lib/ciflows/graphql.rb', line 9

def job_name
  @job_name
end

#schemaObject (readonly)

Returns the value of attribute schema.



9
10
11
# File 'lib/ciflows/graphql.rb', line 9

def schema
  @schema
end

#workflowObject

Returns the value of attribute workflow.



10
11
12
# File 'lib/ciflows/graphql.rb', line 10

def workflow
  @workflow
end

#workflow_idObject (readonly)

Returns the value of attribute workflow_id.



9
10
11
# File 'lib/ciflows/graphql.rb', line 9

def workflow_id
  @workflow_id
end

Instance Method Details

#approve_jobObject



22
23
24
25
26
27
28
# File 'lib/ciflows/graphql.rb', line 22

def approve_job
  client.query(id: job.id) do
    mutation(id: :ID!) do
      approveJob(id: :id)
    end
  end
end

#get_jobs(status) ⇒ Object



54
55
56
# File 'lib/ciflows/graphql.rb', line 54

def get_jobs(status)
  @failed_jobs ||= workflow.data.workflow.jobs.select { |job| job.status.eql?(status) }
end

#get_workflowObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ciflows/graphql.rb', line 30

def get_workflow
  @workflow ||= client.query(id: workflow_id) do
    query(id: :ID!) do
      workflow(id: :id) do
        status
        jobs do
          id
          name
          type
          status
        end
      end
    end
  end
end

#rerun_workflow_from(from = 'failed') ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ciflows/graphql.rb', line 46

def rerun_workflow_from(from = 'failed')
  client.query(id: workflow_id, from: from.upcase) do
    mutation(id: :ID!, from: :RerunWorkflowFromOption) do
      rerunWorkflow(id: :id, from: :from)
    end
  end
end