Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: also detect variations in license-file names in GitHub repos, such as LICENSE.md #460

Closed
mklement0 opened this issue Jun 3, 2015 · 4 comments

Comments

@mklement0
Copy link
Contributor

It seems that currently only files named LICENSE are recognized for GitHub-license badge URLs such as https://img.shields.io/github/license/mklement0/make-pkg.svg.

The above badge link is for a repo (of mine) that has a LICENSE.md file in lieu of LICENSE, which, unfortunately, renders the badge with "unknown license".

It would be great if filename variations such as LICENSE.md or LICENSE.markdown were recognized as well.

P.S.: Thanks for a great site and service.

@espadrine
Copy link
Member

Why presume when the source is there? ;)

We actually rely on GitHub to give us the correct license.

However, if you paste your repo's URL https://github.com/mklement0/make-pkg into the search bar in shields.io and press “Suggest badges”, the correct (static) license badge will show up!

Then, click on the badge to be able to copy and paste it into wherever!

@mklement0
Copy link
Contributor Author

Thanks for pointing me in the right direction.

To summarize: my diagnosis was speculative and incorrect; the truth is:

  • It is the GitHub API that provides the license information (the license-related part of the API is in developer preview as of this writing).
  • It does account for variations in license filenames (including the British spelling, "licence"), but the difficulty lies in having to identify the license by the files' contents, which doesn't always work.

Therefore, I'll go bug the GitHub people about it.


(I'm being less speculative here, but I'm still shy about digging into the source myself.)

The "Suggest badges" code must be different, because it works for repos that the GitHub-repo-URL-based badges don't work with, and vice versa.

I'm looking for a programmatic solution, and it seems (speculation alert) that a license-ID-based badge can be constructed as follows:

https://img.shields.io/badge/license-{{SPDX license ID with dashes doubled}}-blue.svg

E.g., for the BSD-3-Clause license: https://img.shields.io/badge/license-BSD--3--Clause-blue.svg

@espadrine
Copy link
Member

Wow, apparently “licence” is not just used in the UK, it is also in use in Canada and Australia!

The "Suggest badges” code lies in suggest.js. The reason it is separate is that I allow very slow code there, code that can take several seconds. The license badge offered by suggestion makes a series of API calls to GitHub to find the license file, and compares its contents with a number of known licenses to figure out which it is. Then, it delivers a custom badge, one which does not need to make any computation whatsoever.

Custom badges are detailed at the bottom of https://shields.io. You could put https://img.shields.io/badge/licence-BSD--3--Clause-blue.svg (with s/license/licence/), if you prefer, or any other text, or any other color. Blue is roughly standard for license badges.

@mklement0
Copy link
Contributor Author

Wow, apparently “licence” is not just used in the UK, it is also in use in Canada and Australia!

Let's not forget India, South Africa, Singapore ... (Commonwealth of Nations members), "[w]here written English (...) generally favours British as opposed to American spelling, with one notable exception being Canada, where there is also a strong influence from neighbouring American English." [1]

Re "Suggest badges” :

Thanks for the explanation, that's helpful. Here's one example where the GitHub API succeeds, but your code doesn't. It is admittedly a strange corner case and may not be worth handling: the license file contains the literal text of the BSD-2-Clause with the list numbering removed (and whitespace differences):
https://github.com/tlevine/urchin/blob/master/LICENCE

Re custom badges:

Again, good to know, thanks. Looks like I simply created a custom badge and speculatively read special significance into it (non-existent interpretation of an SPDX license ID).

What a speculationfest. But festivities are over now. Thanks for all your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants