mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
Add badge in job page
Also features the copy of the Markdown code for the badge into the clipboard
This commit is contained in:
parent
444de3ae11
commit
21dc122bb6
2 changed files with 26 additions and 3 deletions
13
run.py
13
run.py
|
@ -919,12 +919,19 @@ async def html_job(request, job_id):
|
||||||
|
|
||||||
job = job[0]
|
job = job[0]
|
||||||
|
|
||||||
app = Repo.select().where(Repo.url == job.url_or_path)
|
application = Repo.select().where(Repo.url == job.url_or_path)
|
||||||
app = app[0] if app else None
|
application = application[0] if application else None
|
||||||
|
|
||||||
|
job_url = app.config.BASE_URL + app.url_for("html_job", job_id=job.id)
|
||||||
|
badge_url = app.config.BASE_URL + app.url_for("api_badge_job", job_id=job.id)
|
||||||
|
shield_badge_url = f"https://img.shields.io/endpoint?url={badge_url}"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"job": job,
|
"job": job,
|
||||||
'app': app,
|
'app': application,
|
||||||
|
'job_url': job_url,
|
||||||
|
'badge_url': badge_url,
|
||||||
|
'shield_badge_url': shield_badge_url,
|
||||||
'relative_path_to_root': '../',
|
'relative_path_to_root': '../',
|
||||||
'path': request.path
|
'path': request.path
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
<tr><th>Created time</th><td>{{timestampToDate(job.created_time)}}</td></tr>
|
<tr><th>Created time</th><td>{{timestampToDate(job.created_time)}}</td></tr>
|
||||||
<tr><th>Started time</th><td>{{timestampToDate(job.started_time)}}</td></tr>
|
<tr><th>Started time</th><td>{{timestampToDate(job.started_time)}}</td></tr>
|
||||||
<tr><th>End time</th><td>{{timestampToDate(job.end_time)}}</td></tr>
|
<tr><th>End time</th><td>{{timestampToDate(job.end_time)}}</td></tr>
|
||||||
|
<tr><th>Badge</th><td><img src="<{ shield_badge_url }>" alt="<{job.state}>" title="Click to copy its Markdown code" id="badge"/></td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2 class="subtitle">Execution log:</h2>
|
<h2 class="subtitle">Execution log:</h2>
|
||||||
|
@ -95,4 +96,19 @@
|
||||||
};
|
};
|
||||||
})()
|
})()
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
// Thanks to https://tech-wiki.online/fr/clipboard-api.html
|
||||||
|
document.querySelector('#badge').addEventListener('click', async event => {
|
||||||
|
if (!navigator.clipboard) {
|
||||||
|
// Clipboard API not available
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const text = "[](https://ci.pijean.ovh/ci/job/<{ job.id }>)"
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(text)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to copy Markdown code for the job badge', err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
<% endblock %>
|
<% endblock %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue