chandler 0.5.0 → 0.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec007e148274235db641d253dd9fa9fe1acbb945
4
- data.tar.gz: 1f28e083665578567a9dd64f53034011ab894b2c
3
+ metadata.gz: 8ca571dcd740acdf7ea4863eb43a0de361344213
4
+ data.tar.gz: cce37a9c6b223a77c740f913eed635feb0d47b2d
5
5
  SHA512:
6
- metadata.gz: ac6bbf38b10b06cd5ee908b41fe69f1561729dd235bb9a44a8b97cec9e06ac8aaaecd848e4c26d39d5fb4b6e8327d4985f84b46c034587d34da442bf6f53c162
7
- data.tar.gz: 684fbf5edf1686d1b258c9b10d6a86f5dc1d66ed68f5dfcc55bb035d9133cd85e9ba86c00a93bc956b155c9c55c4bc5b012d14c10394ae57eb2ea9b77af04cdb
6
+ metadata.gz: 730d4f1e2e19824164be7a03dc91e32676dbec33f2968cb24de5fb47ea0575bfe1dae43ae9cbaefd29e1ffea1e4e025ae28274c695896daff2608e4c314be049
7
+ data.tar.gz: 547e330cff56d6fe05a07e70f9c0133ff9e73f2825ca34771821b92717bc68386a66ef5d0da5d3ce8b1288c6543d12dd8d1ed7c0d4dcb47d916731e330d6295d
@@ -1,5 +1,7 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.1
3
+ DisplayCopNames: true
4
+ DisplayStyleGuide: true
3
5
  Exclude:
4
6
  - "*.gemspec"
5
7
 
@@ -15,6 +17,9 @@ Metrics/ClassLength:
15
17
  Exclude:
16
18
  - "test/**/*"
17
19
 
20
+ Performance/Casecmp:
21
+ Enabled: false
22
+
18
23
  Style/BarePercentLiterals:
19
24
  EnforcedStyle: percent_q
20
25
 
@@ -2,5 +2,10 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1
4
4
  - 2.2
5
- - 2.3.0
6
- before_install: gem install bundler -v 1.10.4
5
+ - 2.3.1
6
+ before_install: gem install bundler -v 1.13.1
7
+ matrix:
8
+ include:
9
+ # Run Danger only once, on 2.3.1
10
+ - rvm: 2.3.1
11
+ before_script: bundle exec danger
@@ -8,6 +8,10 @@ chandler is in a pre-1.0 state. This means that its APIs and behavior are subjec
8
8
 
9
9
  * Your contribution here!
10
10
 
