-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add -t option to populate managed modules using GitHub's repository topics #158
Open
joestump
wants to merge
3
commits into
voxpupuli:master
Choose a base branch
from
joestump:jstump-github-topics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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
This file contains 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 |
---|---|---|
|
@@ -11,11 +11,19 @@ | |
require 'monkey_patches' | ||
|
||
GITHUB_TOKEN = ENV.fetch('GITHUB_TOKEN', '') | ||
GITHUB_ORGANIZATION = ENV.fetch('GITHUB_ORGANIZATION', '') | ||
|
||
Octokit.configure do |c| | ||
c.api_endpoint = ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com') | ||
c.auto_paginate = true | ||
|
||
# We use a different Accept header by default here so we can get access | ||
# to the developer's preview that enables repository topics. | ||
c.default_media_type = ::Octokit::Preview::PREVIEW_TYPES[:topics] | ||
end | ||
|
||
GITHUB = Octokit::Client.new(:access_token => GITHUB_TOKEN) | ||
|
||
module ModuleSync | ||
include Constants | ||
|
||
|
@@ -50,8 +58,16 @@ def self.module_files(local_files, path) | |
local_files.map { |file| file.sub(/#{path}/, '') } | ||
end | ||
|
||
def self.managed_modules(config_file, filter, negative_filter) | ||
managed_modules = Util.parse_config(config_file) | ||
def self.managed_modules(config_file, filter, negative_filter, topic) | ||
if topic | ||
managed_modules = [] | ||
GITHUB.org_repos(GITHUB_ORGANIZATION).each do |repo| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if |
||
managed_modules.push(repo.name) if repo.topics.include?(topic) | ||
end | ||
else | ||
managed_modules = Util.parse_config(config_file) | ||
end | ||
|
||
if managed_modules.empty? | ||
puts "No modules found in #{config_file}. Check that you specified the right :configs directory and :managed_modules_conf file." | ||
exit | ||
|
@@ -133,8 +149,7 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op | |
# We only do GitHub PR work if the GITHUB_TOKEN variable is set in the environment. | ||
repo_path = "#{namespace}/#{module_name}" | ||
puts "Submitting PR '#{options[:pr_title]}' on GitHub to #{repo_path} - merges #{options[:branch]} into master" | ||
github = Octokit::Client.new(:access_token => GITHUB_TOKEN) | ||
pr = github.create_pull_request(repo_path, 'master', options[:branch], options[:pr_title], options[:message]) | ||
pr = GITHUB.create_pull_request(repo_path, 'master', options[:branch], options[:pr_title], options[:message]) | ||
puts "PR created at #{pr['html_url']}" | ||
|
||
# PR labels can either be a list in the YAML file or they can pass in a comma | ||
|
@@ -145,7 +160,7 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op | |
# already exist. We DO NOT create missing labels. | ||
unless pr_labels.empty? | ||
puts "Attaching the following labels to PR #{pr['number']}: #{pr_labels.join(', ')}" | ||
github.add_labels_to_an_issue(repo_path, pr['number'], pr_labels) | ||
GITHUB.add_labels_to_an_issue(repo_path, pr['number'], pr_labels) | ||
end | ||
end | ||
end | ||
|
@@ -158,7 +173,7 @@ def self.update(options) | |
local_files = self.local_files(path) | ||
module_files = self.module_files(local_files, path) | ||
|
||
managed_modules = self.managed_modules("#{options[:configs]}/#{options[:managed_modules_conf]}", options[:filter], options[:negative_filter]) | ||
managed_modules = self.managed_modules("#{options[:configs]}/#{options[:managed_modules_conf]}", options[:filter], options[:negative_filter], options[:topic]) | ||
|
||
errors = false | ||
# managed_modules is either an array or a hash | ||
|
This file contains 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
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about a global with state. Perhaps it should be a lazy (static) method on the module. This can help in case it's used in an offline context.