~edwargix/git.sr.ht

247556ea06b5a16a7c3b4b38bd7a84acbcfcc2b0 — Drew DeVault 6 years ago c667ae0
Detect repositories w/o a license, show warning

This links users to the following page with advice on choosing a
software license:

https://man.sr.ht/license.md
2 files changed, 25 insertions(+), 1 deletions(-)

M gitsrht/blueprints/repo.py
M gitsrht/templates/summary.html
M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +13 -1
@@ 103,12 103,24 @@ def summary(owner, repo):
        tags = sorted(tags, key=lambda c: commit_time(c[1]), reverse=True)
        latest_tag = tags[0] if len(tags) else None

        license = False
        for path in [
                "LICENSE", "COPYING",
                "LICENSE.txt", "license.txt",
                "COPYING.txt", "copying.txt",
                "LICENSE.md", "license.md",
                "COPYING.md", "copying.md",
        ]:
            if path in tip.tree:
                license = True
                break

        message = session.pop("message", None)
        return render_template("summary.html", view="summary",
                owner=owner, repo=repo, readme=readme, commits=commits,
                latest_tag=latest_tag, default_branch=default_branch,
                is_annotated=lambda t: isinstance(t, pygit2.Tag),
                message=message)
                message=message, license=license)

@repo.route("/<owner>/<repo>/<path:path>")
def go_get(owner, repo, path):

M gitsrht/templates/summary.html => gitsrht/templates/summary.html +12 -0
@@ 119,6 119,18 @@
      </div>
    </div>
  </div>
  {% if current_user.id == repo.owner_id
    and not license
    and repo.visibility.value == 'public' %}
  <div class="alert alert-danger">
    <strong>Head's up!</strong> We couldn't find a license file for your
    repository, which means that it may not be possible for others to use this
    project. If you're unsure of how to choose a license, consult our wiki page,
    <a
      href="https://man.sr.ht/license.md" rel="noopener"
    >choosing a software license</a>.
  </div>
  {% endif %}
  {% if readme %}
  <div class="row" id="readme">
    <div class="col-md-10">