Collection of themes/skins for the Fossil SCM

⌈⌋ ⎇ branch:  Fossil Skins Extra


Artifact [19f05e3887]

Artifact 19f05e38877aae83f0c4fe20614a299bccedd653:

  • Executable file extroot/project.json — part of check-in [afc0986fac] at 2021-10-20 05:57:23 on branch trunk — submitter+sitemap added (user: mario size: 3509)

#!/usr/bin/php-cgi -dcgi.force_redirect=0
<?php
# encoding: utf-8
# api: cgi
# type: output
# category: api
# title: project.json
# description: freshcode-style project.json w/ changelog
# version: 0.2
# state: beta
# depends: php:sqlite
# config: -
# access: public
#
# Generates a project.json containing general details
# as well as a `releases` changelog + download links.
#


#-- init
include("./fossil_common.php");


#-- changelog
function rc() {
    return db("
     SELECT event.mtime, tag.tagname, MAX(tag.tagid), DATE(event.mtime) AS d,
            event.comment AS comment
     FROM event
      LEFT JOIN tagxref ON event.objid=tagxref.rid
      LEFT JOIN tag ON tagxref.tagid=tag.tagid
     WHERE type='ci'
     GROUP BY objid
     ORDER BY event.mtime DESC
     LIMIT 1750
    ") + [99999=>["tagname"=>"end-0.0", "d"=>"0-0-0", "comment"=>"-"]];
}
# guess stability
function state($ver, $changes) {
    if (preg_match("/stable|beta|alpha/", $changes, $uu)) {
        return $uu[0];
    }
    elseif (preg_match("/\.0/", $ver)) {
        return "stable";
    }
    else {
        return "development";
    }
}
# judge fix/changeyness
function scope($ver, $changes) {
    $fix = preg_match_all("/fix|correct|merge/i", $changes, $uu);
    $add = preg_match_all("/add|change|intro/i", $changes, $uu);
    $s =  (($fix + $add) > 20) ? "major " : "minor ";
    $s .= ($fix > $add) ? "bugfix" : "changes";
    return $s;
}
# stack release notes by tag/version
function releases() {
    $ver = "trunk";
    $date = time();
    $changes = "";
    $releases = [];
    foreach(rc() as $r) {
        if (preg_match("/\d+\.\d+/", $r["tagname"]) and $r["tagname"] != $ver) {
#            if ($ver != "trunk")
            $releases[] = [
                "version" => preg_replace("/^.+?(?=\d+\.\d+)/", "", $ver),
                "state" => state($ver, $changes),
                "scope" => scope($ver, $changes),
                "changes" => substr($changes, 0, 1024),
                "download" => "$_SERVER[FOSSIL_SELF]zip?uuid=" . preg_replace("/^sym-/", "", $ver),
                "published" => $date,
            ];
            $changes = "";
            $ver = $r["tagname"];
            $date = $r["d"];
        }
        $changes .= $r["comment"] . "\n";
    }
    return $releases;
}

# unpack extra links
function sitemap_extra() {
    preg_match_all("~^\s*([\w.-]+)\s+(\w+://\S+)~m", get_config("sitemap-extra", ""), $uu);
    return array_combine($uu[1], $uu[2]);
}

# user with most events = main user
function main_user() {
    return db("SELECT user, COUNT(type) AS c FROM event LEFT JOIN user ON user.uid=event.uid GROUP BY user ORDER BY c DESC;")[0]["user"];
}

#-- output
header("Content-Type: application/json; x-mime=json/vnd.freshcode.club; charset=UTF-8");
print(json_encode([
    "\$feed-origin" => "$_SERVER[FOSSIL_SELF]",
    "\$feed-license" => "CC-BY-SA 4.0",
    "name" => preg_replace("/\.\w+$/", "", basename($_SERVER["FOSSIL_REPOSITORY"])),
    "title" => get_config("project-name", ""),
    "summary" => substr(get_config("project-description", NULL), 0, 50),
    "description" => get_config("project-description", ""),
    "homepage" => get_config("project-homepage", "$_SERVER[FOSSIL_SELF]"),
    "license" => get_config("project-license", ""),
    "tags" => get_config("project-tags", ""),
    "image" => "$_SERVER[FOSSIL_SELF]logo",
    "submitter" => main_user(),
    "urls" => sitemap_extra(),
    "releases" => releases(),
], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));