1
+ require "clamp"
2
+ require "erb"
3
+ require "octokit"
4
+ require_relative "git_helper"
5
+
6
+ class GeneratePluginPlaceholderDoc < Clamp ::Command
7
+ option "--output-path" , "OUTPUT" , "Path to a directory where logstash-docs repository is cloned and changes going to be written to" , required : true
8
+ option "--plugin-type" , "STRING" , "Type (ex: integration, input, etc) of a new plugin." , required : true
9
+ option "--plugin-name" , "STRING" , "Name of the plugin." , required : true
10
+
11
+ SUPPORTED_TYPES = %w( integration )
12
+
13
+ def execute
14
+ generate_placeholder ( plugin_type , plugin_name )
15
+ submit_pr
16
+ end
17
+
18
+ # adds an empty static page under the VPR
19
+ # this helps us to eliminate broken link issues in the docs
20
+ def generate_placeholder ( type , name )
21
+ if type . nil? || name . nil?
22
+ $stderr. puts ( "Plugin type and name are required." )
23
+ return
24
+ end
25
+
26
+ unless SUPPORTED_TYPES . include? ( type )
27
+ $stderr. puts ( "#{ type } is not supported. Supported types are #{ SUPPORTED_TYPES . inspect } " )
28
+ return
29
+ end
30
+
31
+ placeholder_asciidoc = "#{ logstash_docs_path } /docs/versioned-plugins/#{ type } s/#{ name } -index.asciidoc"
32
+ # changing template will fail to re-index the doc, do not change or keep consistent with VPR templates
33
+ template = ERB . new ( IO . read ( "logstash/templates/docs/versioned-plugins/plugin-index.asciidoc.erb" ) )
34
+ content = template . result_with_hash ( name : name , type : type , versions : [ ] )
35
+ File . write ( placeholder_asciidoc , content )
36
+ end
37
+
38
+ def logstash_docs_path
39
+ path = File . join ( output_path , "logstash-docs" )
40
+ fail ( "#{ path } doesn't exist. Please provide the path for `--output-path` where `logstash-docs` repo is located." ) unless Dir . exist? ( path )
41
+ path
42
+ end
43
+
44
+ def submit_pr
45
+ branch_name = "new_plugin_placeholder"
46
+ git_helper = GitHelper . new ( "elastic/logstash-docs" )
47
+ if git_helper . branch_exists? ( branch_name )
48
+ puts "WARNING: Branch \" #{ branch_name } \" already exists. Aborting creation of PR. Please merge the existing PR or delete the PR and the branch."
49
+ return
50
+ end
51
+
52
+ pr_title = "A placeholder for new plugin"
53
+ git_helper . commit ( logstash_docs_path , branch_name , "create an empty placeholder for new plugin" )
54
+ git_helper . create_pull_request ( branch_name , "versioned_plugin_docs" , pr_title , "" , { draft : true } )
55
+ end
56
+ end
57
+
58
+ if __FILE__ == $0
59
+ GeneratePluginPlaceholderDoc . run
60
+ end
0 commit comments