Class: DEIS::Git
- Inherits:
-
Object
- Object
- DEIS::Git
- Defined in:
- lib/rdeis/git.rb
Class Method Summary collapse
- .branch ⇒ Object
- .branch_cmd ⇒ Object
- .checkout_to_ref_cmd(ref, branch) ⇒ Object
-
.github_token ⇒ Object
find env based token.
-
.github_token_cmd ⇒ Object
more advanced version that reads config files.
- .github_token_varname ⇒ Object
- .init_with_remote_cmd(remote) ⇒ Object
- .is_git? ⇒ Boolean
- .is_git_cmd ⇒ Object
- .name ⇒ Object
- .ref ⇒ Object
- .ref_cmd ⇒ Object
- .remote ⇒ Object
Class Method Details
.branch ⇒ Object
34 35 36 |
# File 'lib/rdeis/git.rb', line 34 def self.branch `#{DEIS::Git.branch_cmd}`.strip end |
.branch_cmd ⇒ Object
38 39 40 |
# File 'lib/rdeis/git.rb', line 38 def self.branch_cmd "git rev-parse --abbrev-ref HEAD" end |
.checkout_to_ref_cmd(ref, branch) ⇒ Object
46 47 48 |
# File 'lib/rdeis/git.rb', line 46 def self.checkout_to_ref_cmd(ref, branch) "git fetch origin && git checkout -f origin/#{branch} && git branch -d #{branch} ; git checkout -f #{branch} && git checkout -f #{ref} 2>&1 | grep 'error:' | wc -l" end |
.github_token ⇒ Object
find env based token
51 52 53 54 |
# File 'lib/rdeis/git.rb', line 51 def self.github_token v = self.github_token_varname ENV[v] end |
.github_token_cmd ⇒ Object
more advanced version that reads config files
57 58 59 |
# File 'lib/rdeis/git.rb', line 57 def self.github_token_cmd "cat #{DEIS::Storage::BASE_PATH}.profile | grep #{DEIS::Git.github_token_varname}=.* -o | sed -E 's##{DEIS::Git.github_token_varname}=##' | sed -E 's#\"##g'" end |
.github_token_varname ⇒ Object
61 62 63 |
# File 'lib/rdeis/git.rb', line 61 def self.github_token_varname "GITHUB_TOKEN" end |
.init_with_remote_cmd(remote) ⇒ Object
42 43 44 |
# File 'lib/rdeis/git.rb', line 42 def self.init_with_remote_cmd(remote) "git init && git remote add origin #{remote} 2>&1 | grep 'fatal:' -o | wc -l" end |
.is_git? ⇒ Boolean
4 5 6 7 |
# File 'lib/rdeis/git.rb', line 4 def self.is_git? res = `#{DEIS::Git.is_git_cmd}`.to_i if res == 0 then true else false end end |
.is_git_cmd ⇒ Object
9 10 11 |
# File 'lib/rdeis/git.rb', line 9 def self.is_git_cmd "git status 2>&1 | grep 'fatal: Not a git' | wc -l" end |
.name ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/rdeis/git.rb', line 13 def self.name remote = DEIS::Git.remote if remote.nil? || remote.length == 0 return "na" else `echo #{remote} | grep "/.*\.git" -o | sed -E "s#/##" | sed -E "s#.git##" 2>/dev/null`.strip end end |
.ref ⇒ Object
26 27 28 |
# File 'lib/rdeis/git.rb', line 26 def self.ref `#{DEIS::Git.ref_cmd}`.strip end |
.ref_cmd ⇒ Object
30 31 32 |
# File 'lib/rdeis/git.rb', line 30 def self.ref_cmd "git rev-parse --verify HEAD 2>/dev/null" end |
.remote ⇒ Object
22 23 24 |
# File 'lib/rdeis/git.rb', line 22 def self.remote `c=$(git remote show | wc -l ) ; if [ "$c" -gt 0 ]; then git remote show -n origin | grep " Fetch URL:" | grep ": .*" -o | sed -E "s#: ##" 2>/dev/null ; fi`.strip end |