huborg 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -20
  3. data/LICENSE +198 -11
  4. data/lib/huborg.rb +89 -45
  5. data/lib/huborg/version.rb +1 -1
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77b0a3fbcce8421c99cb40deb90fd3428b85ac81f238ab0f8b5121d81299a57b
4
- data.tar.gz: c4a93167f48a1cf45894e445872a583715df7b6dfe44f5710bd0b70ef1951fdc
3
+ metadata.gz: 948131a37b61ab2a4acce4903acd0fd7fd60ee9df803cb841f8b393ad0c1b0ef
4
+ data.tar.gz: 0774d0aac9a75d7cff97c679df9b33f6233023020aee7a0e981a544208e1997e
5
5
  SHA512:
6
- metadata.gz: e88edb17cbb567fef94563a2a2d060ee8140a5f9f5de0d10618253fb5da229efeac1485d05eaf942a5329afbe24209de021c28b8b8279914cd2291f276cf3126
7
- data.tar.gz: 4ffc1475e19ac6b86c127d34c90037b2476e9e92b24b1cfbaeb7d9eb4086df94b380a7cd71b8f0c2a13ecfe57acb3427fdfa9f36672d1452d082d1fd611e2df2
6
+ metadata.gz: 261df09eb3aea048626c57362f089fc370c99508777513efc20e96809c373602de268c52f79bf6e4aca4478604f1a126d01669ab4335d4bf767d13c93ff74ad3
7
+ data.tar.gz: a7b719b66e34af9d993c6ac9a9ced1fcc8af05ac8f3a56b0d51b22681d45e9d6e05ef9af23f68875731be67bde435a808f1975a35388360008dfa703c85dbf68
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.3.1](https://github.com/samvera-labs/huborg/tree/v0.3.1) (2020-06-14)
4
+
5
+ [Full Changelog](https://github.com/samvera-labs/huborg/compare/v0.3.0...v0.3.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Favoring default\_branch instead of "master" [\#15](https://github.com/samvera-labs/huborg/pull/15) ([jeremyf](https://github.com/jeremyf))
10
+ - Collapse repository filtering into a single callable [\#13](https://github.com/samvera-labs/huborg/pull/13) ([mjgiarlo](https://github.com/mjgiarlo))
11
+ - Update license with full Apache 2.0 license [\#12](https://github.com/samvera-labs/huborg/pull/12) ([mjgiarlo](https://github.com/mjgiarlo))
12
+ - Allow filtering repositories by one or more topics [\#11](https://github.com/samvera-labs/huborg/pull/11) ([mjgiarlo](https://github.com/mjgiarlo))
13
+
3
14
  ## [v0.3.0](https://github.com/samvera-labs/huborg/tree/v0.3.0) (2020-04-28)
4
15
 
5
16
  [Full Changelog](https://github.com/samvera-labs/huborg/compare/v0.2.0...v0.3.0)
@@ -29,23 +40,6 @@
29
40
  - Adding Huborg::Client\#audit\_license [\#2](https://github.com/samvera-labs/huborg/pull/2) ([jeremyf](https://github.com/jeremyf))
30
41
  - Adding Huborg::Client\#clone\_and\_rebase! [\#1](https://github.com/samvera-labs/huborg/pull/1) ([jeremyf](https://github.com/jeremyf))
31
42
 
32
- # Changelog
33
-
34
- ## [v0.2.0](https://github.com/samvera-labs/huborg/tree/v0.2.0) (2020-02-28)
35
-
36
- [Full Changelog](https://github.com/samvera-labs/huborg/compare/v0.1.0...v0.2.0)
37
-
38
- **Implemented enhancements:**
39
-
40
- - Adding release process [\#4](https://github.com/samvera-labs/huborg/pull/4) ([jeremyf](https://github.com/jeremyf))
41
-
42
- **Merged pull requests:**
43
-
44
- - Tweaking documentation [\#5](https://github.com/samvera-labs/huborg/pull/5) ([jeremyf](https://github.com/jeremyf))
45
- - Adding Huborg::Client\#synchronize\_mailmap! [\#3](https://github.com/samvera-labs/huborg/pull/3) ([jeremyf](https://github.com/jeremyf))
46
- - Adding Huborg::Client\#audit\_license [\#2](https://github.com/samvera-labs/huborg/pull/2) ([jeremyf](https://github.com/jeremyf))
47
- - Adding Huborg::Client\#clone\_and\_rebase! [\#1](https://github.com/samvera-labs/huborg/pull/1) ([jeremyf](https://github.com/jeremyf))
48
-
49
43
  ## [v0.1.0](https://github.com/samvera-labs/huborg/tree/v0.1.0) (2020-02-26)
50
44
 
51
45
  [Full Changelog](https://github.com/samvera-labs/huborg/commit/cc1ce07147ad552cabf343c8195610bbb8c9376d)
@@ -53,6 +47,3 @@
53
47
  - Adding Huborg::Client\#push\_template! ([jeremyf](https://github.com/jeremyf))
54
48
 
55
49
  \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
56
-
57
-
58
- \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/LICENSE CHANGED
@@ -1,14 +1,201 @@
1
- Copyright 2020 University of Notre Dame
2
- Additional copyright may be held by others, as reflected in the commit history.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
3
4
 
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
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
6
 
8
- http://www.apache.org/licenses/LICENSE-2.0
7
+ 1. Definitions.
9
8
 
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.
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020 University of Notre Dame
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require "huborg/version"
2
3
  require 'octokit'
3
4
  require 'git'
@@ -18,19 +19,21 @@ module Huborg
18
19
  # * {#synchronize_mailmap!} - ensure all git .mailmap files are
19
20
  # synchronized
20
21
  class Client
21
- # When checking repository names, this pattern will match all repositories.
22
- # @see #initialize `#initialize` for details on the repository pattern.
23
- DEFAULT_REPOSITORY_PATTERN = %r{\A.*\Z}
22
+ # When listing repositories, this callable will return all repositories.
23
+ # @see #initialize `#initialize` for details on the repository filter.
24
+ DEFAULT_REPOSITORY_FILTER = ->(client, repo) { true }
24
25
 
25
26
  # @since v0.1.0
26
27
  #
27
28
  # @param logger [Logger] used in logging output of processes
28
- # @param github_access_token [String] used to connect to the Oktokit::Client.
29
+ # @param github_access_token [String] used to connect to the Octokit::Client.
29
30
  # The given token will need to have permission to interact with
30
31
  # repositories. Defaults to ENV["GITHUB_ACCESS_TOKEN"]
31
- # @param org_names [Array<String>, String] used as the default list of Github organizations
32
- # in which we'll interact.
33
- # @param repository_pattern [Regexp] limit the list of repositories to the given pattern; defaults to ALL
32
+ # @param org_names [Array<String>, String] list of GitHub organizations
33
+ # Huborg will act on
34
+ # @param repository_filter [Proc<Octokit::Client,Octokit::Repository>] filter
35
+ # the list of repositories to those for those which the callable returns
36
+ # true; defaults to ALL
34
37
  #
35
38
  # @example
36
39
  # # Without configuration options. You'll want ENV["GITHUB_ACCESS_TOKEN"]
@@ -42,24 +45,27 @@ module Huborg
42
45
  # # insensitivity is declared as the `i` at the end of the regular
43
46
  # # expression).
44
47
  # client = Huborg::Client.new(
45
- # logger: Logger.new(STDOUT),
46
- # github_access_token: "40-random-characters-for-your-token",
47
- # org_names: ["samvera", "samvera-labs"],
48
- # repository_patter: %r{hyrax}i
49
- # )
48
+ # logger: Logger.new(STDOUT),
49
+ # github_access_token: "40-random-characters-for-your-token",
50
+ # org_names: ["samvera", "samvera-labs"],
51
+ # repository_filter: ->(client, repo) { repo.full_name.match?(/.*hyrax.*/) }
52
+ # )
50
53
  #
51
54
  # @see https://github.com/octokit/octokit.rb#oauth-access-tokens Octokit's documentation for OAuth Tokens
52
55
  # @see https://developer.github.com/v3/repos/#list-organization-repositories Github's documentation for repository data structures
53
- def initialize(logger: default_logger, github_access_token: default_access_token, org_names:, repository_pattern: DEFAULT_REPOSITORY_PATTERN)
56
+ def initialize(org_names:,
57
+ logger: default_logger,
58
+ github_access_token: default_access_token,
59
+ repository_filter: DEFAULT_REPOSITORY_FILTER)
60
+ @org_names = Array(org_names)
54
61
  @logger = logger
55
62
  @client = Octokit::Client.new(access_token: github_access_token)
56
- @org_names = Array(org_names)
57
- @repository_pattern = repository_pattern
63
+ @repository_filter = repository_filter
58
64
  end
59
65
 
60
66
  private
61
67
 
62
- attr_reader :client, :logger, :org_names, :repository_pattern
68
+ attr_reader :client, :logger, :org_names, :repository_filter
63
69
 
64
70
  def default_logger
65
71
  require 'logger'
@@ -198,13 +204,14 @@ module Huborg
198
204
  next if repo.archived?
199
205
  push_template_to!(filename: ".mailmap", template: consolidated_template, repo: repo, overwrite: true)
200
206
  end
201
- return true
207
+
208
+ true
202
209
  end
203
210
 
204
211
  # @api public
205
212
  # @since v0.2.0
206
213
  #
207
- # Clone all repositories (that match the {#repository_pattern} for
214
+ # Clone all repositories (that match the {#repository_filter} for
208
215
  # the given organization(s). Then and rebase any existing repositories.
209
216
  #
210
217
  # @param directory [String] the directory in which to clone the repositories
@@ -265,8 +272,8 @@ module Huborg
265
272
  # @param skip_archived [Boolean] skip any archived projects
266
273
  # @param query [Hash] the query params to use when selecting pull requests
267
274
  #
268
- # @yieldparam [Oktokit::PullRequest] responds to #created_at, #title, #html_url, etc
269
- # @yieldparam [Oktokit::Repository] responds to #full_name
275
+ # @yieldparam [Octokit::PullRequest] responds to #created_at, #title, #html_url, etc
276
+ # @yieldparam [Octokit::Repository] responds to #full_name
270
277
  #
271
278
  # @example
272
279
  # require 'huborg'
@@ -289,13 +296,47 @@ module Huborg
289
296
  true
290
297
  end
291
298
 
299
+ # @api public
300
+ # @since v0.4.0
301
+ #
302
+ # List every repository that will be acted upon. This is primarily to
303
+ # provide extra assurance to the user.
304
+ #
305
+ # @yieldparam [Octokit::Repository] responds to #full_name
306
+ #
307
+ # @example
308
+ # require 'huborg'
309
+ # client = Huborg::Client.new(
310
+ # org_names: ["samvera", "samvera-labs"],
311
+ # repository_filter: ->(client, repo) {
312
+ # ['infrastructure', 'gem'].all? { |topic|
313
+ # client.topics(repo.full_name, accept: Octokit::Preview::PREVIEW_TYPES[:topics])[:names].include?(topic)
314
+ # }
315
+ # }
316
+ # )
317
+ # client.list_repositories do |repo|
318
+ # puts repo.full_name
319
+ # end
320
+ #
321
+ # @see https://developer.github.com/v3/repos/#list-organization-repositories
322
+ # for the response document
323
+ #
324
+ # @return [True]
325
+ def list_repositories
326
+ each_github_repository do |repo|
327
+ yield repo
328
+ end
329
+
330
+ true
331
+ end
332
+
292
333
  private
293
334
 
294
- # Fetch all of the repositories for the initialized :org_names that
295
- # match the initialized :repository_pattern
335
+ # Fetch all of the repositories for the initialized :org_names for which
336
+ # the initialized :repository_filter returns true
296
337
  #
297
- # @yield [Oktokit::Repository] each repository will be yielded
298
- # @yieldparam [Oktokit::Repository]
338
+ # @yield [Octokit::Repository] each repository will be yielded
339
+ # @yieldparam [Octokit::Repository]
299
340
  # @see https://developer.github.com/v3/repos/#list-organization-repositories
300
341
  # for the response document
301
342
  # @return [True]
@@ -308,13 +349,16 @@ module Huborg
308
349
  end
309
350
 
310
351
  repos.each do |repo|
311
- block.call(repo) if repository_pattern.match?(repo.full_name)
352
+ next unless repository_filter.call(client, repo)
353
+
354
+ block.call(repo)
312
355
  end
313
- return true
356
+
357
+ true
314
358
  end
315
359
 
316
360
  # @note Due to an implementation detail in octokit.rb, refs sometimes
317
- # need to be "heads/master" and "refs/heads/master" as detailed
361
+ # need to be "heads/<branch>" and "refs/heads/<branch>" as detailed
318
362
  # below
319
363
  # @param repo [#full_name, #archived] Likely the result of Octokit::Client#org
320
364
  # @param template [String] name of the template to push out to all
@@ -328,11 +372,11 @@ module Huborg
328
372
  # would likely want to overwrite.
329
373
  def push_template_to!(repo:, template:, filename:, overwrite: false)
330
374
  return if repo.archived
331
- # Note: Sometimes I'm using "heads/master" and other times I'm using
332
- # "refs/heads/master". There appears to be an inconsistency in
375
+ # Note: Sometimes I'm using "heads/<default>" and other times I'm using
376
+ # "refs/heads/<default>". There appears to be an inconsistency in
333
377
  # the implementation of octokit.
334
- master = client.ref(repo.full_name, "heads/master")
335
- copy_on_master = begin
378
+ default_branch = client.ref(repo.full_name, "heads/#{repo.default_branch}")
379
+ filename_ref_on_default_branch = begin
336
380
  # I have seen both a return value of nil or seen raised an Octokit::NotFound
337
381
  # exception (one for a file at root, the other for a file in a non-existent
338
382
  # directory)
@@ -340,23 +384,23 @@ module Huborg
340
384
  rescue Octokit::NotFound
341
385
  nil
342
386
  end
343
- commit_message = "Adding #{filename}\n\nThis was uploaded via automation."
387
+ commit_message = "Adding/updating #{filename}\n\nThis was uploaded via automation."
344
388
  logger.info("Creating pull request for #{filename} on #{repo.full_name}")
345
389
  target_branch_name = "refs/heads/autoupdate-#{Time.now.utc.to_s.gsub(/\D+/,'')}"
346
- if copy_on_master
390
+ if filename_ref_on_default_branch
347
391
  return unless overwrite
348
- branch = client.create_reference(repo.full_name, target_branch_name, master.object.sha)
392
+ client.create_reference(repo.full_name, target_branch_name, default_branch.object.sha)
349
393
  client.update_contents(
350
394
  repo.full_name,
351
395
  filename,
352
396
  commit_message,
353
- copy_on_master.sha,
397
+ filename_ref_on_default_branch.sha,
354
398
  file: File.new(template, "r"),
355
399
  branch: target_branch_name
356
400
  )
357
- client.create_pull_request(repo.full_name, "refs/heads/master", target_branch_name, commit_message)
401
+ client.create_pull_request(repo.full_name, "refs/heads/#{repo.default_branch}", target_branch_name, commit_message)
358
402
  else
359
- branch = client.create_reference(repo.full_name, target_branch_name, master.object.sha)
403
+ client.create_reference(repo.full_name, target_branch_name, default_branch.object.sha)
360
404
  client.create_contents(
361
405
  repo.full_name,
362
406
  filename,
@@ -364,7 +408,7 @@ module Huborg
364
408
  file: File.new(template, "r"),
365
409
  branch: target_branch_name
366
410
  )
367
- client.create_pull_request(repo.full_name, "refs/heads/master", target_branch_name, commit_message)
411
+ client.create_pull_request(repo.full_name, "refs/heads/#{repo.default_branch}", target_branch_name, commit_message)
368
412
  end
369
413
  end
370
414
 
@@ -391,9 +435,9 @@ module Huborg
391
435
  git.branch.stashes.save("Stashing via #{self.class}#clone_and_rebase!")
392
436
  end
393
437
  end
394
- git.branch("master").checkout
395
- logger.info("Pulling down master branch from origin for #{repo_path}")
396
- git.pull("origin", "master")
438
+ git.branch(repo.default_branch).checkout
439
+ logger.info("Pulling down #{repo.default_branch} branch from origin for #{repo_path}")
440
+ git.pull("origin", repo.default_branch)
397
441
  else
398
442
  parent_directory = File.dirname(repo_path)
399
443
  logger.info("Creating #{parent_directory}")
@@ -410,15 +454,15 @@ module Huborg
410
454
  # @param rel [Symbol] The name of the related object(s) for the
411
455
  # given org
412
456
  # @param from [Object] The receiver of the rels method call. This could be
413
- # but is not limited to an Oktokit::Organization or
414
- # Oktokit::Repository.
457
+ # but is not limited to an Octokit::Organization or
458
+ # Octokit::Repository.
415
459
  #
416
460
  # @return [Array<Object>]
417
461
  def fetch_rel_for(rel:, from:, query: {})
418
462
  # Build a list of repositories, note per Github's API, these are
419
463
  # paginated.
420
464
  from_to_s = from.respond_to?(:name) ? from.name : from.to_s
421
- logger.info "Fetching rels[#{rel.inspect}] for '#{from_to_s}' with pattern #{repository_pattern.inspect} and query #{query.inspect}"
465
+ logger.info "Fetching rels[#{rel.inspect}] for '#{from_to_s}' with filter #{repository_filter.inspect}, and query #{query.inspect}"
422
466
  source = from.rels[rel].get(query)
423
467
  rels = []
424
468
  while source
@@ -429,7 +473,7 @@ module Huborg
429
473
  source = nil
430
474
  end
431
475
  end
432
- logger.info "Finished fetching rels[#{rel.inspect}] for '#{from_to_s}' with pattern #{repository_pattern.inspect} and query #{query.inspect}"
476
+ logger.info "Finished fetching rels[#{rel.inspect}] for '#{from_to_s}' with filter #{repository_filter.inspect}, and query #{query.inspect}"
433
477
  if block_given?
434
478
  rels
435
479
  else
@@ -1,5 +1,5 @@
1
1
  module Huborg
2
2
  # The current version of Huborg, as per Semantic Versioning
3
3
  # @see https://semver.org
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huborg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2020-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit