Class: Yolo::Tools::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/yolo/tools/git.rb

Overview

Runs git commands

Author:

  • Alex Fish

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGit

Creates the class with default variables, sets the path to the history yml file and loads it.



19
20
21
22
23
# File 'lib/yolo/tools/git.rb', line 19

def initialize
  @yaml_path = File.dirname(__FILE__) + "/../history/history.yml"
  @yaml = YAML::load_file @yaml_path
  @formatter = Yolo::Formatters::ProgressFormatter.new
end

Instance Attribute Details

#project_nameObject

A unique name used to identify the project and its history



13
14
15
# File 'lib/yolo/tools/git.rb', line 13

def project_name
  @project_name
end

Instance Method Details

#commitString

The latest commit hash

Returns:

  • (String)

    The latest git commit hash for the project



78
79
80
# File 'lib/yolo/tools/git.rb', line 78

def commit
  @commit
end

#current_branchString

Finds the current branch using some regex and git branch

Returns:

  • (String)

    The current branch name



86
87
88
89
90
91
92
93
94
# File 'lib/yolo/tools/git.rb', line 86

def current_branch
  branch = `git branch`
  branchs = branch.split("\n")
  current_branch = ""
  branchs.each do |b|
    current_branch = b if b.count("*") == 1
  end
  current_branch.gsub("* ", "")
end

#has_new_commit(name) ⇒ BOOL

Checks against the yaml history to see if a new commit is present to build

Parameters:

  • name (String)

    the project name, used as a unique id in the yaml history

Returns:

  • (BOOL)

    returns if there is a new commit to build



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yolo/tools/git.rb', line 30

def has_new_commit(name)
  set_project_name(name)
  if yaml_commit == latest_commit
    @formatter.no_new_commit
    false
  else
    @formatter.new_commit(latest_commit)
    update_commit(latest_commit)
    true
  end
end

#has_new_tag(name) ⇒ BOOL

Checks against the yaml history to see if a new tag is present to build

Parameters:

  • name (String)

    the project name, used as a unique id in the yaml history

Returns:

  • (BOOL)

    returns if there is a new tag to build



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/yolo/tools/git.rb', line 47

def has_new_tag(name)
  new_tag = false
  set_project_name(name)

  if latest_tag
    if yaml_tag != latest_tag or has_new_commit(name)
      @formatter.new_tag(latest_tag)
      update_tag(latest_tag)
      new_tag = true
    end
  end

  unless new_tag
    @formatter.no_new_tag
  end

  new_tag
end

#tagString

The latest git tag

Returns:

  • (String)

    The latest git tag for the project



70
71
72
# File 'lib/yolo/tools/git.rb', line 70

def tag
  @tag
end