dbdoc 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 35a675eef6484bf4c2c6bb78521c9f322ff057804feec72e34061eb899153352
4
- data.tar.gz: 5e80744c319d0e2ea77b321704e317467e871e9d93a53ad77871c655106b8f3b
3
+ metadata.gz: 95d1967a75eb0505c9dd74882fcc2fa18127b464d2358f4fe83bfb803a3291c9
4
+ data.tar.gz: 655b2bf4f41c4c05e4709ec44611af42e9f529daa9891617529c131a095c6968
5
5
  SHA512:
6
- metadata.gz: b49a2edb0d2e31280b4bd8ed29ef109da6ff38fd6669df30a260f049ad5ad841bea5425d3c68fd9862f8e74116f4cbcb90e767f69e44aeed2c0910429ba13ac1
7
- data.tar.gz: 18b09c76bc60de2ffb1a574a9695d03b1be0ba5c40b3bedbeb2d59eaefbd4b431b4a370ea52cb46defb34a388b9a177e2dd6c4496e7a78bdf1c3d7ed0d607a82
6
+ metadata.gz: 65386544fb68b47f56121ab291b86b0bbb0d462c35692e40d223faaaa56b7accc2cf401438001ddf9fb1aab01fb80f51fb28aededa4653f4ff5da41435b65e13
7
+ data.tar.gz: da90433a70497544484e32bacd6806ea166b64f7cd9cf90f1111da06d9c14c90c582dc9fb7890094bea272dff25fc3033261b22f16c623c8b204b3a2b787b6da
@@ -0,0 +1,2 @@
1
+ github: makaroni4
2
+ ko_fi: makaroni4
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem "httparty"
6
+ gem "kramdown"
6
7
 
7
8
  group :development do
8
9
  gem "byebug"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dbdoc (0.1.0)
