~edwargix/git.sr.ht

bef092a7098f3746d8039946270d976f0a579750 — Ivan Habunek 7 years ago 4f6d1a5
Extract clone_urls to a filter
M gitsrht/app.py => gitsrht/app.py +1 -0
@@ 38,6 38,7 @@ class GitApp(SrhtFlask):
        self.register_blueprint(stats)
        self.register_blueprint(manage)

        self.add_template_filter(urls.clone_urls)
        self.add_template_filter(urls.log_rss_url)
        self.add_template_filter(urls.refs_rss_url)


M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +4 -11
@@ 108,17 108,11 @@ def get_last_3_commits(commit):
@repo.route("/<owner>/<repo>")
def summary(owner, repo):
    owner, repo = get_repo_or_redir(owner, repo)

    with GitRepository(repo.path) as git_repo:
        base = (cfg("git.sr.ht", "origin")
            .replace("http://", "")
            .replace("https://", ""))
        clone_urls = [
            url.format(base, owner.canonical_name, repo.name)
            for url in ["https://{}/{}/{}", "git@{}:{}/{}"]
        ]
        if git_repo.is_empty:
            return render_template("empty-repo.html", owner=owner, repo=repo,
                    clone_urls=clone_urls)
            return render_template("empty-repo.html", owner=owner, repo=repo)

        default_branch = git_repo.default_branch()
        tip = git_repo.get(default_branch.target)
        commits = get_last_3_commits(tip)


@@ 130,8 124,7 @@ def summary(owner, repo):
        latest_tag = tags[0] if len(tags) else None
        return render_template("summary.html", view="summary",
                owner=owner, repo=repo, readme=readme, commits=commits,
                clone_urls=clone_urls, latest_tag=latest_tag,
                default_branch=default_branch)
                latest_tag=latest_tag, default_branch=default_branch)

def lookup_ref(git_repo, ref):
    ref = ref or git_repo.default_branch().name[len("refs/heads/"):]

M gitsrht/templates/empty-repo.html => gitsrht/templates/empty-repo.html +4 -2
@@ 21,12 21,14 @@
  <div class="row" style="margin-bottom: 1rem">
    <div class="col-md-4">
      <h3>clone</h3>
      {% with read_only, read_write = repo|clone_urls %}
      <dl>
        <dt>read-only</dt>
        <dd><a href="{{clone_urls[0]}}">{{clone_urls[0]}}</a></dd>
        <dd><a href="{{read_only}}">{{read_only}}</a></dd>
        <dt>read/write</dt>
        <dd>{{clone_urls[1]}}</dd>
        <dd>{{read_write}}</dd>
      </dl>
      {% endwith %}
    </div>
    <div class="col-md-8">
      <p>

M gitsrht/templates/summary.html => gitsrht/templates/summary.html +4 -2
@@ 51,12 51,14 @@
    </div>
    <div class="col-md-4">
      <h3>clone</h3>
      {% with read_only, read_write = repo|clone_urls %}
      <dl>
        <dt>read-only</dt>
        <dd><a href="{{clone_urls[0]}}">{{clone_urls[0]}}</a></dd>
        <dd><a href="{{read_only}}">{{read_only}}</a></dd>
        <dt>read/write</dt>
        <dd>{{clone_urls[1]}}</dd>
        <dd>{{read_write}}</dd>
      </dl>
      {% endwith %}
    </div>
  </div>
  {% if readme %}

M gitsrht/urls.py => gitsrht/urls.py +12 -0
@@ 1,4 1,16 @@
from flask import url_for
from srht.config import cfg

def clone_urls(repo):
    """Returns the readonly and read/write URL for a given repo."""
    base = (cfg("git.sr.ht", "origin")
        .replace("http://", "")
        .replace("https://", ""))

    return [
        url.format(base, repo.owner.canonical_name, repo.name)
        for url in ["https://{}/{}/{}", "git@{}:{}/{}"]
    ]

def log_rss_url(repo, ref=None):
    ref = ref if ref != "master" else None