Class: NliPipeline::GitManager

Inherits:
SystemWrapper::CallWrapper show all
Defined in:
lib/nli_pipeline/git_manager.rb

Overview

simple class for managing git commands

Instance Attribute Summary

Attributes inherited from SystemWrapper::CallWrapper

#last_return_code

Instance Method Summary collapse

Methods inherited from SystemWrapper::CallWrapper

#call_system, #initialize, required_args, supported_args

Methods included from AbstractUtil

#add_attrs, #drop_forbidden_args_message, included, #init_with_attrs, #raise_unless_all, #to_s

Constructor Details

This class inherits a constructor from NliPipeline::SystemWrapper::CallWrapper

Instance Method Details

#branchString

Returns current branch.

Returns:

  • (String)

    current branch



28
29
30
# File 'lib/nli_pipeline/git_manager.rb', line 28

def branch
  call_system('git symbolic-ref --short HEAD', return_output: true)
end

#last_commitString

Returns full length hash of last commit.

Returns:

  • (String)

    full length hash of last commit



18
19
20
# File 'lib/nli_pipeline/git_manager.rb', line 18

def last_commit
  call_system("git log -1 --pretty=format:'%H'", return_output: true)
end

#last_commit_messageString

Returns full messaage for last commit, all as one line.

Returns:

  • (String)

    full messaage for last commit, all as one line



23
24
25
# File 'lib/nli_pipeline/git_manager.rb', line 23

def last_commit_message
  call_system('git log -1 --format=%B --oneline', return_output: true)
end

#last_commit_urlString

Returns full url to commit.

Returns:

  • (String)

    full url to commit



7
8
9
# File 'lib/nli_pipeline/git_manager.rb', line 7

def last_commit_url
  "#{remote}/commits/#{last_commit}"
end

#remote(upstream: 'origin') ⇒ String

Returns url for git remote origin.

Parameters:

  • upstream (String) (defaults to: 'origin')

Returns:

  • (String)

    url for git remote origin



13
14
15
# File 'lib/nli_pipeline/git_manager.rb', line 13

def remote(upstream: 'origin')
  call_system("git ls-remote --get-url #{upstream}", return_output: true)
end