summaryrefslogtreecommitdiff
path: root/includes/refresh-projects.php
blob: 5e4ba69cb95a446f1b394b678cd9405abe8f9f38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

if (!isset($_SERVER['argv'])) die("This script can only be run in a CLI environment.");

// Projects

$secrets = json_decode(file_get_contents("./secrets.json"), true);
$equivalents = [];
$descriptions = [];
$projects = [];

print("GitHub > equestria.dev\n");

$gitea = [];
$page = 1;
$current = json_decode(file_get_contents("https://api.github.com/orgs/equestria-dev/repos?page=$page&per_page=100", false, stream_context_create(["ssl"=>["verify_peer"=>false,"verify_peer_name"=>false],"http"=>["header"=>"User-Agent: Mozilla/5.0 (Equestria.dev; +Starshine; hello@equestria.dev)\r\n"]])), true);
array_push($gitea, ...$current);

while (count($current) > 0) {
    $page++;
    $current = json_decode(file_get_contents("https://api.github.com/orgs/equestria-dev/repos?page=$page&per_page=100", false, stream_context_create(["ssl"=>["verify_peer"=>false,"verify_peer_name"=>false],"http"=>["header"=>"User-Agent: Mozilla/5.0 (Equestria.dev; +Starshine; hello@equestria.dev)\r\n"]])), true);
    array_push($gitea, ...$current);
}

foreach ($gitea as $project) {
    if ($project["visibility"] !== "public") continue;

    print("    " . $project["name"] . "\n");
    $languages = json_decode(file_get_contents("https://api.github.com/repos/equestria-dev/$project[name]/languages", false, stream_context_create(["ssl"=>["verify_peer"=>false,"verify_peer_name"=>false],"http"=>["header"=>"User-Agent: Mozilla/5.0 (Equestria.dev; +Starshine; hello@equestria.dev)\r\n"]])), true);

    if (count($languages) > 0) {
        $languages2 = [];
        $languages_total = array_sum(array_values($languages));

        foreach ($languages as $key => $value) {
            $languages2[$key] = ($value / $languages_total) * 100;
        }
    }

    $projects[] = [
        "id" => md5($project["full_name"]),
        "owner" => $project["owner"]["login"],
        "name" => $project["name"],
        "display_name" => $project["name"],
        "description" => $project["description"],
        "source" => $project["html_url"],
        "icon" => null,
        "website" => $project["html_url"],
        "size" => $project["size"] * 1024,
        "language" => array_keys($languages2)[0] ?? null,
        "languages" => $languages2,
        "update" => strtotime($project["updated_at"]),
        "commit" => strtotime($project["pushed_at"]),
        "archive" => false,
        "readme" => null
    ];
}

file_put_contents("./data/projects.json", json_encode($projects, JSON_PRETTY_PRINT));

// Icons
echo("Icons!\n");
foreach ($projects as $project) {
    echo($project["name"] . "\n");
    file_put_contents("../assets/projects/" . $project["id"] . ".png", file_get_contents("../assets/img/favicon.svg"));
}