coconductor 0.2.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 +7 -0
- data/.github/CODEOWNERS +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
- data/.github/config.yml +23 -0
- data/.github/no-response.yml +15 -0
- data/.github/release-drafter.yml +4 -0
- data/.github/settings.yml +33 -0
- data/.github/stale.yml +29 -0
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +8 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +6 -0
- data/bin/coconductor +32 -0
- data/coconductor.gemspec +34 -0
- data/docs/CODE_OF_CONDUCT.md +73 -0
- data/docs/CONTRIBUTING.md +85 -0
- data/lib/coconductor.rb +33 -0
- data/lib/coconductor/code_of_conduct.rb +155 -0
- data/lib/coconductor/commands/detect.rb +63 -0
- data/lib/coconductor/commands/diff.rb +75 -0
- data/lib/coconductor/commands/version.rb +6 -0
- data/lib/coconductor/matchers.rb +8 -0
- data/lib/coconductor/matchers/dice.rb +10 -0
- data/lib/coconductor/matchers/exact.rb +7 -0
- data/lib/coconductor/matchers/field_aware.rb +34 -0
- data/lib/coconductor/matchers/matcher.rb +9 -0
- data/lib/coconductor/project_files.rb +6 -0
- data/lib/coconductor/project_files/code_of_conduct_file.rb +22 -0
- data/lib/coconductor/project_files/project_file.rb +13 -0
- data/lib/coconductor/projects.rb +8 -0
- data/lib/coconductor/projects/fs_project.rb +24 -0
- data/lib/coconductor/projects/git_project.rb +30 -0
- data/lib/coconductor/projects/github_project.rb +8 -0
- data/lib/coconductor/projects/project.rb +33 -0
- data/lib/coconductor/version.rb +3 -0
- data/script/bootstrap +6 -0
- data/script/cibuild +9 -0
- data/script/console +6 -0
- data/script/vendor-codes-of-conduct +39 -0
- data/vendor/citizen-code-of-conduct/version/2/0/citizen_code_of_conduct.md +127 -0
- data/vendor/citizen-code-of-conduct/version/2/1/citizen_code_of_conduct.md +90 -0
- data/vendor/citizen-code-of-conduct/version/2/2/citizen_code_of_conduct.md +92 -0
- data/vendor/citizen-code-of-conduct/version/2/3/citizen_code_of_conduct.md +98 -0
- data/vendor/contributor-covenant/version/1/0/0/code-of-conduct.md +18 -0
- data/vendor/contributor-covenant/version/1/1/0/code-of-conduct.md +20 -0
- data/vendor/contributor-covenant/version/1/2/0/code-of-conduct.md +27 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.de.md +29 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.es.md +28 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.fr.md +56 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.hu.md +29 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.it.md +29 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.ja.md +48 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.md +53 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.pl.md +29 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.pt-br.md +54 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.pt.md +54 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.ru.md +54 -0
- data/vendor/contributor-covenant/version/1/3/0/code-of-conduct.sl.md +52 -0
- data/vendor/contributor-covenant/version/1/4/.index-template.html +19 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.bn.md +74 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.bs.md +50 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.de.md +48 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.el.md +79 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.es.md +50 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.fa-ir.md +65 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.fr.md +82 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.hi.md +50 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.id.md +67 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.is.md +78 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.iw.md +65 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.ja.md +75 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.kn.md +52 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.ko.md +67 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.md +78 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.mk.md +51 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.nl.md +77 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.pl.md +82 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.pt-br.md +76 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.pt.md +81 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.ro.md +75 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.ru.md +48 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.sl.md +77 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.sv.md +79 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.tr.md +73 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.uk.md +77 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.zh-cn.md +57 -0
- data/vendor/contributor-covenant/version/1/4/code-of-conduct.zh-tw.md +57 -0
- metadata +239 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Contributing to Coconductor
|
|
2
|
+
|
|
3
|
+
Hi there! We're thrilled that you'd like to contribute to Coconductor. Your help is essential for keeping it great.
|
|
4
|
+
|
|
5
|
+
Coconductor is an open source project supported by the efforts of an entire community and built one contribution at a time by users like you. We'd love for you to get involved. Whatever your level of skill or however much time you can give, your contribution is greatly appreciated. There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests, helping other users by commenting on issues, or writing code which can be incorporated into Coconductor itself.
|
|
6
|
+
|
|
7
|
+
Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue, assessing changes, and helping you finalize your pull requests.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## How to report a bug
|
|
12
|
+
|
|
13
|
+
Think you found a bug? Please check [the list of open issues](https://github.com/benbalter/coconductor/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/coconductor/issues/new).
|
|
14
|
+
|
|
15
|
+
Here are a few tips for writing *great* bug reports:
|
|
16
|
+
|
|
17
|
+
* Describe the specific problem (e.g., "widget doesn't turn clockwise" versus "getting an error")
|
|
18
|
+
* Include the steps to reproduce the bug, what you expected to happen, and what happened instead
|
|
19
|
+
* Check that you are using the latest version of the project and its dependencies
|
|
20
|
+
* Include what version of the project your using, as well as any relevant dependencies
|
|
21
|
+
* Only include one bug per issue. If you have discovered two bugs, please file two issues
|
|
22
|
+
* Include screenshots or screencasts whenever possible
|
|
23
|
+
* Even if you don't know how to fix the bug, including a failing test may help others track it down
|
|
24
|
+
|
|
25
|
+
**If you find a security vulnerability, do not open an issue. Please email ben@balter.com instead.**
|
|
26
|
+
|
|
27
|
+
## How to suggest a feature or enhancement
|
|
28
|
+
|
|
29
|
+
If you find yourself wishing for a feature that doesn't exist in Coconductor, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Coconductor has today have been added because our users saw the need.
|
|
30
|
+
|
|
31
|
+
Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and goals of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible, including describing the problem you're trying to solve.
|
|
32
|
+
|
|
33
|
+
[Open an issue](https://github.com/benbalter/coconductor/issues/new) which describes the feature you would like to see, why you want it, how it should work, etc.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Your first contribution
|
|
38
|
+
|
|
39
|
+
We'd love for you to contribute to the project. Unsure where to begin contributing to Coconductor? You can start by looking through these "good first issue" and "help wanted" issues:
|
|
40
|
+
|
|
41
|
+
* [Good first issues](https://github.com/benbalter/coconductor/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) - issues which should only require a few lines of code and a test or two
|
|
42
|
+
* [Help wanted issues](https://github.com/benbalter/coconductor/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) - issues which may be a bit more involved, but are specifically seeking community contributions
|
|
43
|
+
|
|
44
|
+
*p.s. Feel free to ask for help; everyone is a beginner at first* :smiley_cat:
|
|
45
|
+
|
|
46
|
+
## How to propose changes
|
|
47
|
+
|
|
48
|
+
Here's a few general guidelines for proposing changes:
|
|
49
|
+
|
|
50
|
+
* If you are changing any user-facing functionality, please be sure to update the documentation
|
|
51
|
+
* If you are adding a new behavior or changing an existing behavior, please be sure to update the corresponding test(s)
|
|
52
|
+
* Each pull request should implement **one** feature or bug fix. If you want to add or fix more than one thing, submit more than one pull request
|
|
53
|
+
* Do not commit changes to files that are irrelevant to your feature or bug fix
|
|
54
|
+
* Don't bump the version number in your pull request (it will be bumped prior to release)
|
|
55
|
+
* Write [a good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
|
|
56
|
+
|
|
57
|
+
At a high level, [the process for proposing changes](https://guides.github.com/introduction/flow/) is:
|
|
58
|
+
|
|
59
|
+
1. [Fork](https://github.com/benbalter/coconductor/fork) and clone the project
|
|
60
|
+
2. Configure and install the dependencies: `script/bootstrap`
|
|
61
|
+
3. Make sure the tests pass on your machine: `script/cibuild`
|
|
62
|
+
4. Create a descriptively named branch: `git checkout -b my-branch-name`
|
|
63
|
+
5. Make your change, add tests and documentation, and make sure the tests still pass
|
|
64
|
+
6. Push to your fork and [submit a pull request](https://github.com/benbalter/coconductor/compare) describing your change
|
|
65
|
+
7. Pat your self on the back and wait for your pull request to be reviewed and merged
|
|
66
|
+
|
|
67
|
+
**Interesting in submitting your first Pull Request?** It's easy! You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)
|
|
68
|
+
|
|
69
|
+
## Bootstrapping your local development environment
|
|
70
|
+
|
|
71
|
+
`script/bootstrap`
|
|
72
|
+
|
|
73
|
+
## Running tests
|
|
74
|
+
|
|
75
|
+
`script/cibuild`
|
|
76
|
+
|
|
77
|
+
## Code of conduct
|
|
78
|
+
|
|
79
|
+
This project is governed by [the Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
|
|
80
|
+
|
|
81
|
+
## Additional Resources
|
|
82
|
+
|
|
83
|
+
* [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/)
|
|
84
|
+
* [Using Pull Requests](https://help.github.com/articles/using-pull-requests/)
|
|
85
|
+
* [GitHub Help](https://help.github.com)
|
data/lib/coconductor.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'coconductor/version'
|
|
2
|
+
require 'licensee'
|
|
3
|
+
|
|
4
|
+
module Coconductor
|
|
5
|
+
autoload :CodeOfConduct, 'coconductor/code_of_conduct'
|
|
6
|
+
autoload :Matchers, 'coconductor/matchers'
|
|
7
|
+
autoload :Projects, 'coconductor/projects'
|
|
8
|
+
autoload :ProjectFiles, 'coconductor/project_files'
|
|
9
|
+
|
|
10
|
+
CONFIDENCE_THRESHOLD = 90
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
attr_writer :confidence_threshold
|
|
14
|
+
|
|
15
|
+
def codes_of_conduct
|
|
16
|
+
CodeOfConduct.all
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def code_of_conduct(path)
|
|
20
|
+
Coconductor.project(path).code_of_conduct
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def project(path, **args)
|
|
24
|
+
Coconductor::Projects::GitProject.new(path, args)
|
|
25
|
+
rescue Coconductor::Projects::GitProject::InvalidRepository
|
|
26
|
+
Coconductor::Projects::FSProject.new(path, args)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def confidence_threshold
|
|
30
|
+
@confidence_threshold ||= CONFIDENCE_THRESHOLD
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
require 'toml'
|
|
2
|
+
|
|
3
|
+
module Coconductor
|
|
4
|
+
class InvalidCodeOfConduct < ArgumentError; end
|
|
5
|
+
class CodeOfConduct
|
|
6
|
+
VENDORED_CODES_OF_CONDUCT = %w[
|
|
7
|
+
citizen-code-of-conduct
|
|
8
|
+
contributor-covenant
|
|
9
|
+
].freeze
|
|
10
|
+
|
|
11
|
+
KEY_REGEX = %r{
|
|
12
|
+
(?<family>#{Regexp.union(VENDORED_CODES_OF_CONDUCT)})
|
|
13
|
+
/version
|
|
14
|
+
/(?<major>\d)/(?<minor>\d)(/(?<patch>\d))?
|
|
15
|
+
/#{Coconductor::ProjectFiles::CodeOfConductFile::FILENAME_REGEX}
|
|
16
|
+
}ix
|
|
17
|
+
FIELD_REGEX = /\[(?<name>[A-Z_ ]{2,}).*\]/
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
def all
|
|
21
|
+
@all ||= keys.map { |key| new(key) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def find(key)
|
|
25
|
+
all.find { |coc| coc.key == key }
|
|
26
|
+
end
|
|
27
|
+
alias [] find
|
|
28
|
+
alias find_by_key find
|
|
29
|
+
|
|
30
|
+
def vendor_dir
|
|
31
|
+
@vendor_dir ||= Pathname.new File.expand_path '../../vendor', __dir__
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def keys
|
|
35
|
+
@keys ||= vendored_codes_of_conduct.map do |path|
|
|
36
|
+
path = Pathname.new(path)
|
|
37
|
+
key = path.relative_path_from(vendor_dir)
|
|
38
|
+
matches = KEY_REGEX.match(key.to_path)
|
|
39
|
+
matches.to_a.compact[1..-1].insert(1, 'version').join('/') if matches
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def vendored_codes_of_conduct
|
|
46
|
+
@vendored_codes_of_conduct ||= begin
|
|
47
|
+
cocs = "{#{VENDORED_CODES_OF_CONDUCT.join(',')}}"
|
|
48
|
+
path = File.join vendor_dir, cocs, '**', '*.md'
|
|
49
|
+
Dir.glob(path)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
attr_reader :key
|
|
55
|
+
attr_writer :content
|
|
56
|
+
include Licensee::ContentHelper
|
|
57
|
+
|
|
58
|
+
def initialize(key)
|
|
59
|
+
@key = key
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def version
|
|
63
|
+
toml['version']
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def language
|
|
67
|
+
@language ||= begin
|
|
68
|
+
parts = key.split('/')
|
|
69
|
+
parts.last if parts.last =~ /^[a-z-]{2,5}$/
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def name
|
|
74
|
+
return @name if defined? @name
|
|
75
|
+
@name = name_without_version.dup
|
|
76
|
+
@name << " (#{language.upcase})" if language
|
|
77
|
+
@name << " v#{version}" if version
|
|
78
|
+
@name
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def name_without_version
|
|
82
|
+
@name_without_version ||= begin
|
|
83
|
+
key.split('/').first.split('-').map(&:capitalize).join(' ')
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def content
|
|
88
|
+
@content ||= parts.last
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def inspect
|
|
92
|
+
"#<Licensee::CodeOfConduct key=#{key}>"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def family
|
|
96
|
+
@family ||= key.split('/').first
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def contributor_covenant?
|
|
100
|
+
family == 'contributor-covenant'
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def citizen_code_of_conduct?
|
|
104
|
+
family == 'citizen-code-of-conduct'
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def fields
|
|
108
|
+
content.scan(FIELD_REGEX).flatten
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
def filename
|
|
114
|
+
if contributor_covenant?
|
|
115
|
+
filename = 'code-of-conduct'
|
|
116
|
+
elsif citizen_code_of_conduct?
|
|
117
|
+
filename = 'citizen_code_of_conduct'
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
filename << '.' + language if language
|
|
121
|
+
filename << '.md'
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def path
|
|
125
|
+
parts = key.split('/')
|
|
126
|
+
parts.pop if language
|
|
127
|
+
path = File.join(*parts[0...5], filename)
|
|
128
|
+
path = File.expand_path path, self.class.vendor_dir
|
|
129
|
+
Pathname.new(path)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Raw content of code of conduct file, including TOML front matter
|
|
133
|
+
def raw_content
|
|
134
|
+
unless File.exist?(path)
|
|
135
|
+
msg = "'#{key}' is not a valid code of conduct key"
|
|
136
|
+
raise Coconductor::InvalidCodeOfConduct, msg
|
|
137
|
+
end
|
|
138
|
+
@raw_content ||= File.read(path, encoding: 'utf-8')
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def toml
|
|
142
|
+
@toml ||= begin
|
|
143
|
+
if parts.length == 3
|
|
144
|
+
TOML::Parser.new(parts[1]).parsed
|
|
145
|
+
else
|
|
146
|
+
{}
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def parts
|
|
152
|
+
@parts ||= raw_content.split('+++')
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
class CoconductorCLI < Thor
|
|
2
|
+
desc 'detect [PATH]', 'Detect the code of conduct of the given project', default: Dir.pwd
|
|
3
|
+
option :confidence, type: :numeric, default: Coconductor.confidence_threshold, desc: 'Confidence threshold'
|
|
4
|
+
option :diff, type: :boolean, desc: 'Compare the code of conduct to the closest match'
|
|
5
|
+
option :code_of_conduct, type: :string, desc: 'The key of the code of conduct to compare (implies --diff)'
|
|
6
|
+
|
|
7
|
+
def detect(_path = nil)
|
|
8
|
+
Coconductor.confidence_threshold = options[:confidence]
|
|
9
|
+
rows = []
|
|
10
|
+
rows << if code_of_conduct
|
|
11
|
+
['Code of conduct:', code_of_conduct.name]
|
|
12
|
+
else
|
|
13
|
+
['Code of conduct:', set_color('None', :red)]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
unless code_of_conduct.nil?
|
|
17
|
+
%i[key family version language].each do |method|
|
|
18
|
+
value = code_of_conduct.public_send(method)
|
|
19
|
+
rows << [humanize(method, :method), humanize(value, method)] if value
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
unless code_of_conduct_file.nil?
|
|
24
|
+
%i[relative_path confidence matcher content_hash].each do |method|
|
|
25
|
+
value = code_of_conduct_file.public_send(method)
|
|
26
|
+
rows << [humanize(method, :method), humanize(value, method)] if value
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
print_table rows
|
|
31
|
+
|
|
32
|
+
return unless code_of_conduct_file && (options[:code_of_conduct] || options[:diff])
|
|
33
|
+
expected_code_of_conduct = options[:code_of_conduct] || closest_code_of_conduct
|
|
34
|
+
return unless expected_code_of_conduct
|
|
35
|
+
|
|
36
|
+
invoke(:diff, nil,
|
|
37
|
+
code_of_conduct: expected_code_of_conduct,
|
|
38
|
+
code_of_conduct_to_diff: code_of_conduct_file)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def closest_code_of_conduct
|
|
44
|
+
return unless code_of_conduct_file
|
|
45
|
+
matcher = Coconductor::Matchers::Dice.new(code_of_conduct_file)
|
|
46
|
+
matches = matcher.matches_by_similarity
|
|
47
|
+
matches.first.first.key unless matches.empty?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Given a string or object, prepares it for output and human consumption
|
|
51
|
+
def humanize(value, type = nil)
|
|
52
|
+
case type
|
|
53
|
+
when :matcher
|
|
54
|
+
value.class
|
|
55
|
+
when :confidence
|
|
56
|
+
Licensee::ContentHelper.format_percent(value)
|
|
57
|
+
when :method
|
|
58
|
+
value.to_s.tr('_', ' ').capitalize + ':'
|
|
59
|
+
else
|
|
60
|
+
value
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'tmpdir'
|
|
2
|
+
|
|
3
|
+
class CoconductorCLI < Thor
|
|
4
|
+
desc 'diff [PATH]', 'Compare the given code of conduct text to a known code of conduct'
|
|
5
|
+
option :code_of_conduct, type: :string, desc: 'The key of the code of conduct to compare'
|
|
6
|
+
|
|
7
|
+
def diff(_path = nil)
|
|
8
|
+
say "Comparing to #{expected_code_of_conduct.name}:"
|
|
9
|
+
rows = []
|
|
10
|
+
left = expected_code_of_conduct.content_normalized(wrap: 80)
|
|
11
|
+
right = code_of_conduct_to_diff.content_normalized(wrap: 80)
|
|
12
|
+
|
|
13
|
+
similarity = expected_code_of_conduct.similarity(code_of_conduct_to_diff)
|
|
14
|
+
similarity = Licensee::ContentHelper.format_percent(similarity)
|
|
15
|
+
|
|
16
|
+
rows << ['Input Length:', code_of_conduct_to_diff.length]
|
|
17
|
+
rows << ['License length:', expected_code_of_conduct.length]
|
|
18
|
+
rows << ['Similarity:', similarity]
|
|
19
|
+
print_table rows
|
|
20
|
+
|
|
21
|
+
if left == right
|
|
22
|
+
say 'Exact match!', :green
|
|
23
|
+
exit
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Dir.mktmpdir do |dir|
|
|
27
|
+
path = File.expand_path 'CODE_OF_CONDUCT', dir
|
|
28
|
+
Dir.chdir(dir) do
|
|
29
|
+
`git init`
|
|
30
|
+
File.write(path, left)
|
|
31
|
+
`git add CODE_OF_CONDUCT`
|
|
32
|
+
`git commit -m 'left'`
|
|
33
|
+
File.write(path, right)
|
|
34
|
+
say `git diff --word-diff`
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def code_of_conduct_to_diff
|
|
42
|
+
if options[:code_of_conduct_to_diff]
|
|
43
|
+
return options[:code_of_conduct_to_diff]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
@code_of_conduct_to_diff ||= begin
|
|
47
|
+
if STDIN.tty?
|
|
48
|
+
error 'You must pipe the file contents to the command via STDIN'
|
|
49
|
+
exit 1
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
filename = 'CODE_OF_CONDUCT.txt'
|
|
53
|
+
Coconductor::ProjectFiles::CodeOfConductFile.new(STDIN.read, filename)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def expected_code_of_conduct
|
|
58
|
+
if options[:code_of_conduct]
|
|
59
|
+
@expected_code_of_conduct ||= Coconductor::CodeOfConduct.find(
|
|
60
|
+
options[:code_of_conduct]
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
return @expected_code_of_conduct if @expected_code_of_conduct
|
|
64
|
+
|
|
65
|
+
if options[:code_of_conduct]
|
|
66
|
+
error "#{options[:code_of_conduct]} is not a valid code of conduct"
|
|
67
|
+
else
|
|
68
|
+
error 'You must provide an expected code of conduct'
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
keys = Coconductor.codes_of_conduct.map(&:key).join(', ')
|
|
72
|
+
error "Valid codes of conduct: #{keys}"
|
|
73
|
+
exit 1
|
|
74
|
+
end
|
|
75
|
+
end
|