Show author info #40
@@ -16,7 +16,8 @@
|
||||
|
||||
import base64
|
||||
import html
|
||||
from typing import Dict, List
|
||||
import re
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
import requests
|
||||
|
||||
@@ -50,9 +51,36 @@ def _extract_trigger(build: Dict) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def _summarize_trigger(trigger: str) -> Tuple[str, str, str]:
|
||||
if not trigger:
|
||||
return "", "", ""
|
||||
|
||||
pr_url = ""
|
||||
for line in trigger.splitlines():
|
||||
if line.strip().lower().startswith("reviewed-on:"):
|
||||
pr_url = line.split(":", 1)[-1].strip()
|
||||
break
|
||||
|
||||
author_match = re.search(r"\(([^)]+)\)\.", trigger)
|
||||
author = author_match.group(1).strip() if author_match else ""
|
||||
|
||||
pr_match = re.search(r"#(\d+)", trigger)
|
||||
title_match = re.search(r"Merge pull request '([^']+)'", trigger)
|
||||
|
||||
if pr_match:
|
||||
pr_number = pr_match.group(1)
|
||||
title = title_match.group(1).strip() if title_match else ""
|
||||
if title:
|
||||
return f"Merge PR #{pr_number} · {title}", pr_url, author
|
||||
return f"Merge PR #{pr_number}", pr_url, author
|
||||
|
||||
return trigger.splitlines()[0].strip(), pr_url, author
|
||||
|
||||
|
||||
def normalize_build(build: Dict) -> Dict:
|
||||
commits = _extract_commits(build)
|
||||
trigger = _extract_trigger(build)
|
||||
trigger_label, trigger_url, trigger_author = _summarize_trigger(trigger)
|
||||
status = (build.get("result") or "RUNNING").lower()
|
||||
if build.get("building"):
|
||||
status = "running"
|
||||
@@ -65,6 +93,9 @@ def normalize_build(build: Dict) -> Dict:
|
||||
"url": build.get("url"),
|
||||
"commits": commits,
|
||||
"trigger": trigger,
|
||||
"trigger_label": trigger_label,
|
||||
"trigger_url": trigger_url,
|
||||
"trigger_author": trigger_author,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -112,6 +112,9 @@ def test_build_history(monkeypatch):
|
||||
{"commit": "9ac3f91", "message": "Anade la API de Jenkins", "author": "Dev One"}
|
||||
]
|
||||
assert first["trigger"] == "Triggered by Merge pull request #37"
|
||||
assert first["trigger_label"] == "Merge PR #37"
|
||||
assert first["trigger_url"] == ""
|
||||
assert first["trigger_author"] == ""
|
||||
|
||||
second = builds[1]
|
||||
assert second["number"] == 204
|
||||
@@ -119,6 +122,9 @@ def test_build_history(monkeypatch):
|
||||
assert second["duration_seconds"] == 1
|
||||
assert second["commits"] == []
|
||||
assert second["trigger"] == ""
|
||||
assert second["trigger_label"] == ""
|
||||
assert second["trigger_url"] == ""
|
||||
assert second["trigger_author"] == ""
|
||||
|
||||
|
||||
def test_build_history_error_returns_empty(monkeypatch):
|
||||
|
||||
@@ -377,14 +377,25 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
<span class={`status-dot ${build.status}`}></span>
|
||||
<span class="summary-title">#{build.number}</span>
|
||||
|
||||
{#if build.commits.length === 0}
|
||||
<span class="muted">
|
||||
{build.trigger || 'Ejecución manual'}
|
||||
</span>
|
||||
{:else}
|
||||
{#if build.trigger_label || build.trigger}
|
||||
<div class="summary-trigger">
|
||||
{#if build.trigger_url}
|
||||
<a href={build.trigger_url} target="_blank" rel="noreferrer">
|
||||
{build.trigger_label || build.trigger}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{build.trigger_label || build.trigger}</span>
|
||||
{/if}
|
||||
{#if build.trigger_author}
|
||||
<span class="trigger-author">{build.trigger_author}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if build.commits.length > 0}
|
||||
<span class="summary-commit">
|
||||
{build.commits[0].commit} · {build.commits[0].author}
|
||||
</span>
|
||||
{:else}
|
||||
<span class="muted">Ejecución manual</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -396,17 +407,39 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
</summary>
|
||||
|
||||
<div class="history-body">
|
||||
{#if build.commits.length > 0}
|
||||
{#if build.trigger_label || build.trigger}
|
||||
<p class="history-row">
|
||||
<span>Mensaje</span>
|
||||
<span>{build.commits[0].message}</span>
|
||||
<span>Disparo</span>
|
||||
<span>
|
||||
{#if build.trigger_url}
|
||||
<a
|
||||
class="history-link"
|
||||
href={build.trigger_url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
{build.trigger_label || build.trigger}
|
||||
</a>
|
||||
{:else}
|
||||
{build.trigger_label || build.trigger}
|
||||
{/if}
|
||||
{#if build.trigger_author}
|
||||
<span class="trigger-author">{build.trigger_author}</span>
|
||||
{/if}
|
||||
</span>
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if build.trigger}
|
||||
{#if build.commits.length > 0}
|
||||
<p class="history-row">
|
||||
<span>Disparo</span>
|
||||
<span>{build.trigger}</span>
|
||||
<span>Commit</span>
|
||||
<span class="mono">
|
||||
{build.commits[0].commit} · {build.commits[0].author}
|
||||
</span>
|
||||
</p>
|
||||
<p class="history-row">
|
||||
<span>Mensaje</span>
|
||||
<span>{build.commits[0].message}</span>
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -697,6 +697,25 @@ li {
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.summary-trigger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
flex-wrap: wrap;
|
||||
color: #fbbf24;
|
||||
font-weight: 700;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.summary-trigger a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.summary-trigger a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.summary-meta {
|
||||
display: flex;
|
||||
gap: 0.6rem;
|
||||
@@ -748,6 +767,21 @@ li {
|
||||
color: #cbd5f5;
|
||||
}
|
||||
|
||||
.history-link {
|
||||
color: #fbbf24;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.history-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: #94a3b8;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.history-message {
|
||||
margin: 0.2rem 0 0;
|
||||
background: rgba(248, 113, 113, 0.12);
|
||||
@@ -835,3 +869,15 @@ li {
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.85;
|
||||
}
|
||||
.trigger-author {
|
||||
padding: 0.1rem 0.4rem;
|
||||
border-radius: 999px;
|
||||
background: rgba(148, 163, 184, 0.16);
|
||||
color: #cbd5f5;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.history-row .trigger-author {
|
||||
margin-left: 0.35rem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user