Class: GitLab::Monitor::Git

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

Overview

Git monitoring helping class

Takes a repository path for construction and provides 2 main methods:

- pull
- push

Both methods return a CommandResult which includes the output of the execution plus the tracked execution time.

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Git

Returns a new instance of Git.



14
15
16
17
18
# File 'lib/gitlab_monitor/git.rb', line 14

def initialize(repo)
  fail "Repository #{repo} does not exists" unless Dir.exist? repo
  @repo = repo
  @tracker = TimeTracker.new
end

Instance Method Details

#empty_commit(message = "Beep") ⇒ Object



29
30
31
# File 'lib/gitlab_monitor/git.rb', line 29

def empty_commit(message = "Beep")
  @tracker.track { execute("git commit --allow-empty -m '#{message}'") }
end

#pullObject



20
21
22
# File 'lib/gitlab_monitor/git.rb', line 20

def pull
  @tracker.track { execute "git pull -q" }
end

#pushObject



24
25
26
27
# File 'lib/gitlab_monitor/git.rb', line 24

def push
  empty_commit
  @tracker.track { execute "git push -q" }
end