sync_readme 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: 6ba1afc35004193ffabf9193ee396e6f53e4a4a5
4
- data.tar.gz: 9f89d7cb5e2aaf0e4970f6fd7949184c5f0cfc51
3
+ metadata.gz: 5aae0ad2a0988f1ab3b183584b9c3be86c5bc013
4
+ data.tar.gz: 44f347b0583e8d4ca3d1747c7937771f88e5ae8c
5
5
  SHA512:
6
- metadata.gz: caa4072c8f7e3e41dbaabe1de190edaa4942d38c293bbb9e45bc9b735c799dd2210d421d525cfd48097996354a99275184eae1f0919b7f7d9d8d4bc51e5918fc
7
- data.tar.gz: 0ff87c4d310577499a9b5aa7dbc0199437b5e5d3cd39440c6203830cd7f09ffba39965f0006d341ca542a60ec3ded04684dde2f5e648cfb714796c46d7dd85b8
6
+ metadata.gz: 5e9b679d27ee036868e06633687a98091d39ef8d2156ccb4751ae5286211cdd8889709edc0e7a864e839a68c27854e2670e185a82c1bfde5272d674b50f1021c
7
+ data.tar.gz: 5d17aadfbc0335682eeec7917700ba87d4f67dd18f73a530beda3312b5f036b0834650cb708d722111302d271e61916fe0b37118eca21c710ca11e99f3b6d8a1
data/README.md CHANGED
@@ -27,26 +27,33 @@ readme:
27
27
  url: http://confluence.url.here # required
28
28
  page_id: 123456 # required
29
29
  filename: Readme.md # required
30
- username: foo # optional, generally better as an environment variable
31
- password: bar # optional, generally better as an environment variable
30
+ username: foo # optional, can be prompted for or put in an environment variable
31
+ password: bar # optional, can be prompted for or put in an environment variable
32
32
  notice: this file is sync'd! # optional, adds the notice (as html) to the top of the confluance docs
33
33
  strip_title: false # optional, defaults false, strips the first h1 (#) tag from the file
34
- syntax_highlighting: true # optional, defaults true, uses coderay sytax highlighting on code blocks
34
+ syntax_highlighting: true # optional, defaults true, uses coderay syntax highlighting on code blocks
35
35
  ```
36
36
 
37
- You'll also need to set environment variables with credentials to update the page in question:
37
+ You can also set the following in your environment (ex: continuous integration) to store credentials:
38
38
 
39
39
  ```
40
40
  CONFLUENCE_USERNAME=jsmith
41
41
  CONFLUENCE_PASSWORD=$UPER $ECURE PA$$WORD
42
42
  ```
43
43
 
44
+ The Atlassian Cloud supports [API tokens](https://confluence.atlassian.com/cloud/api-tokens-938839638.html), which can be used for `CONFLUENCE_PASSWORD`
45
+
46
+ If credentials are not stored anywhere, they are prompted for at run time.
47
+
44
48
  ## Usage
45
49
  ```
