huborg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7aeb15386624a5bf1430e4fd989064ce84a04f4b88d760cc274db0defa21312d
4
+ data.tar.gz: 6d7b42c930fbbe776b97b022473133ea65e6faa89422532d7c5bf9559448c0fe
5
+ SHA512:
6
+ metadata.gz: dac200b5c0d7cc50d6ec0f7d1db4b4ba43bc5f5e3330520e2f7f9f7b536742e43ae56d9ed73e3f513488fc81e77b6c530d0658cacc440b008d8cfe2cfeb05dee
7
+ data.tar.gz: 13c4e14c1d5c761e366c5c19715019aecbf8d8f643efde3bae158fddaa5280893e93647a5f6287ed1b9e1d1dbacca4ca887661b70056414b88e7f7b36c0d7d35
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
@@ -0,0 +1,36 @@
1
+ The Samvera community is dedicated to providing a welcoming and
2
+ positive experience for all its members, whether they are at a formal
3
+ gathering, in a social setting, or taking part in activities online.
4
+ The Samvera community welcomes participation from people all over the
5
+ world and these members bring with them a wide variety of
6
+ professional, personal and social backgrounds; whatever these may be,
7
+ we treat colleagues with dignity and respect.
8
+
9
+ Community members communicate primarily in English, though for many of
10
+ them this is not their native language. We therefore strive to express
11
+ ourselves simply and clearly remembering that unnecessary use of
12
+ jargon and slang will be a barrier to understanding for many of our
13
+ colleagues. We are sensitive to the fact that the international
14
+ nature of the community means that we span many different social norms
15
+ around language and behaviour and we strive to conduct ourselves,
16
+ online and in person, in ways that are unlikely to cause offence.
17
+
18
+ Samvera conversations are often information-rich and intended to
19
+ generate discussion and debate. We discuss ideas from a standpoint of
20
+ mutual respect and reasoned argument.
21
+
22
+ Community members work together to promote a respectful and safe
23
+ community. In the event that someone’s conduct is causing offence or
24
+ distress, Samvera has a detailed
25
+ [Anti-Harassment Policy and Protocol](https://wiki.duraspace.org/display/samvera/Anti-Harassment+Policy)
26
+ which can be applied to address the problem. The first step in dealing
27
+ with any serious misconduct is to contact a local meeting organizer,
28
+ the
29
+ [Samvera community helpers](https://wiki.duraspace.org/display/samvera/Samvera+Community+Helpers)
30
+ ([email](mailto:helpers@samvera.org)), a community member you
31
+ trust, or the
32
+ [Samvera Steering Group](https://wiki.duraspace.org/display/samvera/Samvera+Steering+Group+membership)
33
+ immediately; at Samvera events, these people can be identified by
34
+ distinctive name badges. The
35
+ [Policy and Protocol](https://wiki.duraspace.org/display/samvera/Anti-Harassment+Policy)
36
+ should be consulted for fuller details.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,161 @@
1
+ # How to Contribute
2
+
3
+ We want your help to make the Samvera community great. There are a few guidelines
4
+ that we need contributors to follow so that we can have a chance of
5
+ keeping on top of things.
6
+
7
+ ## Code of Conduct
8
+
9
+ The Samvera Community is dedicated to providing a welcoming and positive
10
+ experience for all its members, whether they are at a formal gathering, in
11
+ a social setting, or taking part in activities online. Please see our
12
+ [Code of Conduct](CODE_OF_CONDUCT.md) for more information.
13
+
14
+ ## Samvera Community Intellectual Property Licensing and Ownership
15
+
16
+ All code contributors must have an Individual Contributor License Agreement
17
+ (iCLA) on file with the Samvera Steering Group. If the contributor works for
18
+ an institution, the institution must have a Corporate Contributor License
19
+ Agreement (cCLA) on file.
20
+
21
+ https://wiki.duraspace.org/display/samvera/Samvera+Community+Intellectual+Property+Licensing+and+Ownership
22
+
23
+ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
24
+
25
+ ## Contribution Tasks
26
+
27
+ * Reporting Issues
28
+ * Making Changes
29
+ * Documenting Code
30
+ * Committing Changes
31
+ * Submitting Changes
32
+ * Reviewing and Merging Changes
33
+
34
+ ### Reporting Issues
35
+
36
+ * Make sure you have a [GitHub account](https://github.com/signup/free)
37
+ * Submit a [Github issue](https://github.com/samvera/{{library}}/issues/) by:
38
+ * Clearly describing the issue
39
+ * Provide a descriptive summary
40
+ * Explain the expected behavior
41
+ * Explain the actual behavior
42
+ * Provide steps to reproduce the actual behavior
43
+
44
+ ### Making Changes
45
+
46
+ * Fork the repository on GitHub
47
+ * Create a topic branch from where you want to base your work.
48
+ * This is usually the master branch.
49
+ * To quickly create a topic branch based on master; `git branch fix/master/my_contribution master`
50
+ * Then checkout the new branch with `git checkout fix/master/my_contribution`.
51
+ * Please avoid working directly on the `master` branch.
52
+ * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
53
+ * Make sure you have added sufficient tests and documentation for your changes.
54
+ * Test functionality with RSpec; Test features / UI with Capybara.
55
+ * Run _all_ the tests to assure nothing else was accidentally broken.
56
+
57
+ ### Documenting Code
58
+
59
+ * All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
60
+ * Documentation should seek to answer the question "why does this code exist?"
61
+ * Document private / protected methods as desired.
62
+ * If you are working in a file with no prior documentation, do try to document as you gain understanding of the code.
63
+ * If you don't know exactly what a bit of code does, it is extra likely that it needs to be documented. Take a stab at it and ask for feedback in your pull request. You can use the 'blame' button on GitHub to identify the original developer of the code and @mention them in your comment.
64
+ * This work greatly increases the usability of the code base and supports the on-ramping of new committers.
65
+ * We will all be understanding of one another's time constraints in this area.
66
+ * [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
67
+
68
+ ### Committing changes
69
+
70
+ * Make commits of logical units.
71
+ * Check for unnecessary whitespace with `git diff --check` before committing.
72
+ * Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
73
+ * If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
74
+
75
+ ```
76
+ Present tense short summary (50 characters or less)
77
+
78
+ More detailed description, if necessary. It should be wrapped to 72
79
+ characters. Try to be as descriptive as you can, even if you think that
80
+ the commit content is obvious, it may not be obvious to others. You
81
+ should add such description also if it's already present in bug tracker,
82
+ it should not be necessary to visit a webpage to check the history.
83
+
84
+ Include Closes #<issue-number> when relavent.
85
+
86
+ Description can have multiple paragraphs and you can use code examples
87
+ inside, just indent it with 4 spaces:
88
+
89
+ class PostsController
90
+ def index
91
+ respond_to do |wants|
92
+ wants.html { render 'index' }
93
+ end
94
+ end
95
+ end
96
+
97
+ You can also add bullet points:
98
+
99
+ - you can use dashes or asterisks
100
+
101
+ - also, try to indent next line of a point for readability, if it's too
102
+ long to fit in 72 characters
103
+ ```
104
+
105
+ * Make sure you have added the necessary tests for your changes.
106
+ * Run _all_ the tests to assure nothing else was accidentally broken.
107
+ * When you are ready to submit a pull request
108
+
109
+ ### Submitting Changes
110
+
111
+ * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
112
+ * Make sure your branch is up to date with its parent branch (i.e. master)
113
+ * `git checkout master`
114
+ * `git pull --rebase`
115
+ * `git checkout <your-branch>`
116
+ * `git rebase master`
117
+ * It is a good idea to run your tests again.
118
+ * If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
119
+ * [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
120
+ * `git rebase --interactive master` ([See Github help](https://help.github.com/articles/interactive-rebase))
121
+ * Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
122
+ * Push your changes to a topic branch in your fork of the repository.
123
+ * Submit a pull request from your fork to the project.
124
+
125
+ ### Reviewing and Merging Changes
126
+
127
+ We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
128
+ Common checks that may occur in our repositories:
129
+
130
+ 1. Travis CI - where our automated tests are running
131
+ 2. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
132
+
133
+ If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
134
+
135
+ *Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (Travis CI is usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
136
+
137
+ #### Things to Consider When Reviewing
138
+
139
+ First, the person contributing the code is putting themselves out there. Be mindful of what you say in a review.
140
+
141
+ * Ask clarifying questions
142
+ * State your understanding and expectations
143
+ * Provide example code or alternate solutions, and explain why
144
+
145
+ This is your chance for a mentoring moment of another developer. Take time to give an honest and thorough review of what has changed. Things to consider:
146
+
147
+ * Does the commit message explain what is going on?
148
+ * Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
149
+ * Do new or changed methods, modules, and classes have documentation?
150
+ * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
151
+ * Does the description of the new/changed specs match your understanding of what the spec is doing?
152
+ * Did the Travis tests complete successfully?
153
+
154
+ If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
155
+
156
+ # Additional Resources
157
+
158
+ * [General GitHub documentation](http://help.github.com/)
159
+ * [GitHub pull request documentation](https://help.github.com/articles/about-pull-requests/)
160
+ * [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
161
+ * [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in huborg.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2020 University of Notre Dame
2
+ Additional copyright may be held by others, as reflected in the commit history.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # huborg
2
+
3
+ Code: [![Version](https://badge.fury.io/rb/huborg.png)](http://badge.fury.io/rb/huborg)
4
+
5
+ Docs: [![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
6
+ [![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)
7
+
8
+ Jump in: [![Slack Status](http://slack.samvera.org/badge.svg)](http://slack.samvera.org/)
9
+
10
+ # What is huborg?
11
+
12
+ The `huborg` gem is a set of Ruby classes that help script interactions with
13
+ repositories within an organization (or organizations).
14
+
15
+ ## Product Owner & Maintenance
16
+
17
+ The `huborg` gem is **NOT** a Core Component of the Samvera community. The documentation for
18
+ what we mean by Core Component can be found
19
+ [here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).
20
+
21
+ ### Product Owner
22
+
23
+ [jeremyf](https://github.com/jeremyf)
24
+
25
+ # Help
26
+
27
+ The Samvera community is here to help. Please see our [support guide](./SUPPORT.md).
28
+
29
+ # Getting Started
30
+
31
+ You'll need the `huborg` gem:
32
+
33
+ * Install via `gem install huborg` **or**
34
+ * Add it to your Gemfile: `gem "huborg"`
35
+
36
+ ## The Basics
37
+
38
+ ```ruby
39
+ require 'huborg'
40
+
41
+ # NOTE: You will need to include GITHUB_ACCESS_TOKEN in your ENV
42
+ client = Huborg::Client.new(org_names: ["samvera", "samvera-labs"])
43
+ # This command will push the given template to each repository in the above
44
+ # organizations. By default it will not overwrite existing files.
45
+ client.push_template!(
46
+ template: "/path/to/file/on/your/system",
47
+ filename: "relative/path/in/repository"
48
+ )
49
+ ```
50
+
51
+ The above will create a pull request against all repositories in
52
+ "samvera" and "samvera-labs". That pull request will be to the file
53
+ named `repository` (in the directory `relative/path/in`). The file's
54
+ content will be from the file `/path/to/file/on/your/system`.
55
+
56
+ ## Further Refinements
57
+
58
+ This example demonstrates the full parameter options:
59
+
60
+ ```ruby
61
+ require 'huborg'
62
+ require 'logger'
63
+
64
+ client = Huborg::Client.new(
65
+ org_names: ["samvera", "samvera-labs"]),
66
+ logger: Logger.new(STDOUT),
67
+ github_access_token: "my-super-secret-token",
68
+ repository_pattern: %r{hyrax}i, # Limit to repositories with full name "hyrax"
69
+ )
70
+ client.push_template!(
71
+ template: "/path/to/file/on/your/system",
72
+ filename: "relative/path/in/repository",
73
+ overwrite: true
74
+ )
75
+ ```
76
+
77
+ ## Prerequisites
78
+
79
+ You'll want to have created a [Github OAuth Access Token](https://github.com/octokit/octokit.rb#oauth-access-tokens).
80
+
81
+ ## Hey, Where Are The Repository Tests?
82
+
83
+ Great question. The product owner has chosen not to write the tests as the
84
+ tests would be a preposterous amount of mocks and stubs. The product owner
85
+ recommends that you, intrepid developer, create a Github organization of your
86
+ own and add a few repositories to play against. That is what the product owner
87
+ did, and will be how they test the `huborg` gem going forward.
88
+
89
+ You, dear intrepid developer, can use the rake task `test:push_template` and
90
+ look at your organization's repositories to see the pull request. The product
91
+ owner used the following:
92
+
93
+ ```console
94
+ $ export GITHUB_ACCESS_TOKEN=their-github-token
95
+ $ export GITHUB_ORG_NAME=their-organization
96
+ $ bundle exec rake test:push_template
97
+ ```
98
+
99
+ ## Todo
100
+
101
+ - [ ] Add method to clone repositories
102
+ - [ ] Add method to pull changes from upstream repositories
103
+ - [ ] Add method to run stats against local repositories
104
+
105
+ # Acknowledgments
106
+
107
+ This software has been developed by and is brought to you by the Samvera community. Learn more at the
108
+ [Samvera website](http://samvera.org/).
109
+
110
+ ![Samvera Logo](https://wiki.lyrasis.org/download/thumbnails/87459292/samvera-fall-font2-200w.png?version=1&modificationDate=1498550535816&api=v2)
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ namespace :test do
4
+ desc "Push template to organization (set ENV[GITHUB_ACCESS_TOKEN] and ENV[GITHUB_ORG_NAME])"
5
+ task :push_template do
6
+ require 'huborg'
7
+ client = Huborg::Client.new(
8
+ github_access_token: ENV.fetch("GITHUB_ACCESS_TOKEN"),
9
+ org_names: ENV.fetch("GITHUB_ORG_NAME")
10
+ )
11
+ client.push_template!(
12
+ template: __FILE__,
13
+ filename: "disposable-#{Time.now.utc.to_s.gsub(/\D+/,'')}.rake"
14
+ )
15
+ end
16
+ end
data/SUPPORT.md ADDED
@@ -0,0 +1,5 @@
1
+ If you would like to report an issue, first search [the list of issues](https://github.com/samvera-labs/huborg/issues/) to see if someone else has already reported it, and then feel free to [create a new issue](https://github.com/samvera-labs/huborg/issues/new).
2
+
3
+ If you have questions or need help, please email [the Samvera community tech list](https://groups.google.com/forum/#!forum/samvera-tech) or stop by the #dev channel in [the Samvera community Slack team](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391#Getintouch!-Slack).
4
+
5
+ You can learn more about the various Samvera communication channels on the [Get in touch!](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391) wiki page.
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "huborg"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/huborg.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/huborg/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "huborg"
5
+ spec.version = Huborg::VERSION
6
+ spec.authors = ["Jeremy Friesen"]
7
+ spec.email = ["jeremy.n.friesen@gmail.com"]
8
+
9
+ spec.summary = %q{Make changes to Organization Repositories en-masse.}
10
+ spec.description = %q{Make changes to Organization Repositories en-masse.}
11
+ spec.homepage = "https://github.com/samvera-labs/huborg/"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/samvera-labs/huborg/"
16
+ spec.metadata["changelog_uri"] = "https://github.com/samvera-labs/huborg/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ spec.add_dependency "octokit", "~> 4.16"
27
+ end
data/lib/huborg.rb ADDED
@@ -0,0 +1,182 @@
1
+ require "huborg/version"
2
+ require 'octokit'
3
+
4
+ module Huborg
5
+ class Error < RuntimeError; end
6
+
7
+ # The class that interacts with organizational repositories
8
+ class Client
9
+
10
+ # Match all repositories
11
+ DEFAULT_REPOSITORY_PATTERN = %r{\A.*\Z}
12
+
13
+ # @param logger [Logger] used in logging output of processes
14
+ # @param github_access_token [String] used to connect to the Oktokit::Client.
15
+ # The given token will need to have permission to interact with
16
+ # repositories. Defaults to ENV["GITHUB_ACCESS_TOKEN"]
17
+ # @param org_names [Array<String>] used as the default list of Github organizations
18
+ # in which we'll interact.
19
+ # @param repository_pattern [Regexp] limit the list of repositories to the given pattern; defaults to ALL
20
+ #
21
+ # @see https://github.com/octokit/octokit.rb#oauth-access-tokens
22
+ def initialize(logger: default_logger, github_access_token: default_access_token, org_names:, repository_pattern: DEFAULT_REPOSITORY_PATTERN)
23
+ @logger = logger
24
+ @client = Octokit::Client.new(access_token: github_access_token)
25
+ @org_names = Array(org_names)
26
+ @repository_pattern = repository_pattern
27
+ end
28
+ attr_reader :client, :logger, :org_names, :repository_pattern
29
+
30
+ private
31
+
32
+ def default_logger
33
+ require 'logger'
34
+ Logger.new(STDOUT)
35
+ end
36
+
37
+ def default_access_token
38
+ ENV.fetch('GITHUB_ACCESS_TOKEN')
39
+ rescue KeyError => e
40
+ $stderr.puts "You need to provide an OAuth Access Token.\nSee: https://github.com/octokit/octokit.rb#oauth-access-tokens"
41
+ raise e
42
+ end
43
+
44
+ public
45
+
46
+ # @api public
47
+ #
48
+ # Responsible for pushing the given template file to all of the
49
+ # organizations repositories. As we are pushing changes to
50
+ # repositories, this process will skip archived repositories.
51
+ #
52
+ # @note This skips archived repositories
53
+ #
54
+ # @param template [String] name of the template to push out to all
55
+ # repositories
56
+ # @param filename [String] where in the repository should we write
57
+ # the template. This is a relative pathname, each directory
58
+ # and filename.
59
+ # @param overwrite [Boolean] because sometimes you shouldn't
60
+ # overwrite what already exists. In the case of a LICENSE, we
61
+ # would not want to do that. In the case of a .mailmap, we
62
+ # would likely want to overwrite.
63
+ # @todo Verify that the template exists
64
+ def push_template!(template:, filename:, overwrite: false)
65
+ each_repository do |repo|
66
+ push_template_to!(repo: repo, template: template, filename: filename, overwrite: overwrite)
67
+ end
68
+ end
69
+
70
+ # @api private
71
+ # @note API Private as this is not yet used.
72
+ #
73
+ # Fetch all of the repositories for the initialized :org_names that
74
+ # match the initialized :repository_pattern
75
+ #
76
+ # @yield if given, yield a Oktokit::Repository object for each
77
+ # repository
78
+ # @yieldparam A raw Oktokit::Repository object
79
+ # @return [True]
80
+ def each_repository(&block)
81
+ # Collect all repositories
82
+ repos = []
83
+ org_names.each do |org_name|
84
+ org = client.org(org_name)
85
+ repos += fetch_rel_for(rel: :repos, org: org)
86
+ end
87
+
88
+ repos.each do |repo|
89
+ block.call(repo) if repository_pattern.match?(repo.full_name)
90
+ end
91
+ return true
92
+ end
93
+
94
+ private
95
+
96
+ # @note Due to an implementation detail in octokit.rb, refs sometimes
97
+ # need to be "heads/master" and "refs/heads/master" as detailed
98
+ # below
99
+ # @param repo [#full_name, #archived] Likely the result of Octokit::Client#org
100
+ # @param template [String] name of the template to push out to all
101
+ # repositories
102
+ # @param filename [String] where in the repository should we write
103
+ # the template. This is a relative pathname, each directory
104
+ # and filename.
105
+ # @param overwrite [Boolean] because sometimes you shouldn't
106
+ # overwrite what already exists. In the case of a LICENSE, we
107
+ # would not want to do that. In the case of a .mailmap, we
108
+ # would likely want to overwrite.
109
+ def push_template_to!(repo:, template:, filename:, overwrite: false)
110
+ return if repo.archived
111
+ # Note: Sometimes I'm using "heads/master" and other times I'm using
112
+ # "refs/heads/master". There appears to be an inconsistency in
113
+ # the implementation of octokit.
114
+ master = client.ref(repo.full_name, "heads/master")
115
+ copy_on_master = begin
116
+ # I have seen both a return value of nil or seen raised an Octokit::NotFound
117
+ # exception (one for a file at root, the other for a file in a non-existent
118
+ # directory)
119
+ client.contents(repo.full_name, path: filename)
120
+ rescue Octokit::NotFound
121
+ nil
122
+ end
123
+ commit_message = "Adding #{filename}\n\nThis was uploaded via automation."
124
+ logger.info("Creating pull request for #{filename} on #{repo.full_name}")
125
+ target_branch_name = "refs/heads/autoupdate-#{Time.now.utc.to_s.gsub(/\D+/,'')}"
126
+ if copy_on_master
127
+ return unless overwrite
128
+ branch = client.create_reference(repo.full_name, target_branch_name, master.object.sha)
129
+ client.update_contents(
130
+ repo.full_name,
131
+ filename,
132
+ commit_message,
133
+ copy_on_master.sha,
134
+ file: File.new(template, "r"),
135
+ branch: target_branch_name
136
+ )
137
+ client.create_pull_request(repo.full_name, "refs/heads/master", target_branch_name, commit_message)
138
+ else
139
+ branch = client.create_reference(repo.full_name, target_branch_name, master.object.sha)
140
+ client.create_contents(
141
+ repo.full_name,
142
+ filename,
143
+ commit_message,
144
+ file: File.new(template, "r"),
145
+ branch: target_branch_name
146
+ )
147
+ client.create_pull_request(repo.full_name, "refs/heads/master", target_branch_name, commit_message)
148
+ end
149
+ end
150
+
151
+ # Responsible for fetching an array of the given :rel
152
+ #
153
+ # @param rel [Symbol] The name of the related object(s) for the
154
+ # given org
155
+ # @param org [Object] An Organization object (provided by Oktokit
156
+ # object) from which this method fetchs the related :rel
157
+
158
+ # @return [Array<Object>]
159
+ def fetch_rel_for(rel:, org:)
160
+ # Build a list of repositories, note per Github's API, these are
161
+ # paginated.
162
+ logger.info "Fetching rels[#{rel.inspect}] for '#{org.login}' with pattern #{repository_pattern.inspect}"
163
+ source = org.rels[rel].get
164
+ rels = []
165
+ while source
166
+ rels += source.data
167
+ if source.rels[:next]
168
+ source = source.rels[:next].get
169
+ else
170
+ source = nil
171
+ end
172
+ end
173
+ rels
174
+ logger.info "Finished rels[#{rel.inspect}] for '#{org.login}' with pattern #{repository_pattern.inspect}"
175
+ if block_given?
176
+ rels
177
+ else
178
+ return rels
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,3 @@
1
+ module Huborg
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huborg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Friesen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.16'
27
+ description: Make changes to Organization Repositories en-masse.
28
+ email:
29
+ - jeremy.n.friesen@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CODE_OF_CONDUCT.md
36
+ - CONTRIBUTING.md
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - SUPPORT.md
42
+ - bin/console
43
+ - bin/setup
44
+ - huborg.gemspec
45
+ - lib/huborg.rb
46
+ - lib/huborg/version.rb
47
+ homepage: https://github.com/samvera-labs/huborg/
48
+ licenses: []
49
+ metadata:
50
+ homepage_uri: https://github.com/samvera-labs/huborg/
51
+ source_code_uri: https://github.com/samvera-labs/huborg/
52
+ changelog_uri: https://github.com/samvera-labs/huborg/CHANGELOG.md
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.1.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Make changes to Organization Repositories en-masse.
72
+ test_files: []