-
Notifications
You must be signed in to change notification settings - Fork 13
A logic to generate an empty plugin placeholder. #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "clamp" | ||
require "erb" | ||
require "octokit" | ||
require_relative "git_helper" | ||
|
||
class GeneratePluginPlaceholderDoc < Clamp::Command | ||
option "--output-path", "OUTPUT", "Path to a directory where logstash-docs repository is cloned and changes going to be written to", required: true | ||
option "--plugin-type", "STRING", "Type (ex: integration, input, etc) of a new plugin.", required: true | ||
option "--plugin-name", "STRING", "Name of the plugin.", required: true | ||
|
||
SUPPORTED_TYPES = %w(integration) | ||
|
||
def execute | ||
generate_placeholder(plugin_type, plugin_name) | ||
submit_pr | ||
end | ||
|
||
# adds an empty static page under the VPR | ||
# this helps us to eliminate broken link issues in the docs | ||
def generate_placeholder(type, name) | ||
if type.nil? || name.nil? | ||
$stderr.puts("Plugin type and name are required.") | ||
return | ||
end | ||
|
||
unless SUPPORTED_TYPES.include?(type) | ||
$stderr.puts("#{type} is not supported. Supported types are #{SUPPORTED_TYPES.inspect}") | ||
return | ||
end | ||
|
||
placeholder_asciidoc = "#{logstash_docs_path}/docs/versioned-plugins/#{type}s/#{name}-index.asciidoc" | ||
# changing template will fail to re-index the doc, do not change or keep consistent with VPR templates | ||
template = ERB.new(IO.read("logstash/templates/docs/versioned-plugins/plugin-index.asciidoc.erb")) | ||
content = template.result_with_hash(name: name, type: type, versions: []) | ||
File.write(placeholder_asciidoc, content) | ||
end | ||
|
||
def logstash_docs_path | ||
path = File.join(output_path, "logstash-docs") | ||
fail("#{path} doesn't exist. Please provide the path for `--output-path` where `logstash-docs` repo is located.") unless Dir.exist?(path) | ||
path | ||
end | ||
|
||
def submit_pr | ||
branch_name = "new_plugin_placeholder" | ||
git_helper = GitHelper.new("elastic/logstash-docs") | ||
if git_helper.branch_exists?(branch_name) | ||
puts "WARNING: Branch \"#{branch_name}\" already exists. Aborting creation of PR. Please merge the existing PR or delete the PR and the branch." | ||
return | ||
end | ||
|
||
pr_title = "A placeholder for new plugin" | ||
git_helper.commit(logstash_docs_path, branch_name, "create an empty placeholder for new plugin") | ||
git_helper.create_pull_request(branch_name, "versioned_plugin_docs", pr_title, "", { draft: true }) | ||
end | ||
end | ||
|
||
if __FILE__ == $0 | ||
GeneratePluginPlaceholderDoc.run | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "octokit" | ||
|
||
class GitHelper | ||
|
||
attr_reader :git_client, :repo_name | ||
|
||
def initialize(repo_name) | ||
print "not " if ENV.fetch("GITHUB_TOKEN", "").empty? | ||
puts "using a github token" | ||
|
||
@git_client = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"]) | ||
|
||
fail("Repo name cannot be null or empty") if repo_name.nil? || repo_name.empty? | ||
@repo_name = repo_name | ||
end | ||
|
||
def commit(repo_path, branch_name, commit_msg) | ||
puts "Committing changes..." | ||
Dir.chdir(repo_path) do |path| | ||
`git checkout -b #{branch_name}` | ||
`git add .` | ||
`git commit -m "#{commit_msg}" -a` | ||
`git push origin #{branch_name}` | ||
end | ||
end | ||
|
||
def create_pull_request(branch_name, against_branch, title, description, options = {}) | ||
puts "Creating a PR..." | ||
@git_client.create_pull_request(@repo_name, against_branch, branch_name, title, description, options) | ||
end | ||
|
||
def branch_exists?(branch_name) | ||
@git_client.branch(@repo_name, branch_name) | ||
true | ||
rescue Octokit::NotFound | ||
false | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.