Class: GitLab::Exporter::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/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
19
# File 'lib/gitlab_exporter/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



30
31
32
# File 'lib/gitlab_exporter/git.rb', line 30

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

#pullObject



21
22
23
# File 'lib/gitlab_exporter/git.rb', line 21

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

#pushObject



25
26
27
28
# File 'lib/gitlab_exporter/git.rb', line 25

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