From 247556ea06b5a16a7c3b4b38bd7a84acbcfcc2b0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 23 Jan 2020 11:21:27 -0500 Subject: [PATCH] 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 --- gitsrht/blueprints/repo.py | 14 +++++++++++++- gitsrht/templates/summary.html | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index df23874..85da77d 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -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("///") def go_get(owner, repo, path): diff --git a/gitsrht/templates/summary.html b/gitsrht/templates/summary.html index 6e5bc5f..cc74448 100644 --- a/gitsrht/templates/summary.html +++ b/gitsrht/templates/summary.html @@ -119,6 +119,18 @@ + {% if current_user.id == repo.owner_id + and not license + and repo.visibility.value == 'public' %} +
+ Head's up! 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, + choosing a software license. +
+ {% endif %} {% if readme %}
-- 2.38.4