11
+ ## [0.6.0][] (2016-11-09)
12
+
13
+ * [#19](https://github.com/mattbrictson/chandler/pull/19): Add GitHub Enterprise support - [@mattbrictson](https://github.com/mattbrictson)
14
+
11
15
  ## [0.5.0][] (2016-10-07)
12
16
 
13
17
  * Adds support for using `CHANDLER_GITHUB_API_TOKEN` to authenticate your API requests - Orta
@@ -46,7 +50,8 @@ chandler is in a pre-1.0 state. This means that its APIs and behavior are subjec
46
50
  * Initial release
47
51
 
48
52
  [Semver]: http://semver.org
49
- [Unreleased]: https://github.com/mattbrictson/chandler/compare/v0.5.0...HEAD
53
+ [Unreleased]: https://github.com/mattbrictson/chandler/compare/v0.6.0...HEAD
54
+ [0.6.0]: https://github.com/mattbrictson/chandler/compare/v0.5.0...v0.6.0
50
55
  [0.5.0]: https://github.com/mattbrictson/chandler/compare/v0.4.0...v0.5.0
51
56
  [0.4.0]: https://github.com/mattbrictson/chandler/compare/v0.3.1...v0.4.0
52
57
  [0.3.1]: https://github.com/mattbrictson/chandler/compare/v0.3.0...v0.3.1
@@ -0,0 +1,54 @@
1
+ # Adapted from https://github.com/ruby-grape/danger/blob/master/Dangerfile
2
+ # Q: What is a Dangerfile, anyway? A: See http://danger.systems/
3
+
4
+ # ------------------------------------------------------------------------------
5
+ # Additional pull request data
6
+ # ------------------------------------------------------------------------------
7
+ project_name = github.pr_json["base"]["repo"]["name"]
8
+ pr_number = github.pr_json["number"]
9
+ pr_url = github.pr_json["_links"]["html"]["href"]
10
+
11
+ # ------------------------------------------------------------------------------
12
+ # What changed?
13
+ # ------------------------------------------------------------------------------
14
+ has_lib_changes = !git.modified_files.grep(/^lib/).empty?
15
+ has_test_changes = !git.modified_files.grep(/^test/).empty?
16
+ has_changelog_changes = git.modified_files.include?("CHANGELOG.md")
17
+
18
+ # ------------------------------------------------------------------------------
19
+ # You've made changes to lib, but didn't write any tests?
20
+ # ------------------------------------------------------------------------------
21
+ if has_lib_changes && !has_test_changes
22
+ warn("There are code changes, but no corresponding tests. "\
23
+ "Please include tests if this PR introduces any modifications in "\
24
+ "#{project_name}'s behavior.",
25
+ :sticky => false)
26
+ end
27
+
28
+ # ------------------------------------------------------------------------------
29
+ # Have you updated CHANGELOG.md?
30
+ # ------------------------------------------------------------------------------
31
+ if !has_changelog_changes && has_lib_changes
32
+ markdown <<-MARKDOWN
33
+ Here's an example of a CHANGELOG.md entry (place it immediately under the `* Your contribution here!` line):
34
+
35
+ ```markdown
36
+ * [##{pr_number}](#{pr_url}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author})
37
+ ```
38
+ MARKDOWN
39
+ warn("Please update CHANGELOG.md with a description of your changes. "\
40
+ "If this PR is not a user-facing change (e.g. just refactoring), "\
41
+ "you can disregard this.", :sticky => false)
42
+ end
43
+
44
+ # ------------------------------------------------------------------------------
45
+ # Did you remove the CHANGELOG's "Your contribution here!" line?
46
+ # ------------------------------------------------------------------------------
47
+ if has_changelog_changes
48
+ unless IO.read("CHANGELOG.md") =~ /^\* Your contribution here/i
49
+ fail(
50
+ "Please put the `* Your contribution here!` line back into CHANGELOG.md.",
51
+ :sticky => false
52
+ )
53
+ end
54
+ end
data/README.md CHANGED
@@ -38,7 +38,7 @@ gem install chandler
38
38
 
39
39
  ### 2. Configure .netrc or set ENV vars
40
40
 
41
- In order to access the GitHub API on your behalf, you must provide chandler with your GitHub credentials.
41
+ In order to access the GitHub API on your behalf, you must provide chandler with your GitHub credentials.
42
42
 
43
43
  Do this by creating a `~/.netrc` file with your GitHub username and password, like this:
44
44
 
@@ -80,6 +80,21 @@ Other command-line options:
80
80
  * `--changelog=History.md` – location of the CHANGELOG (defaults to `CHANGELOG.md`)
81
81
  * `--tag-prefix=myapp-` – specify Git version tags are in the format `myapp-1.0.0` instead of `1.0.0`
82
82
 
83
+ ## GitHub Enterprise
84
+
85
+ Chandler supports GitHub Enterprise as well as public GitHub repositories. It will make an educated guess as to where your GitHub Enterprise installation is located based on the `origin` git remote. You can also specify your GitHub Enterprise repository using the `--github` option like this:
86
+
87
+ ```
88
+ --github=git@github.mycompany.com:organization/project.git
89
+ ```
90
+
91
+ Or like this:
92
+
93
+ ```
94
+ --github=https://github.mycompany.com/organization/project
95
+ ```
96
+
97
+ To authenticate, Chandler relies on your `~/.netrc`, as explained above. Replace `api.github.com` with the hostname of your GitHub Enterprise installation (`github.mycompany.com` in the example).
83
98
 
84
99
  ## Rakefile integration
85
100
 
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.10"
27
27
  spec.add_development_dependency "coveralls"
28
+ spec.add_development_dependency "danger"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
29
30
  spec.add_development_dependency "minitest"
30
31
  spec.add_development_dependency "minitest-reporters"
@@ -30,7 +30,10 @@ module Chandler
30
30
  @args = unprocessed.compact
31
31
  end
32
32
 
33
- def option_parser # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
33
+ # rubocop:disable Metrics/AbcSize
34
+ # rubocop:disable Metrics/MethodLength
35
+ # rubocop:disable Metrics/BlockLength
36
+ def option_parser
34
37
  OptionParser.new do |opts|
35
38
  opts.banner = "Usage: chandler push [tag] [options]"
36
39
  opts.separator("")
@@ -23,23 +23,6 @@ module Chandler
23
23
  @git ||= Chandler::Git.new(:path => git_path, :tag_mapper => tag_mapper)
24
24
  end
25
25
 
26
- def octokit
27
- @octokit ||= Octokit::Client.new(octokit_options)
28
- end
29
-
30
- def octokit_options
31
- chandler_token_key = "CHANDLER_GITHUB_API_TOKEN"
32
- if environment[chandler_token_key]
33
- { :access_token => environment[chandler_token_key] }
34
- else
35
- { :netrc => true }
36
- end
37
- end
38
-
39
- def environment
40
- @environment ||= ENV
41
- end
42
-
43
26
  def github
44
27
  @github ||= Chandler::GitHub.new(
45
28
  :repository => github_repository,
@@ -1,4 +1,6 @@
1
- require "octokit"
1
+ require "chandler/github/client"
2
+ require "chandler/github/errors"
3
+ require "chandler/github/remote"
2
4
 
3
5
  module Chandler
4
6
  # A facade for performing GitHub API operations on a given GitHub repository
@@ -7,12 +9,11 @@ module Chandler
7
9
  # is available in the host environment at "CHANDLER_GITHUB_API_TOKEN""
8
10
  #
9
11
  class GitHub
10
- MissingCredentials = Class.new(StandardError)
11
-
12
12
  attr_reader :repository, :config
13
13
 
14
14
  def initialize(repository:, config:)
15
- @repository = parse_repository(repository)
15
+ @repository = repository
16
+ @remote = Remote.parse(repository)
16
17
  @config = config
17
18
  end
18
19
 
@@ -23,16 +24,16 @@ module Chandler
23
24
  return update_release(release, title, description) if release
24
25
 
25
26
  create_release(tag, title, description)
27
+ rescue Octokit::NotFound
28
+ raise InvalidRepository, repository
26
29
  end
27
30
 
28
31
  private
29
32
 
30
- def parse_repository(repo)
31
- repo[%r{(git@github.com:|://github.com/)(.*)\.git}, 2] || repo
32
- end
33
+ attr_reader :remote
33
34
 
34
35
  def existing_release(tag)
35
- release = client.release_for_tag(repository, tag)
36
+ release = client.release_for_tag(remote.repository, tag)
36
37
  release.id.nil? ? nil : release
37
38
  rescue Octokit::NotFound
38
39
  nil
@@ -48,21 +49,13 @@ module Chandler
48
49
  end
49
50
 
50
51
  def create_release(tag, title, desc)
51
- client.create_release(repository, tag, :name => title, :body => desc)
52
+ client.create_release(
53
+ remote.repository, tag, :name => title, :body => desc
54
+ )
52
55
  end
53
56
 
54
57
  def client
55
- @client ||= begin
56
- octokit = config.octokit
57
- octokit.login ? octokit : fail_missing_credentials
58
- end
59
- end
60
-
61
- def fail_missing_credentials
62
- message = "Couldn’t load GitHub credentials from ~/.netrc.\n"
63
- message << "For .netrc instructions, see: "
64
- message << "https://github.com/octokit/octokit.rb#using-a-netrc-file"
65
- raise MissingCredentials, message
58
+ @client ||= Client.new(:host => remote.host).tap(&:login!)
66
59
  end
67
60
  end
68
61
  end
@@ -0,0 +1,42 @@
1
+ require "chandler/github/errors"
2
+ require "delegate"
3
+ require "octokit"
4
+ require "uri"
5
+
6
+ module Chandler
7
+ class GitHub
8
+ # A thin wrapper around Octokit::Client that adds support for automatic
9
+ # GitHub Enterprise, .netrc, and ENV token-based authentication.
10
+ #
11
+ class Client < SimpleDelegator
12
+ def initialize(host: "github.com",
13
+ environment: ENV,
14
+ octokit_client: Octokit::Client)
15
+ options = {}
16
+ options.merge!(detect_auth_option(environment))
17
+ options.merge!(detect_enterprise_endpoint(host))
18
+ super(octokit_client.new(options))
19
+ end
20
+
21
+ def login!
22
+ return if login
23
+ raise netrc ? NetrcAuthenticationFailure : TokenAuthenticationFailure
24
+ end
25
+
26
+ private
27
+
28
+ def detect_auth_option(env)
29
+ if (token = env["CHANDLER_GITHUB_API_TOKEN"])
30
+ { :access_token => token }
31
+ else
32
+ { :netrc => true }
33
+ end
34
+ end
35
+
36
+ def detect_enterprise_endpoint(host)
37
+ return {} if host.downcase == "github.com"
38
+ { :api_endpoint => "https://#{host}/api/v3/" }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,34 @@
1
+ module Chandler
2
+ class GitHub
3
+ Error = Class.new(StandardError)
4
+
5
+ class InvalidRepository < Error
6
+ def initialize(repository)
7
+ @repository = repository
8
+ end
9
+
10
+ def message
11
+ "Failed to find GitHub repository: #{@repository}.\n"\
12
+ "Verify you have permission to access it. Use the --github option to "\
13
+ "specify a different repository."
14
+ end
15
+ end
16
+
17
+ class NetrcAuthenticationFailure < Error
18
+ def message
19
+ "GitHub authentication failed.\n"\
20
+ "Check that ~/.netrc is properly configured.\n"\
21
+ "For instructions, see: "\
22
+ "https://github.com/octokit/octokit.rb#using-a-netrc-file"
23
+ end
24
+ end
25
+
26
+ class TokenAuthenticationFailure < Error
27
+ def message
28
+ "GitHub authentication failed.\n"\
29
+ "Check that the CHANDLER_GITHUB_API_TOKEN environment variable "\
30
+ "is correct."
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ require "uri"
2
+
3
+ module Chandler
4
+ class GitHub
5
+ # Assuming a git remote points to a public GitHub or a GitHub Enterprise
6
+ # repository, this class parses the remote to obtain the host and repository
7
+ # path. Supports SSH and HTTPS style git remotes.
8
+ #
9
+ # This class also handles parsing values passed into the `--github` command
10
+ # line option, which may be a public GitHub repository name, like
11
+ # "mattbrictson/chandler".
12
+ #
13
+ class Remote
14
+ def self.parse(url)
15
+ if (match = url.match(/@([^:]+):(.+)$/))
16
+ new(match[1], match[2])
17
+ else
18
+ parsed_uri = URI(url)
19
+ host = parsed_uri.host || "github.com"
20
+ path = parsed_uri.path.sub(%r{^/+}, "")
21
+ new(host, path)
22
+ end
23
+ end
24
+
25
+ attr_reader :host, :path
26
+
27
+ def initialize(host, path)
28
+ @host = host.downcase
29
+ @path = path
30
+ end
31
+
32
+ def repository
33
+ path.sub(/\.git$/, "")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,6 +2,7 @@ require "bundler/gem_helper"
2
2
  require "chandler/configuration"
3
3
  require "chandler/refinements/version_format"
4
4
  require "chandler/commands/push"
5
+ require "rake"
5
6
 
6
7
  using Chandler::Refinements::VersionFormat
7
8
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Chandler
3
- VERSION = "0.5.0".freeze
3
+ VERSION = "0.6.0".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chandler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brictson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-07 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netrc
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: danger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,7 @@ files:
150
164
  - CHANGELOG.md
151
165
  - CODE_OF_CONDUCT.md
152
166
  - CONTRIBUTING.md
167
+ - Dangerfile
153
168
  - Gemfile
154
169
  - Guardfile
155
170
  - LICENSE.txt
@@ -168,6 +183,9 @@ files:
168
183
  - lib/chandler/configuration.rb
169
184
  - lib/chandler/git.rb
170
185
  - lib/chandler/github.rb
186
+ - lib/chandler/github/client.rb
187
+ - lib/chandler/github/errors.rb
188
+ - lib/chandler/github/remote.rb
171
189
  - lib/chandler/logger.rb
172
190
  - lib/chandler/logging.rb
173
191
  - lib/chandler/refinements/color.rb
@@ -194,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
212
  version: '0'
195
213
  requirements: []
196
214
  rubyforge_project:
197
- rubygems_version: 2.5.1
215
+ rubygems_version: 2.6.8
198
216
  signing_key:
199
217
  specification_version: 4
200
218
  summary: Syncs CHANGELOG entries to GitHub's release notes