devcenter 1.1.0rc1 → 1.1.0rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 592c9194f39d3e37bf58ec40370e83df3f157c14
4
- data.tar.gz: d2f34c3bdf1ac94219fd567a821e01b98306aeff
3
+ metadata.gz: 1d403c3e7157b49680864b829b6aab2c6426da2f
4
+ data.tar.gz: 9de7f63f1e099b45b62e38620c1f515e09ae7021
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: f7ec004380727c6a826b2a8efab3610b5704734fdbb09054b3419c315eac0aa7fe6d7cf5a8a88078afbf722cfd5b09642edba40325dd4e7988b118ace13e12f2
7
- data.tar.gz: 001e0ec246f33908a0632579efb6f55d20905d2a74558ca4bef740a6d514d264fac6c94a70433d7e5618a75139d80082f1c5a5e785124b27a4d73f67e19e9691
6
+ metadata.gz: cd23a4e4416512cee66e406348456ade33641d22850559d03b54018ec3b7997008cdae278835d6f7ba880cab5eab5498f3c1e27f18a1dff4c4858952b4c055f0
7
+ data.tar.gz: f1f7ef0ad66419c3eea4ad748d3d5ba39d9332339623f2e606b5abc8a14f80924acae5753ad810215dfefc2cb89749f28c2d8e684fa640837288a7b9690a6653
data/README.md CHANGED
@@ -34,7 +34,7 @@ This will open a preview in your default browser and get it refreshed when you s
34
34
 
35
35
  $ devcenter push dynos
36
36
 
37
- This will save the title and content from your local article in Dev Center. You'll be asked to authenticate to verify that you have permissions to update the article.
37
+ This will save the title and content from your local article in Dev Center, using your Heroku credentials from `~/.netrc`, which you can set by doing `heroku auth:login`.
38
38
 
39
39
  ### Help
40
40
 
@@ -29,4 +29,5 @@ Gem::Specification.new do |gem|
29
29
  gem.add_runtime_dependency('tilt', '~>1.3.3')
30
30
  gem.add_runtime_dependency('rack-highlighter', '~>0.2.0')
31
31
  gem.add_runtime_dependency('devcenter-parser', '~>1.3.4')
32
+ gem.add_runtime_dependency('netrc', '~>0.7.7')
32
33
  end
@@ -49,6 +49,11 @@ module Devcenter
49
49
  auth_request(:put, token, path: update_article_path(article_id), body: form, :headers => { "Content-Type" => "application/x-www-form-urlencoded" })
50
50
  end
51
51
 
52
+ def check_broken_links(token, content, parser)
53
+ form = URI.encode_www_form({content: content, parser: parser})
54
+ auth_request(:post, token, path: broken_link_checks_path, body: form, :headers => { "Content-Type" => "application/x-www-form-urlencoded" })
55
+ end
56
+
52
57
  def response(request_call)
53
58
  Response.new request_call
54
59
  end
@@ -23,18 +23,12 @@ module Devcenter::Commands
23
23
  if @article.parsing_error
24
24
  abort "The content of #{@md_path} can't be parsed properly, fix it and try again."
25
25
  end
26
- say 'Authenticate with your Heroku account:'
27
- email = ask('Email: ')
28
- password = ask('Password: ') { |q| q.echo = '*' }
29
- response = Devcenter::Client.get_oauth_token(email, password)
30
- if response.access_denied?
31
- abort "Authentication error: bad credentials. Please try again."
32
- elsif response.ok?
33
- token = response.body['access_token']['token']
34
- push_article(token) if validate_article(token)
35
- else
36
- abort "Authentication error: #{response.body['message']}"
37
- end
26
+ if token = get_oauth_token
27
+ display_broken_links(token)
28
+ if validate_article(token)
29
+ push_article(token)
30
+ end
31
+ end
38
32
  end
39
33
 
40
34
  def validate_article(token)
@@ -47,14 +41,22 @@ module Devcenter::Commands
47
41
  response = Devcenter::Client.validate_article(token, article_id, article_params)
48
42
  errors = response.body
49
43
  if errors.any?
50
- say "The article \"#{@slug}\" is not valid:"
44
+ say "The article \"#{@slug}\" can't be saved:"
51
45
  abort errors.to_yaml.gsub(/\A(\-+)\n-/, '')
52
- else
53
- say "The article \"#{@slug}\" is valid."
54
46
  end
55
47
  errors.empty?
56
48
  end
57
49
 
50
+ def display_broken_links(token)
51
+ response = Devcenter::Client.check_broken_links(token, @article.content, @article.metadata.markdown_flavour)
52
+ broken_links = response.body
53
+ if broken_links.any?
54
+ say "The article \"#{@slug}\" contains broken link/s:"
55
+ broken_links.each{ |link| say("- [#{link['text']}](#{link['url']})") }
56
+ say "\n"
57
+ end
58
+ end
59
+
58
60
  def push_article(token)
59
61
  article_id = @article.metadata.id
60
62
  article_params = {
@@ -64,11 +66,11 @@ module Devcenter::Commands
64
66
  }
65
67
  response = Devcenter::Client.update_article(token, article_id, article_params)
66
68
  if response.ok?
67
- say "\"#{@slug}\" pushed successfully."
69
+ say "\"Article #{@slug}\" pushed successfully."
68
70
  else
69
71
  error = response.body['error']
70
72
  abort "Error pushing \"#{@slug}\": #{error}"
71
73
  end
72
- end
74
+ end
73
75
  end
74
76
  end
@@ -1,9 +1,15 @@
1
+ require 'netrc'
2
+
1
3
  module Devcenter::Helpers
2
4
 
3
5
  def devcenter_base_url
4
6
  ENV['DEVCENTER_BASE_URL'] || 'https://devcenter.heroku.com'
5
7
  end
6
8
 
9
+ def broken_link_checks_path
10
+ '/api/v1/private/broken-link-checks.json'
11
+ end
12
+
7
13
  def article_path(slug)
8
14
  "/articles/#{slug}"
9
15
  end
@@ -47,4 +53,11 @@ module Devcenter::Helpers
47
53
  File.open(filename, 'w'){ |f| f.write(content) }
48
54
  end
49
55
 
56
+ def get_oauth_token
57
+ netrc = Netrc.read
58
+ user, token = netrc['api.heroku.com']
59
+ abort 'Heroku credentials not found. Execute "heroku login" to create them.' unless token
60
+ token
61
+ end
62
+
50
63
  end
@@ -1,3 +1,3 @@
1
1
  module Devcenter
2
- VERSION = "1.1.0rc1"
2
+ VERSION = "1.1.0rc2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devcenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0rc1
4
+ version: 1.1.0rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raul Murciano
@@ -193,6 +193,20 @@ dependencies:
193
193
  - - ~>
194
194
  - !ruby/object:Gem::Version
195
195
  version: 1.3.4
196
+ - !ruby/object:Gem::Dependency
197
+ name: netrc
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ~>
201
+ - !ruby/object:Gem::Version
202
+ version: 0.7.7
203
+ type: :runtime
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ~>
208
+ - !ruby/object:Gem::Version
209
+ version: 0.7.7
196
210
  description: CLI to interact with Heroku's Dev Center
197
211
  email:
198
212
  - raul@heroku.com