Class: CommitLive::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/commit-live/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGithub

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

#netrcObject

Returns the value of attribute netrc.



8
9
10
# File 'lib/commit-live/github.rb', line 8

def netrc
  @netrc
end

#post_detailsObject

Returns the value of attribute post_details.



8
9
10
# File 'lib/commit-live/github.rb', line 8

def post_details
  @post_details
end

#sentryObject

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

#ownerObject



19
20
21
22
# File 'lib/commit-live/github.rb', line 19

def owner
	netrc.read(machine: 'ga-extra')
	netrc.
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_message(log_title,
					{
						'url' => enc_url,
						'repo_name' => repo_name,
						'response-body' => response.body,
						'response-status' => response.status
					}
				)
			end
		end
	rescue Timeout::Error
		sentry.log_message(log_title,
			{
				'url' => enc_url,
				'track_name' => repo_name
			}
		)
	end
end

#tokenObject



14
15
16
17
# File 'lib/commit-live/github.rb', line 14

def token
	netrc.read
	netrc.password
end