-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1405 from mbj/add/org-license
Add organization license decoder
- Loading branch information
Showing
12 changed files
with
642 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutant | ||
module License | ||
class Subscription | ||
class Repository | ||
include Anima.new(:host, :path) | ||
|
||
REMOTE_REGEXP = /\A[^\t]+\t(?<url>[^ ]+) \((?:fetch|push)\)\n\z/.freeze | ||
GIT_SSH_REGEXP = %r{\A[^@]+@(?<host>[^:/]+)[:/](?<path>.+?)(?:\.git)?\z}.freeze | ||
GIT_HTTPS_REGEXP = %r{\Ahttps://(?<host>[^/]+)/(?<path>.+?)(?:\.git)?\z}.freeze | ||
WILDCARD = '/*' | ||
WILDCARD_RANGE = (..-WILDCARD.length).freeze | ||
|
||
private_constant(*constants(false)) | ||
|
||
def to_s | ||
[host, path].join('/') | ||
end | ||
|
||
def self.load_from_git(world) | ||
world | ||
.capture_stdout(%w[git remote --verbose]) | ||
.fmap(&method(:parse_remotes)) | ||
end | ||
|
||
def self.parse_remotes(input) | ||
input.lines.map(&method(:parse_remote)).to_set | ||
end | ||
private_class_method :parse_remotes | ||
|
||
def self.parse(input) | ||
host, path = *input.split('/', 2).map(&:downcase) | ||
new(host: host, path: path) | ||
end | ||
|
||
def self.parse_remote(input) | ||
match = REMOTE_REGEXP.match(input) or | ||
fail "Unmatched remote line: #{input.inspect}" | ||
|
||
parse_url(match[:url]) | ||
end | ||
private_class_method :parse_remote | ||
|
||
def self.parse_url(input) | ||
match = GIT_SSH_REGEXP.match(input) || GIT_HTTPS_REGEXP.match(input) | ||
|
||
unless match | ||
fail "Unmatched git remote URL: #{input.inspect}" | ||
end | ||
|
||
new(host: match[:host], path: match[:path].downcase) | ||
end | ||
private_class_method :parse_url | ||
|
||
def allow?(other) | ||
other.host.eql?(host) && path_match?(other.path) | ||
end | ||
|
||
private | ||
|
||
def path_match?(other_path) | ||
path.eql?(other_path) || wildcard_match?(path, other_path) || wildcard_match?(other_path, path) | ||
end | ||
|
||
def wildcard_match?(left, right) | ||
left.end_with?(WILDCARD) && right.start_with?(left[WILDCARD_RANGE]) | ||
end | ||
end # Repository | ||
end # Subscription | ||
end # License | ||
end # Mutant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
module Mutant | ||
# Current mutant version | ||
VERSION = '0.11.24' | ||
VERSION = '0.11.25' | ||
end # Mutant |
Oops, something went wrong.