46
- sync_readme [configuration]
50
+ sync_readme [options] [profile]
51
+ -u, --user=username Confluence username
52
+ -a, --all Run all configured syncronizations
53
+ -h, --help Show help
47
54
  ```
48
55
 
49
- ## Adding to Gitlab-CI
56
+ ## Using in Gitlab-CI
50
57
 
51
58
  1. Create a confluence user specifically to sync with
52
59
  2. If you haven't already, create the pages you want to sync to on confluence and get their IDs.
@@ -54,13 +61,14 @@ sync_readme [configuration]
54
61
  4. Add `gem 'sync_readme'` to your apps gemfile
55
62
  5. Set `CONFLUENCE_USERNAME` and `CONFLUENCE_PASSWORD` as CI Variables.
56
63
  6. Add the following job to your .gitlab-ci.yml
57
- ``` yaml
58
- Sync To Confluence:
59
- stage: update_docs # Replace that with the stage you want this to run
60
- only: master # Only run on master branch probably after you deploy
61
- script:
62
- - bundle exec sync_readme --all # Alternately just the profile you want to run
63
- ```
64
+
65
+ ```yaml
66
+ Sync To Confluence:
67
+ stage: update_docs # Replace that with the stage you want this to run
68
+ only: master # Only run on master branch probably after you deploy
69
+ script:
70
+ - bundle exec sync_readme --all # Alternately just the profile you want to run
71
+ ```
64
72
 
65
73
  ## Development
66
74
 
@@ -1,15 +1,15 @@
1
1
  require 'yaml'
2
-
3
2
  module SyncReadme
4
3
  class Config
5
4
  DEFAULT_CONFIG_FILE = File.join(Dir.pwd, '.sync_readme.yml')
6
- NO_CONFIGURATION_ERROR = "this profile has not been configured, please add it to #{DEFAULT_CONFIG_FILE}".freeze
5
+ NO_CONFIGURATION_ERROR = SyncReadme::NoConfigurationError.new("this profile has not been configured, please add it to #{DEFAULT_CONFIG_FILE}".freeze)
7
6
 
8
7
  def self.profiles(config_file = DEFAULT_CONFIG_FILE)
9
8
  YAML.load_file(config_file).keys.select { |key| key != 'default' }
10
9
  end
11
10
 
12
11
  def self.default(config_file = DEFAULT_CONFIG_FILE)
12
+ raise NO_CONFIGURATION_ERROR unless File.exists?(config_file)
13
13
  default = YAML.load_file(config_file)['default']
14
14
  unless default
15
15
  profiles = SyncReadme::Config.profiles(config_file)
@@ -19,13 +19,13 @@ module SyncReadme
19
19
  end
20
20
 
21
21
  def get_page
22
- response = @client.get("/rest/api/content/#{@page_id}", expand: 'body.view,version')
22
+ response = @client.get("rest/api/content/#{@page_id}", expand: 'body.view,version')
23
23
  JSON.parse(response.body)
24
24
  end
25
25
 
26
26
  def update(params)
27
27
  @client.put do |request|
28
- request.url "/rest/api/content/#{@page_id}"
28
+ request.url "rest/api/content/#{@page_id}"
29
29
  request.headers['Content-Type'] = 'application/json'
30
30
  request.body = params.to_json
31
31
  end
@@ -0,0 +1,7 @@
1
+ module SyncReadme
2
+
3
+ class Error < RuntimeError
4
+ end
5
+ class NoConfigurationError < Error
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module SyncReadme
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
data/lib/sync_readme.rb CHANGED
@@ -1,9 +1,11 @@
1
+ require 'sync_readme/errors'
1
2
  require 'sync_readme/config'
2
3
  require 'sync_readme/confluence_sync'
3
4
  require 'sync_readme/reader'
4
5
  require 'sync_readme/version'
5
6
  require 'optparse'
6
7
  require 'dotenv'
8
+ require 'highline/import'
7
9
 
8
10
  Dotenv.load
9
11
 
@@ -11,13 +13,26 @@ module SyncReadme
11
13
  def self.invoke(args)
12
14
  options = {}
13
15
  OptionParser.new do |opts|
14
- opts.banner = "Usage: sync_readme [options] [profile]"
16
+ opts.banner = 'Usage: sync_readme [options] [profile]'
15
17
 
16
- opts.on("-a", "--all", "Run verbosely") do
18
+ opts.on('-u', '--user=username', String, 'Confluence username') do |user|
19
+ ENV['CONFLUENCE_USERNAME'] = user
20
+ ENV['CONFLUENCE_PASSWORD'] = ask("Password for #{user}: ") { |q| q.echo = false }
21
+ end
22
+
23
+ opts.on('-a', '--all', 'Run all configured syncronizations') do
17
24
  options[:all] = true
18
25
  end
26
+
27
+ opts.on_tail('-h', '--help', 'Show help') do
28
+ puts opts
29
+ exit
30
+ end
19
31
  end.parse!(args)
20
32
 
33
+ ENV['CONFLUENCE_USERNAME'] ||= ask("Confluence username: ")
34
+ ENV['CONFLUENCE_PASSWORD'] ||= ask("Password for #{ENV['CONFLUENCE_USERNAME']}: ") { |q| q.echo = false }
35
+
21
36
  default_profile = SyncReadme::Config.default
22
37
 
23
38
  if options[:all] || (args.empty? && default_profile.nil?)
@@ -29,6 +44,10 @@ module SyncReadme
29
44
  else
30
45
  SyncReadme.perform(args.last)
31
46
  end
47
+
48
+ rescue SyncReadme::Error => sre
49
+ STDERR.puts sre.message
50
+ exit 1
32
51
  end
33
52
 
34
53
  def self.perform(profile)
data/sync_readme.gemspec CHANGED
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency 'faraday', '~> 0.11'
23
23
  spec.add_dependency 'kramdown', '~> 1.13'
24
- spec.add_dependency 'dotenv', '~> 2.1.2'
24
+ spec.add_dependency 'dotenv', '~> 2'
25
+ spec.add_dependency 'highline', '~> 1'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.12'
27
28
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync_readme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Ives
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.2
47
+ version: '2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.2
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: highline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +159,7 @@ files:
145
159
  - lib/sync_readme.rb
146
160
  - lib/sync_readme/config.rb
147
161
  - lib/sync_readme/confluence_sync.rb
162
+ - lib/sync_readme/errors.rb
148
163
  - lib/sync_readme/reader.rb
149
164
  - lib/sync_readme/version.rb
150
165
  - sync_readme.gemspec