4
+ dbdoc (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -20,6 +20,8 @@ GEM
20
20
  mime-types (~> 3.0)
21
21
  multi_xml (>= 0.5.2)
22
22
  json (2.3.1)
23
+ kramdown (2.3.0)
24
+ rexml
23
25
  mime-types (3.3.1)
24
26
  mime-types-data (~> 3.2015)
25
27
  mime-types-data (3.2020.0512)
@@ -77,6 +79,7 @@ DEPENDENCIES
77
79
  coveralls
78
80
  dbdoc!
79
81
  httparty
82
+ kramdown
80
83
  rake (~> 12.0)
81
84
  rspec (~> 3.0)
82
85
  rubocop
data/README.md CHANGED
@@ -40,7 +40,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
40
40
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
41
 
42
42
  ```
43
- gem uninstall dbdoc && gem build dbdoc.gemspec && bundle && rake build && rake install && dbdoc help
43
+ Y | gem uninstall dbdoc && gem build dbdoc.gemspec && bundle && rake build && rake install && dbdoc help
44
+ ```
45
+
46
+ ```
47
+ Y | gem uninstall dbdoc && gem build dbdoc.gemspec && bundle && rake build && rake release
44
48
  ```
45
49
 
46
50
  ## Contributing
@@ -1,4 +1,4 @@
1
- ||Name||Type||Description||
1
+ ||Name||Type||Foreign Key||Description||
2
2
  <%- columns.each do |column| -%>
3
- |<%= column[:name] %>|<%= column[:type] %>|<%= column[:description].strip %>|
3
+ |<%= column[:name] %>|<%= column[:type] %>|<%= column[:foreign_key] || " " %>|<%= column[:description].strip %>|
4
4
  <%- end -%>
@@ -3,6 +3,7 @@
3
3
  - :name: <%= name %>
4
4
  :type: <%= type %>
5
5
  :position: <%= position %>
6
+ :foreign_key: TODO
6
7
  :description: |
7
8
  TODO
8
9
  <%- end -%>
@@ -1 +1,5 @@
1
- Write table description here
1
+ This is a table description in a normal Markdown.
2
+
3
+ This is **bold**.
4
+
5
+ This is *italic*.
@@ -1,10 +1,8 @@
1
- h3. Count all users
1
+ ### How to count all users
2
2
 
3
3
  Use this query to count all user records:
4
4
 
5
- (!) This is a warning note.
6
-
7
- {code:language=sql}
5
+ ~~~sql
8
6
  SELECT COUNT(*)
9
7
  FROM users
10
- {code}
8
+ ~~~
@@ -18,7 +18,7 @@ module Confluence
18
18
  end
19
19
 
20
20
  def delete_page(page_id:)
21
- HTTParty.delete(
21
+ response = HTTParty.delete(
22
22
  "https://dbdoc.atlassian.net/wiki/rest/api/content/#{page_id}", {
23
23
  headers: {
24
24
  "Authorization" => "Basic #{basic_auth}",
@@ -26,9 +26,12 @@ module Confluence
26
26
  }
27
27
  }
28
28
  )
29
+
30
+ response.code == 200
29
31
  end
30
32
 
31
33
  def existing_pages
34
+ # TODO: paginate over all pages in the space
32
35
  response = HTTParty.get(
33
36
  "https://dbdoc.atlassian.net/wiki/rest/api/content/?&spaceKey=#{@space}", {
34
37
  headers: {
@@ -0,0 +1,87 @@
1
+ require "kramdown"
2
+
3
+ module Confluence
4
+ class MarkdownConverter
5
+ CONVERTERS = %w(
6
+ convert_h1
7
+ convert_h2
8
+ convert_h3
9
+ convert_h4
10
+ convert_h5
11
+ convert_bold
12
+ convert_italic
13
+ convert_code
14
+ convert_unordered_list
15
+ )
16
+
17
+ def convert(original_markdown)
18
+ return if original_markdown.nil?
19
+
20
+ output = original_markdown
21
+
22
+ CONVERTERS.each do |converter_method|
23
+ output = send(converter_method, output)
24
+ end
25
+
26
+ output
27
+ end
28
+
29
+ private
30
+
31
+ def convert_h1(markdown)
32
+ markdown.gsub(/^(#)([^#].+)$/, 'h1.\2')
33
+ end
34
+
35
+ def convert_h2(markdown)
36
+ markdown.gsub(/^(##)([^\#].+)$/, 'h2.\2')
37
+ end
38
+
39
+ def convert_h3(markdown)
40
+ markdown.gsub(/^(###)([^\#].+)$/, 'h3.\2')
41
+ end
42
+
43
+ def convert_h4(markdown)
44
+ markdown.gsub(/^(####)([^\#].+)$/, 'h4.\2')
45
+ end
46
+
47
+ def convert_h5(markdown)
48
+ markdown.gsub(/^(#####)([^\#].+)$/, 'h5.\2')
49
+ end
50
+
51
+ def convert_bold(markdown)
52
+ markdown.gsub(/(\*\*)(\w+)(\*\*)/, '*\2*')
53
+ end
54
+
55
+ def convert_italic(markdown)
56
+ markdown.gsub(/(\*)(\w+)(\*)/, '_\2_')
57
+ end
58
+
59
+ def convert_code(markdown)
60
+ output_lines = []
61
+
62
+ markdown.each_line do |line|
63
+ if line =~ /^\~{3}\w+$/
64
+ language = line.gsub("~~~", "").strip
65
+
66
+ output_lines.push("{code:language=#{language}}\n")
67
+ elsif line =~ /^\~{3}$/
68
+ output_lines.push("{code}")
69
+ else
70
+ output_lines.push(line)
71
+ end
72
+ end
73
+
74
+ output_lines.join
75
+ end
76
+
77
+ def convert_unordered_list(markdown)
78
+ markdown.gsub(/^\*\s(.+)$/, '- \1')
79
+ end
80
+
81
+ # TODO: add nested list convertion
82
+ # TODO: add numbered list convertion
83
+
84
+ # TODO :add emoji
85
+ # https://support.atlassian.com/confluence-cloud/docs/use-symbols-emojis-and-special-characters/
86
+ end
87
+ end
@@ -77,7 +77,24 @@ module Dbdoc
77
77
  uploader.upload
78
78
 
79
79
  0
80
- elsif args.first == "clear_confluence_space"
80
+ elsif args.first == "existing_pages"
81
+ options = extract_options(args)
82
+
83
+ config = Dbdoc::Config.load
84
+ config.merge!(options)
85
+
86
+ uploader = Dbdoc::Uploader.new(config: config)
87
+ pages = uploader.space_pages
88
+
89
+ pages.each do |page|
90
+ page_title = page["title"]
91
+ page_id = page["id"]
92
+
93
+ puts "#{page_title}: #{page_id}"
94
+ end
95
+
96
+ 0
97
+ elsif args.first == "clear_space"
81
98
  options = extract_options(args)
82
99
 
83
100
  config = Dbdoc::Config.load
@@ -86,6 +103,16 @@ module Dbdoc
86
103
  uploader = Dbdoc::Uploader.new(config: config)
87
104
  uploader.clear_confluence_space
88
105
 
106
+ 0
107
+ elsif args.first == "todo"
108
+ options = extract_options(args)
109
+
110
+ config = Dbdoc::Config.load
111
+ config.merge!(options)
112
+
113
+ manager = Dbdoc::Manager.new(config: config)
114
+ manager.todo
115
+
89
116
  0
90
117
  elsif args.first == "help"
91
118
  puts "--> SOME HELP"
@@ -24,6 +24,24 @@ module Dbdoc
24
24
  pp current_schema - input_schema
25
25
  end
26
26
 
27
+ def todo
28
+ doc_folder_files = File.join(Dir.pwd, "doc", "**/*")
29
+
30
+ Dir[doc_folder_files].each do |file|
31
+ next if file == "."
32
+ next if file == ".."
33
+ next if File.directory?(file)
34
+
35
+ File.read(file).split("\n").each_with_index do |line, i|
36
+ if line.include?("TODO")
37
+ relative_path = file.gsub(Dir.pwd, "")
38
+
39
+ puts "#{relative_path}:#{i + 1}"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
27
45
  def apply(path: Dir.pwd, verbose: true)
28
46
  puts "--> APPLY"
29
47
  puts
@@ -1,4 +1,5 @@
1
1
  require "dbdoc/constants"
2
+ require_relative "../confluence/markdown_converter"
2
3
  require_relative "../confluence/api"
3
4
 
4
5
  module Dbdoc
@@ -14,10 +15,23 @@ module Dbdoc
14
15
  delete_pages_for_dropped_schemas_or_tables
15
16
  end
16
17
 
18
+ def space_pages
19
+ @confluence_api.existing_pages["results"]
20
+ end
21
+
17
22
  def clear_confluence_space
18
- # TODO paginate and fetch all Confluence pages
19
- # TODO ask user to Yn if they want to proceed with deletion
20
- # TODO iterate over each page_id, unlog it from page_ids.yml and @confluence_api.delete_page(page_id:)
23
+ uploaded_pages = YAML.load(File.read(page_ids_file))
24
+
25
+ space_pages.each do |page|
26
+ page_key = page["title"]
27
+ page_id = page["id"]
28
+
29
+ puts "--> Deleting #{page_key} #{page_id}"
30
+
31
+ if @confluence_api.delete_page(page_id: page_id)
32
+ unlog_page_id(key: page_key)
33
+ end
34
+ end
21
35
  end
22
36
 
23
37
  private
@@ -162,13 +176,17 @@ module Dbdoc
162
176
  end
163
177
  end
164
178
 
179
+ def markdown(input)
180
+ Confluence::MarkdownConverter.new.convert(input)
181
+ end
182
+
165
183
  def upload_table(schema_name:, table_name:, schema_page_id:)
166
184
  table_folder = File.join(@doc_folder, schema_name, table_name)
167
185
 
168
- table_description = File.read(File.join(table_folder, "description.md"))
186
+ table_description = markdown(File.read(File.join(table_folder, "description.md")))
169
187
 
170
188
  examples_folder = File.join(table_folder, "examples")
171
- table_examples = Dir[File.join(examples_folder, "*.md")].map { |f| File.read(f) }
189
+ table_examples = Dir[File.join(examples_folder, "*.md")].map { |f| File.read(f) }.map { |example| markdown(example) }
172
190
 
173
191
  columns_markdown_template_file = File.join(DBDOC_HOME, "doc_files", "columns.md.erb")
174
192
 
@@ -177,8 +195,14 @@ module Dbdoc
177
195
  nil,
178
196
  "-"
179
197
  )
198
+
199
+ columns_doc = YAML.load(File.read(File.join(table_folder, "columns.yml")))
200
+ columns_doc.each do |col|
201
+ col[:description] = markdown(col[:description])
202
+ end
203
+
180
204
  columns_table = columns_table_template.result_with_hash({
181
- columns: YAML.load(File.read(File.join(table_folder, "columns.yml")))
205
+ columns: columns_doc
182
206
  })
183
207
 
184
208
  page_body = <<-MARKDOWN
@@ -1,3 +1,3 @@
1
1
  module Dbdoc
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoli Makarevich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Dbdoc is a tool to keep your database documentation up-to-date and version
14
14
  controlled.
@@ -19,6 +19,7 @@ executables:
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - ".github/FUNDING.yml"
22
23
  - ".gitignore"
23
24
  - ".rspec"
24
25
  - ".rubocop.yml"
@@ -43,6 +44,7 @@ files:
43
44
  - doc_files/table_description.md
44
45
  - doc_files/table_example.md
45
46
  - lib/confluence/api.rb
47
+ - lib/confluence/markdown_converter.rb
46
48
  - lib/dbdoc.rb
47
49
  - lib/dbdoc/cli.rb
48
50
  - lib/dbdoc/config.rb