Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit c186179

Browse files
committed
add contributor view
1 parent 21d5e07 commit c186179

9 files changed

Lines changed: 144 additions & 6 deletions

File tree

api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ func AnalysisContributor(username string, repo string) AnalysisData {
194194
if err != nil {
195195
return AnalysisData{nil, err.Error(), iris.StatusNotFound}
196196
}
197+
info, err := GetRepo(username, repo)
198+
if err != nil {
199+
return AnalysisData{nil, err.Error(), iris.StatusNotFound}
200+
}
197201
var contributors []map[string]any
198202
for _, v := range res {
199203
v := v.(map[string]interface{})
@@ -207,6 +211,7 @@ func AnalysisContributor(username string, repo string) AnalysisData {
207211
iris.Map{
208212
"username": username,
209213
"repo": repo,
214+
"color": GetColor(info["language"]),
210215
"contributors": contributors,
211216
}, "", iris.StatusOK,
212217
}

app/contributor.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
include 'utils.php';
3+
4+
$dark = isset($_GET['theme']) && $_GET['theme'] === 'dark';
5+
$header = $dark ? "#fff" : "#434d58";
6+
$background = $dark ? "#000" : "#fffefe";
7+
$username = get('username', '');
8+
$repo = get('repo', '');
9+
$column = max((int)get('column', '6'), 4);
10+
11+
$stats = fetch("contributor/$username/$repo");
12+
if (!$stats) {
13+
include 'error.php';
14+
exit;
15+
}
16+
$name = "$username / $repo";
17+
$number = count($stats['contributors']);
18+
$height = 100 + (ceil($number / $column) * 64);
19+
20+
ob_start('compress');
21+
?>
22+
<svg width="540" viewBox="0 0 <?php echo 100 + ($column * 64) ?> <?php echo $height + 1 ?>" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="descId">
23+
<title id="titleId"><?php echo $name ?>'s Contributors</title>
24+
<desc id="descId">Repository Contributors</desc>
25+
<defs><mask id="circle-mask"><circle cx="25" cy="25" r="25" fill="white" /></mask></defs>
26+
<style>
27+
.circle {
28+
animation: fadeInAnimation 0.8s ease-in-out forwards;
29+
}
30+
.avatar {
31+
animation: fadeInAnimation 0.8s ease-in-out forwards;
32+
border-radius: 50%;
33+
}
34+
.header {
35+
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
36+
fill: #2f80ed;
37+
animation: fadeInAnimation 0.8s ease-in-out forwards;
38+
}
39+
@supports (appearance: auto) {
40+
.header {
41+
font-size: 16px;
42+
}
43+
}
44+
@keyframes growWidthAnimation {
45+
from {
46+
width: 0;
47+
}
48+
to {
49+
width: 100%;
50+
}
51+
}
52+
#rect-mask rect {
53+
animation: fadeInAnimation 1s ease-in-out forwards;
54+
}
55+
@keyframes fadeInAnimation {
56+
from {
57+
opacity: 0;
58+
}
59+
to {
60+
opacity: 1;
61+
}
62+
}
63+
</style>
64+
<rect data-testid="card-bg" x="0.5" y="0.5" rx="4.5" height="99%" stroke="#e4e2e2" width="99%" fill="<?php echo $background ?>" stroke-opacity="1"/>
65+
<g data-testid="card-title" transform="translate(40, 35)">
66+
<g transform="translate(0, 0)">
67+
<circle class="circle" cx="-10" cy="-5" r="5" fill="<?php echo $stats['color'] ?>" />
68+
<text x="0" y="0" class="header" data-testid="header"><?php echo $name ?></text>
69+
</g>
70+
</g>
71+
<g xmlns="http://www.w3.org/2000/svg" transform="translate(18, 65)" data-testid="main-card-progress">
72+
<svg data-testid="contributors" x="25">
73+
<mask id="rect-mask"><rect x="0" y="0" width="300" height="8" fill="white" rx="5"/></mask>
74+
<?php foreach ($stats['contributors'] as $idx => $contributor) { ?>
75+
<g class="avatar" transform="translate(<?php echo ($idx % $column) * 64 ?>, <?php echo (int)($idx / $column) * 64 ?>)">
76+
<image height="50" width="50" href="<?php echo $contributor['avatar'] ?>" mask="url(#circle-mask)" />
77+
</g>
78+
<?php } ?>
79+
</svg>
80+
</g>
81+
</svg>
82+
83+
<?php
84+
ob_end_flush();
85+
?>

app/repo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
include 'utils.php';
33

44
$dark = isset($_GET['theme']) && $_GET['theme'] === 'dark';
5-
$username = get('username', 'zmh-program');
6-
$repo = get('repo', 'code-statistic');
5+
$username = get('username', '');
6+
$repo = get('repo', '');
77

88
$stats = fetch("repo/$username/$repo");
99
if (!$stats) {
1010
include 'error.php';
1111
exit;
1212
}
1313
$langs = $stats['languages'];
14-
$name = "$username/$repo";
14+
$name = "$username / $repo";
1515

1616
list($langs, $bar, $height, $header, $background) = extracted($stats['languages'], $dark);
1717
?>

app/user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
include 'utils.php';
33

44
$dark = isset($_GET['theme']) && $_GET['theme'] === 'dark';
5-
$username = get('username', 'zmh-program');
5+
$username = get('username', '');
66

77
$stats = fetch("user/$username");
88
if (!$stats) {

config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
token: ""
12
debug: true
23
server:
34
port: 8080

docs/nginx.conf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
server
2+
{
3+
listen 80;
4+
listen 443 ssl http2;
5+
server_name stats.deeptrain.net;
6+
index gui/index.html;
7+
root /www/wwwroot/stats/app;
8+
9+
add_header Strict-Transport-Security "max-age=31536000";
10+
error_page 497 https://$host$request_uri;
11+
12+
include enable-php-81.conf;
13+
include /www/server/panel/vhost/rewrite/stats.deeptrain.net.conf;
14+
15+
location = /favicon.ico {
16+
root /www/wwwroot/stats/app/gui/;
17+
}
18+
19+
location /assets {
20+
expires 12h;
21+
alias /www/wwwroot/stats/app/gui/assets;
22+
try_files $uri $uri/ =404;
23+
}
24+
25+
location /user/ {
26+
rewrite ^/user/(.*?)/?$ /user.php?username=$1 last;
27+
}
28+
29+
location /repo/ {
30+
rewrite ^/repo/(.*?)/(.*?)/?$ /repo.php?username=$1&repo=$2 last;
31+
}
32+
33+
location /api {
34+
proxy_pass http://localhost:8080; # backend
35+
proxy_set_header Host $host;
36+
proxy_set_header X-Real-IP $remote_addr;
37+
}
38+
access_log /www/wwwlogs/stats.deeptrain.net.log;
39+
error_log /www/wwwlogs/stats.deeptrain.net.error.log;
40+
}

gui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "vue-tsc --noEmit && vite build",
9-
"release": "vue-tsc --noEmit && vite build --emptyOutDir --outDir ../deploy/gui",
9+
"release": "vue-tsc --noEmit && vite build --emptyOutDir --outDir ../deploy/app/gui",
1010
"preview": "vite preview",
1111
"prepare": "node -e \"if(require('fs').existsSync('.git')){process.exit(1)}\" || is-ci || husky install"
1212
},

gui/public/favicon.ico

32.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)