commit-live-cli 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be81db24b2d7f33d3f9b7a9359e5a53a99698045
4
- data.tar.gz: 12e23e3064893b3a7c31436410c1b4518a7b316e
3
+ metadata.gz: 5191b44ad67fb9ca78c7f6510b80c63309719f92
4
+ data.tar.gz: 5a846a02dda610cc46ae5dc2e6f2b75f351ff451
5
5
  SHA512:
6
- metadata.gz: f4df041940c12845f2f9e54b7a47aaba40d7ccd13e081def97a7a63a05cd9f72b74d719a1f58ddceb04ee92ab75bd9e1178693c882d2e3b07d58b1c858d937fb
7
- data.tar.gz: eb728339f9e44a5299a917d078a5c70837e40cf0878cfe91090d3d1c4762495eb2b06571e01d0e20a153e944344ea89254c41fb087bacc47f3248664ceff085e
6
+ metadata.gz: 6932ea6b8953c2e72212ecca5fea53669337e059d91f079d685f973c1b4e48f227874118d8aeff471de66d12ac5d5364c030a34759e60effc64571669c87cda3
7
+ data.tar.gz: c12e0a098b32b132d11304bbc034be5322c797a58a3910f4f47386ece9f069a4ad26979d9e2f3bedc078d9397328f194b1cd1d8cd0c9130201f08dd71fa59c06
@@ -1,16 +1,76 @@
1
1
  require "commit-live/netrc-interactor"
2
+ require "commit-live/sentry"
3
+ require "commit-live/api"
2
4
  require "octokit"
3
5
 
4
6
  module CommitLive
5
7
  class Github
6
- attr_accessor :client
8
+ attr_accessor :netrc, :post_details, :sentry
7
9
  def initialize()
8
- netrc = CommitLive::NetrcInteractor.new()
9
- netrc.read
10
- token = netrc.password
11
- if !token.nil?
12
- @client = Octokit::Client.new(:access_token => token)
13
- end
10
+ @netrc = CommitLive::NetrcInteractor.new()
11
+ @sentry = CommitLive::Sentry.new()
12
+ end
13
+
14
+ def token
15
+ netrc.read
16
+ netrc.password
17
+ end
18
+
19
+ def owner
20
+ netrc.read(machine: 'ga-extra')
21
+ netrc.login
22
+ end
23
+
24
+ def getAttr(attr)
25
+ if !attr.nil?
26
+ post_details.fetch(attr)
27
+ end
28
+ end
29
+
30
+ def getValue(key)
31
+ data = getAttr('data')
32
+ data[key]
33
+ end
34
+
35
+ def post(repo_name, isFork = false)
36
+ enc_url = "/v2/github/createPullRequest"
37
+ log_title = "#{owner} - Pull Request Failed"
38
+ if isFork
39
+ enc_url = URI.escape("/v2/github/createFork")
40
+ log_title = "#{owner} - Lesson Forked Failed"
41
+ end
42
+ begin
43
+ Timeout::timeout(60) do
44
+ response = CommitLive::API.new().post(
45
+ enc_url,
46
+ headers: {
47
+ 'Authorization' => "#{token}",
48
+ 'Content-Type' => 'application/json'
49
+ },
50
+ body: {
51
+ "repoUrl": repo_name
52
+ }
53
+ )
54
+ @post_details = JSON.parse(response.body)
55
+ if response.status != 200 && !response.body.match(/A pull request already exists/)
56
+ sentry.log_message(log_title,
57
+ {
58
+ 'url' => enc_url,
59
+ 'repo_name' => repo_name,
60
+ 'response-body' => response.body,
61
+ 'response-status' => response.status
62
+ }
63
+ )
64
+ end
65
+ end
66
+ rescue Timeout::Error
67
+ sentry.log_message(log_title,
68
+ {
69
+ 'url' => enc_url,
70
+ 'track_name' => repo_name
71
+ }
72
+ )
73
+ end
14
74
  end
15
75
  end
16
76
  end
@@ -175,31 +175,8 @@ module CommitLive
175
175
 
176
176
  def createPullRequest
177
177
  puts 'Creating Pull Request...'
178
- userGithub = CommitLive::Github.new()
179
- netrc.read(machine: 'ga-extra')
180
- username = netrc.login
181
- begin
182
- Timeout::timeout(45) do
183
- pullRequest = userGithub.client.create_pull_request(
184
- repo_url,
185
- 'master',
186
- "#{username}:master",
187
- "#{track_slug} - PR by #{username}"
188
- )
189
- end
190
- rescue Octokit::Error => err
191
- if !err.message.match(/A pull request already exists/)
192
- sentry.log_exception(err,
193
- {
194
- 'event': 'creating-pull-request',
195
- 'lesson_name' => lessonName,
196
- }
197
- )
198
- end
199
- rescue Timeout::Error
200
- puts "Please check your internet connection."
201
- exit 1
202
- end
178
+ github = CommitLive::Github.new()
179
+ github.post(repo_url)
203
180
  end
204
181
 
205
182
  def repo_name(remote: remote_name)
@@ -9,7 +9,7 @@ require "oj"
9
9
 
10
10
  module CommitLive
11
11
  class Open
12
- attr_reader :rootDir, :lesson, :forkedRepo, :lesson_status, :sentry
12
+ attr_reader :rootDir, :lesson, :forked_ssh_url, :lesson_status, :sentry
13
13
 
14
14
  HOME_DIR = File.expand_path("~")
15
15
  ALLOWED_TYPES = ["CODE", "PRACTICE"]
@@ -27,7 +27,7 @@ module CommitLive
27
27
  if lesson_type === "PRACTICE"
28
28
  "git@github.com:#{lesson_repo}.git"
29
29
  else
30
- forkedRepo.ssh_url
30
+ forked_ssh_url
31
31
  end
32
32
  end
33
33
 
@@ -99,21 +99,8 @@ module CommitLive
99
99
  def forkCurrentLesson
100
100
  puts "Forking lesson..."
101
101
  github = CommitLive::Github.new()
102
- begin
103
- Timeout::timeout(15) do
104
- @forkedRepo = github.client.fork(lesson_repo)
105
- end
106
- rescue Octokit::Error => err
107
- sentry.log_exception(err,
108
- {
109
- 'event': 'forking',
110
- 'lesson_name' => lesson_name,
111
- }
112
- )
113
- rescue Timeout::Error
114
- puts "Please check your internet connection."
115
- exit
116
- end
102
+ github.post(lesson_repo, true)
103
+ @forked_ssh_url = github.getValue("sshUrl")
117
104
  end
118
105
 
119
106
  def cloneCurrentLesson
@@ -1,5 +1,5 @@
1
1
  module CommitLive
2
2
  module Cli
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commit-live-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - greyatom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-30 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler