Class: Gloo::Objs::Git

Inherits:
Core::Obj show all
Defined in:
lib/gloo/objs/dev/git.rb

Constant Summary collapse

KEYWORD =
'git_repo'.freeze
KEYWORD_SHORT =
'git'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Obj

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Obj

#add_child, #add_children_on_create?, #add_default_children, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #set_value, #sql_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



42
43
44
45
46
# File 'lib/gloo/objs/dev/git.rb', line 42

def self.messages
  actions = %w[validate commit get_branch review]
  changes = %w[check_changes get_changes]
  return super + changes + actions
end

.short_typenameObject

The short name of the object type.



24
25
26
# File 'lib/gloo/objs/dev/git.rb', line 24

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



17
18
19
# File 'lib/gloo/objs/dev/git.rb', line 17

def self.typename
  return KEYWORD
end

Instance Method Details

#msg_check_changesObject

Check to see if the repo has changes.



113
114
115
116
117
118
119
120
121
122
# File 'lib/gloo/objs/dev/git.rb', line 113

def msg_check_changes
  result = false
  path = path_value
  if path_is_dir?( path )
    data = `cd #{path}; git status -s`
    result = true unless data.strip.empty?
  end

  @engine.heap.it.set_to result
end

#msg_commitObject

Commit pending changes.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gloo/objs/dev/git.rb', line 75

def msg_commit
  msg = 'Commit'
  path = path_value
  if path_is_dir?( path )
    if @params&.token_count&.positive?
      expr = Gloo::Expr::Expression.new( @engine, @params.tokens )
      msg = expr.evaluate
    end
    branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
    branch = branch.strip
    add = 'git add .'
    cmt = 'git commit -m '
    psh = 'git push origin '
    `cd #{path};#{add};#{cmt}"#{msg}";#{psh}#{branch}`
  end
  @engine.heap.it.set_to msg
end

#msg_get_branchObject

Get the current working branch.



51
52
53
54
55
56
57
58
59
60
# File 'lib/gloo/objs/dev/git.rb', line 51

def msg_get_branch
  branch = ''
  path = path_value
  if path_is_dir?( path )
    branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
    branch = branch.strip
  end

  @engine.heap.it.set_to branch
end

#msg_get_changesObject

Get the pending changes.



96
97
98
99
100
101
# File 'lib/gloo/objs/dev/git.rb', line 96

def msg_get_changes
  path = path_value
  result = `cd #{path}; git status -s` if path_is_dir?( path )
  result ||= ''
  @engine.heap.it.set_to result
end

#msg_reviewObject

Review pending changes.



65
66
67
68
69
70
# File 'lib/gloo/objs/dev/git.rb', line 65

def msg_review
  @engine.log.debug 'Reviewing pending changes'
  cmd = "cd #{path_value}; git diff"
  @engine.log.debug cmd
  system cmd
end

#msg_validateObject

Check to make sure this is a valide git repo.



127
128
129
130
131
132
133
134
135
136
# File 'lib/gloo/objs/dev/git.rb', line 127

def msg_validate
  result = false
  path = path_value
  if path_is_dir?( path )
    pn = File.join( path, '.git' )
    result = File.exist? pn
  end

  @engine.heap.it.set_to result
end

#path_is_dir?(path) ⇒ Boolean

Is the given path non nil and is it a directory?

Returns:



106
107
108
# File 'lib/gloo/objs/dev/git.rb', line 106

def path_is_dir?( path )
  return path && File.directory?( path )
end

#path_valueObject

Get the path to the git repo (locally).



31
32
33
# File 'lib/gloo/objs/dev/git.rb', line 31

def path_value
  return value
end