Skip to content

Commit 83dc6c9

Browse files
authored
Adds ability to fetch per-repo license information (piotrmurach#344)
The Github Licenses API uses the open source Ruby Gem Licensee to attempt to identify the project's license. Licensee matches the contents of a project's LICENSE file (if it exists) against a short list of known licenses. As a result, the API does not take into account the licenses of project dependencies or other means of documenting a project's license such as references to the license name in the documentation. If a license is matched, the license key and name returned conforms to the SPDX specification. Signed-off-by: zachwick <[email protected]>
1 parent 5080af2 commit 83dc6c9

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

lib/github_api/client/repos/contents.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ def readme(*args)
3333
get_request("/repos/#{arguments.user}/#{arguments.repo}/readme", arguments.params)
3434
end
3535

36+
# Get the LICENSE
37+
#
38+
# This method returns the contents of the repository's license file, if one is detected.
39+
#
40+
# @param [Hash] params
41+
#
42+
# @example
43+
# github = Github.new
44+
# github.repos.contents.license 'user-name', 'repo-name'
45+
#
46+
# @api public
47+
def license(*args)
48+
arguments(args, required: [:user, :repo])
49+
50+
get_request("/repos/#{arguments.user}/#{arguments.repo}/license", arguments.params)
51+
end
52+
3653
# Get contents
3754
#
3855
# This method returns the contents of any file or directory in a repository.

spec/unit/api/actions_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
let(:api) { Github::Client::Repos::Contents }
77

88
it "lists all available actions for an api class" do
9-
expect(api.actions).to eq([:archive, :create, :delete, :find, :get, :readme, :update])
9+
expect(api.actions).to eq([:archive, :create, :delete, :find, :get, :license, :readme, :update])
1010
end
1111

1212
it "lists all available actions for an api instance" do
13-
expect(api.new.actions).to eq([:archive, :create, :delete, :find, :get, :readme, :update])
13+
expect(api.new.actions).to eq([:archive, :create, :delete, :find, :get, :license, :readme, :update])
1414
end
1515
end

0 commit comments

Comments
 (0)