Class: Semaph::Model::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/semaph/model/workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, raw) ⇒ Workflow

Returns a new instance of Workflow.



9
10
11
12
13
14
15
16
17
# File 'lib/semaph/model/workflow.rb', line 9

def initialize(project, raw)
  @project = project
  @raw = raw
  @id = raw["wf_id"]
  @created_at = Time.at(raw["created_at"]["seconds"].to_i)
  @branch = raw["branch_name"]
  @branch_id = raw["branch_id"]
  extract_git_details
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def branch
  @branch
end

#branch_idObject (readonly)

Returns the value of attribute branch_id.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def branch_id
  @branch_id
end

#commitObject (readonly)

Returns the value of attribute commit.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def commit
  @commit
end

#created_atObject (readonly)

Returns the value of attribute created_at.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def id
  @id
end

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def project
  @project
end

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def raw
  @raw
end

#shaObject (readonly)

Returns the value of attribute sha.



7
8
9
# File 'lib/semaph/model/workflow.rb', line 7

def sha
  @sha
end

Instance Method Details

#createdObject



35
36
37
# File 'lib/semaph/model/workflow.rb', line 35

def created
  Semaph::Formatting.time(created_at)
end

#descriptionObject



39
40
41
# File 'lib/semaph/model/workflow.rb', line 39

def description
  [created, branch, commit].join(" ")
end

#extract_git_detailsObject



19
20
21
22
23
# File 'lib/semaph/model/workflow.rb', line 19

def extract_git_details
  @sha = raw["commit_sha"]
  @commit = @sha.slice(0..10)
  @commit = `git log -n 1 --format="%h %an %s" #{sha}`.chomp if `git cat-file -t #{sha} 2>&1`.chomp == "commit"
end

#pipeline_collectionObject



25
26
27
# File 'lib/semaph/model/workflow.rb', line 25

def pipeline_collection
  @pipeline_collection ||= PipelineCollection.new(self)
end

#rerunObject



29
30
31
32
33
# File 'lib/semaph/model/workflow.rb', line 29

def rerun
  rerun_response = project.client.rerun_workflow(@id)
  workflow_response = project.client.workflow(rerun_response["wf_id"])
  Workflow.new(project, workflow_response["workflow"])
end

#stopObject



43
44
45
# File 'lib/semaph/model/workflow.rb', line 43

def stop
  project.client.stop_workflow(@id)
end