Class: CommitLive::Github
- Inherits:
-
Object
- Object
- CommitLive::Github
- Defined in:
- lib/commit-live/github.rb
Instance Attribute Summary collapse
-
#netrc ⇒ Object
Returns the value of attribute netrc.
-
#post_details ⇒ Object
Returns the value of attribute post_details.
-
#sentry ⇒ Object
Returns the value of attribute sentry.
Instance Method Summary collapse
- #getAttr(attr) ⇒ Object
- #getValue(key) ⇒ Object
-
#initialize ⇒ Github
constructor
A new instance of Github.
- #owner ⇒ Object
- #post(repo_name, isFork = false) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize ⇒ Github
Returns a new instance of Github.
9 10 11 12 |
# File 'lib/commit-live/github.rb', line 9 def initialize() @netrc = CommitLive::NetrcInteractor.new() @sentry = CommitLive::Sentry.new() end |
Instance Attribute Details
#netrc ⇒ Object
Returns the value of attribute netrc.
8 9 10 |
# File 'lib/commit-live/github.rb', line 8 def netrc @netrc end |
#post_details ⇒ Object
Returns the value of attribute post_details.
8 9 10 |
# File 'lib/commit-live/github.rb', line 8 def post_details @post_details end |
#sentry ⇒ Object
Returns the value of attribute sentry.
8 9 10 |
# File 'lib/commit-live/github.rb', line 8 def sentry @sentry end |
Instance Method Details
#getAttr(attr) ⇒ Object
24 25 26 27 28 |
# File 'lib/commit-live/github.rb', line 24 def getAttr(attr) if !attr.nil? post_details.fetch(attr) end end |
#getValue(key) ⇒ Object
30 31 32 33 |
# File 'lib/commit-live/github.rb', line 30 def getValue(key) data = getAttr('data') data[key] end |
#owner ⇒ Object
19 20 21 22 |
# File 'lib/commit-live/github.rb', line 19 def owner netrc.read(machine: 'ga-extra') netrc.login end |
#post(repo_name, isFork = false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/commit-live/github.rb', line 35 def post(repo_name, isFork = false) enc_url = "/v2/github/createPullRequest" log_title = "#{owner} - Pull Request Failed" if isFork enc_url = URI.escape("/v2/github/createFork") log_title = "#{owner} - Lesson Forked Failed" end begin Timeout::timeout(60) do response = CommitLive::API.new().post( enc_url, headers: { 'Authorization' => "#{token}", 'Content-Type' => 'application/json' }, body: { "repoUrl": repo_name } ) @post_details = JSON.parse(response.body) if response.status != 200 && !response.body.match(/A pull request already exists/) sentry.(log_title, { 'url' => enc_url, 'repo_name' => repo_name, 'response-body' => response.body, 'response-status' => response.status } ) end end rescue Timeout::Error sentry.(log_title, { 'url' => enc_url, 'track_name' => repo_name } ) end end |
#token ⇒ Object
14 15 16 17 |
# File 'lib/commit-live/github.rb', line 14 def token netrc.read netrc.password end |