ghbulk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +2 -0
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/.rubocop.yml +41 -0
- data/.travis.yml +68 -0
- data/CHANGELOG.md +20 -0
- data/CODEOWNERS +7 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE.md +25 -0
- data/README.md +94 -0
- data/Rakefile +6 -0
- data/VERSION.txt +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/ghbulk +83 -0
- data/ghbulk.gemspec +30 -0
- data/lib/ghbulk.rb +142 -0
- data/lib/ghbulk/version.rb +3 -0
- data/spec/ghbulk_spec.rb +5 -0
- data/spec/spec_helper.rb +14 -0
- data/stale.yml +17 -0
- data/testing/ghbulk +86 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eea0c66a66064566820f5426ce299cfc9d9de5d3e24bbb5b70f9df26564433c6
|
4
|
+
data.tar.gz: 0dfa890c22ac6edee1f46e48b7bbeacfaf8d64c9102c69784f79164207b052f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4dfa54a871236983205198a902636952fe130543b25852af02cbe04a64a81b84169391d1af2ef12123151ceef8cc640ac98a1b547b23d259669a3deb453691cc
|
7
|
+
data.tar.gz: d35a779fb3c3139d6e2fb14cb9440a46d84dd8c38345ce32051b64f81afa683fb67907d9693adfb0cf28a0654dccae787bb93a05c19256ebd24612ef3d1e0f02
|
data/.gitattributes
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Layout/IndentationWidth:
|
2
|
+
Width: 4
|
3
|
+
|
4
|
+
Layout/LineLength:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/ClassLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/CyclomaticComplexity:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/PerceivedComplexity:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/FrozenStringLiteralComment:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/HashSyntax:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/RedundantParentheses:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/RedundantBegin:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/RedundantReturn:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/SpecialGlobalVars:
|
41
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
matrix:
|
2
|
+
include:
|
3
|
+
- language: ruby
|
4
|
+
name: "Bundler (rvm 2.4 & bundler 1.17.3)"
|
5
|
+
rvm: 2.4
|
6
|
+
before_install:
|
7
|
+
- gem install bundler -v 1.17.3
|
8
|
+
- language: ruby
|
9
|
+
name: "Bundler (rvm 2.4 & bundler 2.0.1)"
|
10
|
+
rvm: 2.4
|
11
|
+
before_install:
|
12
|
+
- gem install bundler -v 2.0.1
|
13
|
+
- language: ruby
|
14
|
+
name: "Bundler (rvm 2.5 & bundler 2.0.1)"
|
15
|
+
rvm: 2.5
|
16
|
+
before_install:
|
17
|
+
- gem install bundler -v 2.0.1
|
18
|
+
- language: ruby
|
19
|
+
name: "Bundler (rvm 2.6 & bundler 2.0.1)"
|
20
|
+
rvm: 2.6
|
21
|
+
before_install:
|
22
|
+
- gem install bundler -v 2.0.1
|
23
|
+
- language: ruby
|
24
|
+
name: "Rubocop (rvm 2.4)"
|
25
|
+
env: SKIP_INTERPRETER=true
|
26
|
+
rvm: 2.4
|
27
|
+
before_install:
|
28
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
29
|
+
install:
|
30
|
+
- ./rubocop-travis/install.sh
|
31
|
+
script:
|
32
|
+
- ./rubocop-travis/scan.sh
|
33
|
+
- language: ruby
|
34
|
+
name: "Rubocop (rvm 2.5)"
|
35
|
+
env: SKIP_INTERPRETER=true
|
36
|
+
rvm: 2.5
|
37
|
+
before_install:
|
38
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
39
|
+
install:
|
40
|
+
- ./rubocop-travis/install.sh
|
41
|
+
script:
|
42
|
+
- ./rubocop-travis/scan.sh
|
43
|
+
- language: ruby
|
44
|
+
name: "Rubocop (rvm 2.6)"
|
45
|
+
env: SKIP_INTERPRETER=true
|
46
|
+
rvm: 2.6
|
47
|
+
before_install:
|
48
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
49
|
+
install:
|
50
|
+
- ./rubocop-travis/install.sh
|
51
|
+
script:
|
52
|
+
- ./rubocop-travis/scan.sh
|
53
|
+
- language: ruby
|
54
|
+
name: Link Checking (rvm 2.6)
|
55
|
+
rvm: 2.6
|
56
|
+
env:
|
57
|
+
- WHITELIST="https://github.com/WolfSoftware/ghbulk,https://rubygems.org,https://img.shields.io"
|
58
|
+
before_install:
|
59
|
+
- mkdir travis
|
60
|
+
- git clone https://github.com/TravisToolbox/awesomebot-travis.git travis/awesomebot
|
61
|
+
install:
|
62
|
+
- "./travis/awesomebot/install.sh"
|
63
|
+
script:
|
64
|
+
- "./travis/awesomebot/scan.sh"
|
65
|
+
notifications:
|
66
|
+
email: false
|
67
|
+
slack:
|
68
|
+
secure: pu6TcL6di8LeEkIQQcO1MO7BuuP6IFJlyNqkmYugoAWe9M0P1sJodEttch8k9uvxrjgzE3f7dFn2vhgLnU762OFuBF3pLmIeJbq/jtIRXu2Az65Yz7eCktFmLmBeziu5hAYgPxdAIYFvbg/uBMzHSuqFebwt/swBuCuVqiRarUV5K7k04797VT1L9aof0nJrxYSC0JKtJZDIbsyOJfMgObl5D9jNx5jDKOP3K5oyTWwhXTd/NxcoqC9rYYXP+Q/m3wo7X/GDfU6H4KM9Q3X1NknhJmVRbWfHNiVcHwG2FY6rJpqOyRZSJKDXEQlK7WjmgtKULRbpmq2DkRdC87HpT+yPT1wZIfG/7OiLw2z0Rz72e/DHD2AHummFfjJChgKa3HUAt0T6NeHgSiXgL6ElbQK+09R0Tnb3JpQsd7w49p+CyYDLtEAzWaNcG0Nnv5tVkKYsUyvK5434L79x3Y0zx8Q9lti9IcmiFZpv0ZpZKPy7Yb3ychip4Wf7Ag3yTU1cyMK6pnXve1jy3Rwc3FiCYZ6cyYW52E5GkZAci6/3USw+bwsvExgtrYcallcrLLgipzYbIutB8fpUWPTwFBnyYWbDEilRSNtdFfHBNIw6JTXCIVVFsvItmDQknwxkIkkYb4BMGoM0eXuhlpVD31X0otw9H7lQlIAtfZB6aVOooNY=
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# ghbulk Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
For further info see our [changelogs](https://github.com/WolfSoftware/changelogs) guide.
|
8
|
+
|
9
|
+
## [Unreleased]
|
10
|
+
|
11
|
+
|
12
|
+
## [v1.0.0] - { release date }
|
13
|
+
|
14
|
+
* Initial Release ([@TGWolf][])
|
15
|
+
|
16
|
+
|
17
|
+
[@TGWolf]: https://github.com/TGWolf
|
18
|
+
|
19
|
+
[unreleased]: https://github.com/WolfSoftware/ghbulk/compare/v1.0.0...HEAD
|
20
|
+
[v1.0.0]: https://github.com/WolfSoftware/ghbulk/releases/tag/v1.0.0
|
data/CODEOWNERS
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Copyright © `2009-2020` `Wolf Software Limited`
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person
|
7
|
+
obtaining a copy of this software and associated documentation
|
8
|
+
files (the “Software”), to deal in the Software without
|
9
|
+
restriction, including without limitation the rights to use,
|
10
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the
|
12
|
+
Software is furnished to do so, subject to the following
|
13
|
+
conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
[![Build Status](https://img.shields.io/travis/WolfSoftware/ghbulk/master?style=for-the-badge&logo=travis)](https://travis-ci.org/WolfSoftware/ghbulk)
|
2
|
+
[![Software License](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge)](LICENSE.md)
|
3
|
+
[![Release](https://img.shields.io/github/release/WolfSoftware/ghbulk?color=blue&style=for-the-badge&logo=github&label=Latest%20Release)](https://github.com/WolfSoftware/c/releases/latest)
|
4
|
+
[![Last Release](https://img.shields.io/github/release-date/WolfSoftware/ghbulk?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/ghbulk/releases/latest)
|
5
|
+
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/WolfSoftware/ghbulk/latest?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/ghbulk/commits)
|
6
|
+
[![Last Commit](https://img.shields.io/github/last-commit/WolfSoftware/ghbulk?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/ghbulk/commits/master)
|
7
|
+
[![Code Size](https://img.shields.io/github/languages/code-size/WolfSoftware/ghbulk?color=blue&style=for-the-badge&logo=github)](#)
|
8
|
+
[![Repo Size](https://img.shields.io/github/repo-size/WolfSoftware/ghbulk?color=blue&style=for-the-badge&logo=github)](#)
|
9
|
+
[![Contributors](https://img.shields.io/github/contributors/WolfSoftware/ghbulk?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/ghbulk/graphs/contributors)
|
10
|
+
[![WolfSoftware](https://img.shields.io/badge/Created%20By-Wolf%20Software%20Ltd.-blue?style=for-the-badge)](https://github.com/WolfSoftware)
|
11
|
+
|
12
|
+
# GHBulk
|
13
|
+
|
14
|
+
GHBulk is a GitHub bulk respostiory creator, it works by reading a yaml file which contains the repository information.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Installing GHBulk is very simple, just execute the following command.
|
19
|
+
|
20
|
+
```
|
21
|
+
gem install ghbulk
|
22
|
+
```
|
23
|
+
|
24
|
+
## Command line usage
|
25
|
+
|
26
|
+
```
|
27
|
+
Usage: ghbulk
|
28
|
+
-h, --help Display this screen
|
29
|
+
-f, --filename string The file where the repository details are stored.
|
30
|
+
-t, --token string The GitHub token to use.
|
31
|
+
```
|
32
|
+
|
33
|
+
> Default filename is repositories.yml
|
34
|
+
|
35
|
+
## File format
|
36
|
+
|
37
|
+
The file should contain valid YAML.
|
38
|
+
|
39
|
+
### Example File
|
40
|
+
|
41
|
+
```
|
42
|
+
repos:
|
43
|
+
- name: ghbulk
|
44
|
+
organization: WolfSoftware
|
45
|
+
description: A small gem for bulk creation of GitHub repositories
|
46
|
+
has_issues: true
|
47
|
+
has_projects: false
|
48
|
+
has_wiki: false
|
49
|
+
license_template: mit
|
50
|
+
```
|
51
|
+
|
52
|
+
### File options
|
53
|
+
|
54
|
+
| Name | Type | Default | Description |
|
55
|
+
| ---- |:----:|:-------:| ----------- |
|
56
|
+
| action | string | create | The action to be performed. |
|
57
|
+
| allow\_merge\_commit | boolean | true | Either true to allow merging pull requests with a merge commit, or false to prevent merging pull requests with merge commits. |
|
58
|
+
| allow\_rebase_merge | boolean | true | Either true to allow rebase-merging pull requests, or false to prevent rebase-merging. |
|
59
|
+
| allow\_squash\_merge | boolean | true | Either true to allow squash-merging pull requests, or false to prevent squash-merging. |
|
60
|
+
| auto\_init | boolean | false | Pass true to create an initial commit with empty README. |
|
61
|
+
| delete\_branch\_on\_merge | boolean | false | Either true to allow automatically deleting head branches when pull requests are merged, or false to prevent automatic deletion |
|
62
|
+
| description | string | | A short description of the repository. |
|
63
|
+
| gitignore\_template | string | | Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". |
|
64
|
+
| has\_issues | boolean | true | Either true to enable issues for this repository or false to disable them. |
|
65
|
+
| has\_projects | boolean | true | Either true to enable projects for this repository or false to disable them. If you're creating a repository in an organization that has disabled repository projects, the default is false, and if you pass true, the API returns an error. |
|
66
|
+
| has\_wiki | boolean | true | Either true to enable the wiki for this repository or false to disable it. |
|
67
|
+
| homepage | string | | A URL with more information about the repository. |
|
68
|
+
| is\_template | boolean | false | Either true to make this repo available as a template repository or false to prevent it. |
|
69
|
+
| license_template | string | | Choose an open source license template that best suits your needs, and then use the license keyword as the license_template string. For example, "mit" or "mpl-2.0". |
|
70
|
+
| name | string | | The name of the repository. |
|
71
|
+
| private | boolean | false | Either true to create a private repository or false to create a public one. Creating private repositories requires a paid GitHub account. |
|
72
|
+
| team\_id | integer | | The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization. |
|
73
|
+
|
74
|
+
|
75
|
+
> The only 'required' parameter is 'name'.
|
76
|
+
|
77
|
+
## Contributing to GHBulk
|
78
|
+
|
79
|
+
### Setup
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
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
|
84
|
+
create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
85
|
+
|
86
|
+
### Testing
|
87
|
+
|
88
|
+
For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
|
89
|
+
|
90
|
+
For further information please refer to the [contributing](https://github.com/WolfSoftware/contributing) documentation.
|
91
|
+
|
92
|
+
# To-Do List
|
93
|
+
|
94
|
+
- [ ] Better validation
|
data/Rakefile
ADDED
data/VERSION.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.1.0
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ghbulk'
|
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
data/exe/ghbulk
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'ghbulk'
|
5
|
+
|
6
|
+
# -------------------------------------------------------------------------------- #
|
7
|
+
# Create Repositories #
|
8
|
+
# -------------------------------------------------------------------------------- #
|
9
|
+
|
10
|
+
def create_repositories(options)
|
11
|
+
begin
|
12
|
+
ghbulk = GHBulk.new
|
13
|
+
ghbulk.create_repositories(options[:token], options[:filename])
|
14
|
+
rescue StandardError => e
|
15
|
+
puts "Error: #{e}"
|
16
|
+
puts e.backtrace
|
17
|
+
exit(1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# -------------------------------------------------------------------------------- #
|
22
|
+
# Process Arguments #
|
23
|
+
# -------------------------------------------------------------------------------- #
|
24
|
+
# This function will process the input from the command line and work out what it #
|
25
|
+
# is that the user wants to see. #
|
26
|
+
# #
|
27
|
+
# This is the main processing function where all the processing logic is handled. #
|
28
|
+
# -------------------------------------------------------------------------------- #
|
29
|
+
|
30
|
+
def process_arguments
|
31
|
+
options = { :filename => 'repositories.yml' }
|
32
|
+
# Enforce the presence of
|
33
|
+
mandatory = %I[filename token]
|
34
|
+
|
35
|
+
optparse = OptionParser.new do |opts|
|
36
|
+
opts.banner = "Usage: #{$PROGRAM_NAME}"
|
37
|
+
|
38
|
+
opts.on('-h', '--help', 'Display this screen') do
|
39
|
+
puts opts
|
40
|
+
exit(1)
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('-f', '--filename string', 'The file where the repository details are stored. [default: repositories.yml]') do |filename|
|
44
|
+
options[:filename] = filename
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on('-t', '--token string', 'The GitHub token to use.') do |token|
|
48
|
+
options[:token] = token
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
begin
|
53
|
+
optparse.parse!
|
54
|
+
missing = mandatory.select { |param| options[param].nil? }
|
55
|
+
raise OptionParser::MissingArgument, (missing.join(', ')) unless missing.empty?
|
56
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
57
|
+
puts e.to_s
|
58
|
+
puts optparse
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
|
62
|
+
exit 0 if create_repositories(options)
|
63
|
+
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
|
67
|
+
# -------------------------------------------------------------------------------- #
|
68
|
+
# Main() #
|
69
|
+
# -------------------------------------------------------------------------------- #
|
70
|
+
# The main function where all of the heavy lifting and script config is done. #
|
71
|
+
# -------------------------------------------------------------------------------- #
|
72
|
+
|
73
|
+
def main
|
74
|
+
process_arguments
|
75
|
+
end
|
76
|
+
|
77
|
+
main
|
78
|
+
|
79
|
+
# -------------------------------------------------------------------------------- #
|
80
|
+
# End of Script #
|
81
|
+
# -------------------------------------------------------------------------------- #
|
82
|
+
# This is the end - nothing more to see here. #
|
83
|
+
# -------------------------------------------------------------------------------- #
|
data/ghbulk.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'ghbulk/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ghbulk'
|
7
|
+
spec.version = GHBulk::VERSION
|
8
|
+
spec.authors = ['Tim Gurney aka Wolf']
|
9
|
+
spec.email = ['wolf@tgwolf.com']
|
10
|
+
|
11
|
+
spec.summary = 'A simple gem for bulk GitHub repository creation'
|
12
|
+
spec.description = 'A simple gem for bulk creation of GitHub Repositories.'
|
13
|
+
spec.homepage = 'https://github.com/WolfSoftware/ghbulk'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.0'
|
23
|
+
spec.add_development_dependency 'colorize', '~> 0.8.1'
|
24
|
+
spec.add_development_dependency 'octokit', '~> 4.15.0'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'colorize', '~> 0.8.1'
|
29
|
+
spec.add_runtime_dependency 'octokit', '~> 4.15.0'
|
30
|
+
end
|
data/lib/ghbulk.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'ghbulk/version'
|
2
|
+
|
3
|
+
require 'colorize'
|
4
|
+
require 'octokit'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
#
|
8
|
+
# The class definition
|
9
|
+
#
|
10
|
+
class GHBulk
|
11
|
+
def abort_script(message)
|
12
|
+
puts message.colorize(:light_red)
|
13
|
+
abort
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_error(message)
|
17
|
+
puts message.colorize(:light_red)
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_warning(message)
|
21
|
+
puts message.colorize(:light_yellow)
|
22
|
+
end
|
23
|
+
|
24
|
+
def show_success(message)
|
25
|
+
puts message.colorize(:light_green)
|
26
|
+
end
|
27
|
+
|
28
|
+
def read_file(filename)
|
29
|
+
contents = nil
|
30
|
+
|
31
|
+
begin
|
32
|
+
File.open(filename, 'r') do |f|
|
33
|
+
contents = f.read
|
34
|
+
end
|
35
|
+
rescue SystemCallError
|
36
|
+
abort_script("Error reading file: #{filename} - Aborting")
|
37
|
+
end
|
38
|
+
return contents
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_payload(repo)
|
42
|
+
payload = {}
|
43
|
+
|
44
|
+
payload[:allow_merge_commit] = repo['allow_merge_commit'] if repo.key?('allow_merge_commit')
|
45
|
+
payload[:allow_rebase_merge] = repo['allow_rebase_merge'] if repo.key?('allow_rebase_merge')
|
46
|
+
payload[:allow_squash_merge] = repo['allow_squash_merge'] if repo.key?('allow_squash_merge')
|
47
|
+
payload[:archived] = repo['archived'] if repo.key?('archived')
|
48
|
+
payload[:auto_init] = repo['auto_init'] if repo.key?('auto_init')
|
49
|
+
payload[:delete_branch_on_merge] = repo['delete_branch_on_merge'] if repo.key?('delete_branch_on_merge')
|
50
|
+
payload[:description] = repo['description'] if repo.key?('description')
|
51
|
+
payload[:gitignore_template] = repo['gitignore_template'] if repo.key?('gitignore_template')
|
52
|
+
payload[:has_issues] = repo['has_issues'] if repo.key?('has_issues')
|
53
|
+
payload[:has_projects] = repo['has_projects'] if repo.key?('has_projects')
|
54
|
+
payload[:has_wiki] = repo['has_wiki'] if repo.key?('has_wiki')
|
55
|
+
payload[:homepage] = repo['homepage'] if repo.key?('homepage')
|
56
|
+
payload[:is_template] = repo['is_template'] if repo.key?('is_template')
|
57
|
+
payload[:license_template] = repo['license_template'] if repo.key?('license_template')
|
58
|
+
payload[:organization] = repo['organization'] if repo.key?('organization')
|
59
|
+
payload[:private] = repo['private'] if repo.key?('private')
|
60
|
+
payload[:team_id] = repo['team_id'] if repo.key?('team_id')
|
61
|
+
|
62
|
+
return payload
|
63
|
+
end
|
64
|
+
|
65
|
+
def does_repo_exist(client, repo_name)
|
66
|
+
return client.repository?(repo_name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_repository(client, repo_name, full_repo_name, payload)
|
70
|
+
if does_repo_exist(client, full_repo_name)
|
71
|
+
puts "Updating: #{full_repo_name}"
|
72
|
+
begin
|
73
|
+
client.update_repository(full_repo_name, payload)
|
74
|
+
rescue Octokit::UnprocessableEntity
|
75
|
+
show_error('Error updating repo')
|
76
|
+
else
|
77
|
+
show_success("Repo #{full_repo_name} has been updated")
|
78
|
+
end
|
79
|
+
else
|
80
|
+
puts "Creating: #{repo_name}"
|
81
|
+
begin
|
82
|
+
client.create_repository(repo_name, payload)
|
83
|
+
rescue Octokit::UnprocessableEntity
|
84
|
+
show_error('Error creating repo')
|
85
|
+
else
|
86
|
+
show_success("Repo #{repo_name} has been created")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete_repository(client, full_repo_name)
|
92
|
+
if does_repo_exist(client, full_repo_name)
|
93
|
+
client.delete_repository(full_repo_name)
|
94
|
+
show_error("Repository #{full_repo_name} has been deleted")
|
95
|
+
else
|
96
|
+
show_warning("Cannot delete - #{full_repo_name} doesn't exist")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def load_config(filename)
|
101
|
+
config = read_file(filename)
|
102
|
+
|
103
|
+
return if config.nil?
|
104
|
+
|
105
|
+
yaml_hash = YAML.safe_load(config)
|
106
|
+
|
107
|
+
abort('Repos not located - check file symtax and try again') unless yaml_hash.key?('repos')
|
108
|
+
|
109
|
+
return yaml_hash['repos']
|
110
|
+
end
|
111
|
+
|
112
|
+
def connect_client(gh_token)
|
113
|
+
return Octokit::Client.new(:access_token => gh_token)
|
114
|
+
end
|
115
|
+
|
116
|
+
def create_repositories(gh_token, filename)
|
117
|
+
repo_list = load_config(filename)
|
118
|
+
|
119
|
+
client = connect_client(gh_token)
|
120
|
+
begin
|
121
|
+
username = client.user.login
|
122
|
+
rescue Octokit::Error
|
123
|
+
abort('Inavlid Token')
|
124
|
+
end
|
125
|
+
repo_list.each do |repo|
|
126
|
+
payload = create_payload(repo)
|
127
|
+
|
128
|
+
repo_name = repo['name']
|
129
|
+
full_repo_name = if repo.key?('organization')
|
130
|
+
"#{repo['organization']}/#{repo['name']}"
|
131
|
+
else
|
132
|
+
"#{username}/#{repo['name']}"
|
133
|
+
end
|
134
|
+
|
135
|
+
if repo['action'] && repo['action'] == 'delete'
|
136
|
+
delete_repository(client, full_repo_name)
|
137
|
+
else
|
138
|
+
create_repository(client, repo_name, full_repo_name, payload)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/spec/ghbulk_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'ghbulk'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
data/stale.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
2
|
+
daysUntilStale: 60
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
4
|
+
daysUntilClose: 7
|
5
|
+
# Issues with these labels will never be considered stale
|
6
|
+
exemptLabels:
|
7
|
+
- pinned
|
8
|
+
- security
|
9
|
+
# Label to use when marking an issue as stale
|
10
|
+
staleLabel: wontfix
|
11
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
12
|
+
markComment: >
|
13
|
+
This issue has been automatically marked as stale because it has not had
|
14
|
+
recent activity. It will be closed if no further activity occurs. Thank you
|
15
|
+
for your contributions.
|
16
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
17
|
+
closeComment: true
|
data/testing/ghbulk
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift('./lib')
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'optparse'
|
7
|
+
require 'ghbulk'
|
8
|
+
|
9
|
+
# -------------------------------------------------------------------------------- #
|
10
|
+
# Create Repositories #
|
11
|
+
# -------------------------------------------------------------------------------- #
|
12
|
+
|
13
|
+
def create_repositories(options)
|
14
|
+
begin
|
15
|
+
ghbulk = GHBulk.new
|
16
|
+
ghbulk.create_repositories(options[:token], options[:filename])
|
17
|
+
rescue StandardError => e
|
18
|
+
puts "Error: #{e}"
|
19
|
+
puts e.backtrace
|
20
|
+
exit(1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# -------------------------------------------------------------------------------- #
|
25
|
+
# Process Arguments #
|
26
|
+
# -------------------------------------------------------------------------------- #
|
27
|
+
# This function will process the input from the command line and work out what it #
|
28
|
+
# is that the user wants to see. #
|
29
|
+
# #
|
30
|
+
# This is the main processing function where all the processing logic is handled. #
|
31
|
+
# -------------------------------------------------------------------------------- #
|
32
|
+
|
33
|
+
def process_arguments
|
34
|
+
options = { :filename => 'repositories.yml' }
|
35
|
+
# Enforce the presence of
|
36
|
+
mandatory = %I[filename token]
|
37
|
+
|
38
|
+
optparse = OptionParser.new do |opts|
|
39
|
+
opts.banner = "Usage: #{$PROGRAM_NAME}"
|
40
|
+
|
41
|
+
opts.on('-h', '--help', 'Display this screen') do
|
42
|
+
puts opts
|
43
|
+
exit(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('-f', '--filename string', 'The file where the repository details are stored. [default: repositories.yml]') do |filename|
|
47
|
+
options[:filename] = filename
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on('-t', '--token string', 'The GitHub token to use.') do |token|
|
51
|
+
options[:token] = token
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
optparse.parse!
|
57
|
+
missing = mandatory.select { |param| options[param].nil? }
|
58
|
+
raise OptionParser::MissingArgument, (missing.join(', ')) unless missing.empty?
|
59
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
60
|
+
puts e.to_s
|
61
|
+
puts optparse
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
|
65
|
+
exit 0 if create_repositories(options)
|
66
|
+
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
|
70
|
+
# -------------------------------------------------------------------------------- #
|
71
|
+
# Main() #
|
72
|
+
# -------------------------------------------------------------------------------- #
|
73
|
+
# The main function where all of the heavy lifting and script config is done. #
|
74
|
+
# -------------------------------------------------------------------------------- #
|
75
|
+
|
76
|
+
def main
|
77
|
+
process_arguments
|
78
|
+
end
|
79
|
+
|
80
|
+
main
|
81
|
+
|
82
|
+
# -------------------------------------------------------------------------------- #
|
83
|
+
# End of Script #
|
84
|
+
# -------------------------------------------------------------------------------- #
|
85
|
+
# This is the end - nothing more to see here. #
|
86
|
+
# -------------------------------------------------------------------------------- #
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghbulk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Gurney aka Wolf
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.17'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: colorize
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.8.1
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: octokit
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 4.15.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 4.15.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: colorize
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.8.1
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.8.1
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: octokit
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 4.15.0
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 4.15.0
|
117
|
+
description: A simple gem for bulk creation of GitHub Repositories.
|
118
|
+
email:
|
119
|
+
- wolf@tgwolf.com
|
120
|
+
executables:
|
121
|
+
- ghbulk
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- ".gitattributes"
|
126
|
+
- ".gitignore"
|
127
|
+
- ".rspec"
|
128
|
+
- ".rspec_status"
|
129
|
+
- ".rubocop.yml"
|
130
|
+
- ".travis.yml"
|
131
|
+
- CHANGELOG.md
|
132
|
+
- CODEOWNERS
|
133
|
+
- CONTRIBUTING.md
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- LICENSE.md
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- VERSION.txt
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- exe/ghbulk
|
143
|
+
- ghbulk.gemspec
|
144
|
+
- lib/ghbulk.rb
|
145
|
+
- lib/ghbulk/version.rb
|
146
|
+
- pkg/ghbulk-0.1.0.gem
|
147
|
+
- spec/ghbulk_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- stale.yml
|
150
|
+
- testing/ghbulk
|
151
|
+
homepage: https://github.com/WolfSoftware/ghbulk
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubygems_version: 3.1.2
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: A simple gem for bulk GitHub repository creation
|
174
|
+
test_files: []
|