add custom page scripts (#77307)
This commit is contained in:
parent
1237b3be26
commit
d98ba1e978
|
@ -0,0 +1,186 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import configparser
|
||||
import datetime
|
||||
import glob
|
||||
import html
|
||||
import os
|
||||
import subprocess
|
||||
import requests
|
||||
|
||||
recent = datetime.datetime.now() - datetime.timedelta(days=28)
|
||||
three_days_ago = datetime.datetime.now() - datetime.timedelta(days=3)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read('/etc/gitea/eo-custom.ini')
|
||||
access_token = config.get('settings', 'access_token')
|
||||
|
||||
archived = set()
|
||||
|
||||
try:
|
||||
for i in range(50):
|
||||
repositories = requests.get(
|
||||
'https://git.entrouvert.org/api/v1/orgs/entrouvert/repos?limit=50&page=%s&token=%s'
|
||||
% (i + 1, access_token),
|
||||
headers={'accept': 'application/json'},
|
||||
).json()
|
||||
if not repositories:
|
||||
break
|
||||
archived |= set(x['name'] for x in repositories if x.get('archived'))
|
||||
except requests.exceptions.RequestException:
|
||||
pass
|
||||
|
||||
print(
|
||||
'''<!DOCTYPE html>
|
||||
<html lang="fr-FR" class="theme-auto">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Commits pas encore taggués - Gitea: Git with a cup of tea</title>
|
||||
|
||||
<meta name="default-theme" content="auto">
|
||||
|
||||
<link rel="icon" href="/assets/img/favicon.svg" type="image/svg+xml">
|
||||
<link rel="alternate icon" href="/assets/img/favicon.png" type="image/png">
|
||||
<link rel="stylesheet" href="/assets/css/index.css">
|
||||
<link rel="stylesheet" href="/assets/css/theme-auto.css?v=1.19.3">
|
||||
<link rel="stylesheet" href="/assets/custom.css">
|
||||
|
||||
<style>
|
||||
body { font-family: sans-serif; }
|
||||
h1 { font-weight: 300; font-size: 2.3rem;}
|
||||
h2 { font-weight: 300; font-size: 1.6rem;}
|
||||
a.anchor-link { font-size: 1rem; visibility: hidden;}
|
||||
h2:hover a.anchor-link { visibility: visible; }
|
||||
|
||||
table { border-collapse: collapse; }
|
||||
td.repos { width: 20em; padding-top: 0.5em;}
|
||||
.lag { color: red; }
|
||||
.log { display: none; }
|
||||
pre { margin: 0; font-size: 90%; color: #444; background: #fafafa; }
|
||||
|
||||
</style><body>
|
||||
<div class="full height">
|
||||
<div class="ui top secondary stackable main menu following bar light no-vertical-tabs">
|
||||
<nav class="ui container" id="navbar" aria-label="Navigation Bar">
|
||||
|
||||
<div class="item brand gt-sb">
|
||||
<a href="/" aria-label="Tableau de bord">
|
||||
<img src="/assets/img/logo.svg" alt="Logo" aria-hidden="true" width="30" height="30">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<a class="item " href="/issues">Tickets</a>
|
||||
<a class="item " href="/pulls">Demandes d'ajout</a>
|
||||
<a class="item " href="/milestones">Jalons</a>
|
||||
<a class="item " href="/explore/repos">Explorateur</a>
|
||||
<a class="item active" href="/reviews.html">Rapports</a>
|
||||
<a class="item" href="https://dev.entrouvert.org">Redmine</a>
|
||||
<a class="item" href="https://jenkins.entrouvert.org">Jenkins</a>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="page-content explore">
|
||||
|
||||
<div class="ui secondary pointing tabular top attached borderless stackable menu new-menu navbar">
|
||||
<a class="item" href="/reviews.html">Relectures demandées</a>
|
||||
<a class="active item" href="/lag.html">Commits pas encore taggués</a>
|
||||
</div>
|
||||
|
||||
<div class="ui container">
|
||||
<h1>Commits pas encore taggués</h1>
|
||||
'''
|
||||
)
|
||||
|
||||
|
||||
print(
|
||||
'''
|
||||
<p><label><input id="display-commits" type="checkbox"> Afficher les commits</label></p>
|
||||
<table>'''
|
||||
)
|
||||
|
||||
for repos in sorted(glob.glob('/var/lib/gitea/data/gitea-repositories/entrouvert/*.git')):
|
||||
repos_name = os.path.basename(repos).removesuffix('.git')
|
||||
if repos_name in archived:
|
||||
continue
|
||||
if repos_name.startswith('misc-'): # personal repositories
|
||||
continue
|
||||
if repos_name in ( # ignore list:
|
||||
# déployés depuis le dépôt eobuilder
|
||||
'barbacompta',
|
||||
'debian-django-ckeditor',
|
||||
'scrutiny',
|
||||
'gitea-deb',
|
||||
# test
|
||||
'bidon',
|
||||
# installé depuis les sources
|
||||
'publik-devinst',
|
||||
# iMio
|
||||
'imio-publik-themes',
|
||||
'passerelle-imio-ts1-datasources',
|
||||
'passerelle-imio-extra-fees',
|
||||
'passerelle-imio-ia-delib',
|
||||
'passerelle-imio-liege-lisrue',
|
||||
'passerelle-imio-liege-rn',
|
||||
'passerelle-imio-tax-compute',
|
||||
'imio-teleservices-templatetags',
|
||||
'authentic2-wallonie-connect',
|
||||
):
|
||||
continue
|
||||
os.chdir(repos)
|
||||
try:
|
||||
latest = datetime.datetime.strptime(
|
||||
subprocess.check_output(
|
||||
['git', 'log', '-1', '--pretty=format:%ci'], stderr=subprocess.PIPE
|
||||
).decode('ascii')[:18],
|
||||
'%Y-%m-%d %H:%M:%S',
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
continue
|
||||
if latest < recent:
|
||||
continue
|
||||
try:
|
||||
described = (
|
||||
subprocess.check_output(['git', 'describe'], stderr=subprocess.PIPE).decode('ascii').strip()
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
continue
|
||||
classname = ''
|
||||
if not '-g' in described:
|
||||
continue
|
||||
if latest < three_days_ago:
|
||||
classname = 'lag'
|
||||
module_name = repos.split('/')[-1].removesuffix('.git')
|
||||
print(
|
||||
'<tr class="repos %s"><td class="repos"><a href="https://git.entrouvert.org/entrouvert/%s/graph?branch=refs/heads/main">%s</td> <td class="described"><tt>%s</tt></td><td></td></tr>'
|
||||
% (classname, module_name, module_name, described)
|
||||
)
|
||||
count = int(described.split('-')[1])
|
||||
try:
|
||||
log = (
|
||||
subprocess.check_output(['git', 'log', '--oneline', 'HEAD~%s..' % count], stderr=subprocess.PIPE)
|
||||
.decode()
|
||||
.strip()
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
else:
|
||||
print('<tr class="log"><td colspan="3"><pre>%s</pre></td></tr>' % html.escape(log))
|
||||
|
||||
print(
|
||||
'''</table></div></div></body>
|
||||
<script>
|
||||
const checkbox = document.getElementById('display-commits');
|
||||
checkbox.addEventListener('change', function(e) {
|
||||
document.querySelectorAll('tr.log').forEach(function(tr) {
|
||||
if (checkbox.checked) {
|
||||
tr.style.display = 'table-row';
|
||||
} else {
|
||||
tr.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
const event = new Event('change');
|
||||
checkbox.dispatchEvent(event);
|
||||
</script>
|
||||
</html>'''
|
||||
)
|
|
@ -0,0 +1,101 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import collections
|
||||
import configparser
|
||||
import datetime
|
||||
import psycopg2
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read('/etc/gitea/eo-custom.ini')
|
||||
db_connect_string = config.get('settings', 'db')
|
||||
|
||||
conn = psycopg2.connect(db_connect_string)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"""select "user".full_name, "user".name, repository.name, issue.index, review.created_unix
|
||||
from review, "user", issue, repository, pull_request
|
||||
where "user".id = reviewer_id
|
||||
and review.type = 4
|
||||
and review.issue_id = issue.id
|
||||
and issue.repo_id = repository.id
|
||||
and review.official = true
|
||||
and issue.index = pull_request.index
|
||||
and pull_request.issue_id = issue.id
|
||||
and pull_request.has_merged = false
|
||||
order by "user".full_name, repository.name, review.created_unix
|
||||
"""
|
||||
)
|
||||
|
||||
print(
|
||||
'''<!DOCTYPE html>
|
||||
<html lang="fr-FR" class="theme-auto">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Relectures en attente - Gitea: Git with a cup of tea</title>
|
||||
|
||||
<meta name="default-theme" content="auto">
|
||||
|
||||
<link rel="icon" href="/assets/img/favicon.svg" type="image/svg+xml">
|
||||
<link rel="alternate icon" href="/assets/img/favicon.png" type="image/png">
|
||||
<link rel="stylesheet" href="/assets/css/index.css">
|
||||
<link rel="stylesheet" href="/assets/css/theme-auto.css?v=1.19.3">
|
||||
<link rel="stylesheet" href="/assets/custom.css">
|
||||
|
||||
<style>
|
||||
body { font-family: sans-serif; }
|
||||
h1 { font-weight: 300; font-size: 2.3rem;}
|
||||
h2 { font-weight: 300; font-size: 1.6rem;}
|
||||
a.anchor-link { font-size: 1rem; visibility: hidden;}
|
||||
h2:hover a.anchor-link { visibility: visible; }
|
||||
</style><body>
|
||||
<div class="full height">
|
||||
<div class="ui top secondary stackable main menu following bar light no-vertical-tabs">
|
||||
<nav class="ui container" id="navbar" aria-label="Navigation Bar">
|
||||
|
||||
<div class="item brand gt-sb">
|
||||
<a href="/" aria-label="Tableau de bord">
|
||||
<img src="/assets/img/logo.svg" alt="Logo" aria-hidden="true" width="30" height="30">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<a class="item " href="/issues">Tickets</a>
|
||||
<a class="item " href="/pulls">Demandes d'ajout</a>
|
||||
<a class="item " href="/milestones">Jalons</a>
|
||||
<a class="item " href="/explore/repos">Explorateur</a>
|
||||
<a class="item active" href="/reviews.html">Rapports</a>
|
||||
<a class="item" href="https://dev.entrouvert.org">Redmine</a>
|
||||
<a class="item" href="https://jenkins.entrouvert.org">Jenkins</a>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="page-content explore">
|
||||
|
||||
<div class="ui secondary pointing tabular top attached borderless stackable menu new-menu navbar">
|
||||
<a class="active item" href="/reviews.html">Relectures demandées</a>
|
||||
<a class="item" href="/lag.html">Commits pas encore taggués</a>
|
||||
</div>
|
||||
|
||||
<div class="ui container">
|
||||
<h1>Relectures demandées</h1>
|
||||
'''
|
||||
)
|
||||
|
||||
authors = collections.defaultdict(list)
|
||||
|
||||
for fullname, username, repository, pr, created_unix in cursor.fetchall():
|
||||
authors[username].append((fullname, username, repository, pr, created_unix))
|
||||
|
||||
for author_key, reviews in sorted(authors.items()):
|
||||
fullname, username, repository, pr, created_unix = reviews[0]
|
||||
print(f'''<h2 id="{username}">{fullname} <a class="anchor-link" href="#{username}">¶</a></h2>''')
|
||||
print('<ul>')
|
||||
for review in reviews:
|
||||
fullname, username, repository, pr, created_unix = review
|
||||
print(
|
||||
f'''<li><a href="/entrouvert/{repository}/pulls/{pr}">{repository} #{pr}</a>
|
||||
<span class="datetime">({datetime.datetime.fromtimestamp(created_unix)})</span></li>
|
||||
'''
|
||||
)
|
||||
print('</ul>')
|
||||
|
||||
print('''</div></div></div></html>''')
|
Loading…
Reference in New Issue