Add an endpoint for downloading the logs of a build.
This commit is contained in:
parent
2464124f62
commit
9888c3ad9b
3 changed files with 53 additions and 2 deletions
|
@ -9,10 +9,11 @@ from health.healthcheck import get_healthchecker
|
|||
|
||||
from data import model
|
||||
from data.model.oauth import DatabaseAuthorizationProvider
|
||||
from app import app, billing as stripe, build_logs, avatar, signer
|
||||
from app import app, billing as stripe, build_logs, avatar, signer, log_archive
|
||||
from auth.auth import require_session_login, process_oauth
|
||||
from auth.permissions import (AdministerOrganizationPermission, ReadRepositoryPermission,
|
||||
SuperUserPermission, AdministerRepositoryPermission)
|
||||
SuperUserPermission, AdministerRepositoryPermission,
|
||||
ModifyRepositoryPermission)
|
||||
|
||||
from util.invoice import renderInvoiceToPdf
|
||||
from util.seo import render_snapshot
|
||||
|
@ -248,6 +249,32 @@ def robots():
|
|||
return send_from_directory('static', 'robots.txt')
|
||||
|
||||
|
||||
@web.route('/buildlogs/<build_uuid>', methods=['GET'])
|
||||
@route_show_if(features.BUILD_SUPPORT)
|
||||
@require_session_login
|
||||
def buildlogs(build_uuid):
|
||||
build = model.get_repository_build(build_uuid)
|
||||
if not build:
|
||||
abort(403)
|
||||
|
||||
repo = build.repository
|
||||
if not ModifyRepositoryPermission(repo.namespace_user.username, repo.name).can():
|
||||
abort(403)
|
||||
|
||||
# If the logs have been archived, just return a URL of the completed archive
|
||||
if build.logs_archived:
|
||||
return redirect(log_archive.get_file_url(build.uuid))
|
||||
|
||||
_, logs = build_logs.get_log_entries(build.uuid, 0)
|
||||
response = jsonify({
|
||||
'logs': [log for log in logs]
|
||||
})
|
||||
|
||||
response.mimetype = "application/json"
|
||||
response.headers["Content-Disposition"] = "attachment;filename=" + build.uuid + ".json"
|
||||
return response
|
||||
|
||||
|
||||
@web.route('/receipt', methods=['GET'])
|
||||
@route_show_if(features.BILLING)
|
||||
@require_session_login
|
||||
|
|
|
@ -157,6 +157,24 @@
|
|||
transition: all 0.15s ease-in-out;
|
||||
}
|
||||
|
||||
.build-logs-view .download-button i.fa {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.build-logs-view .download-button {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 124px;
|
||||
z-index: 2;
|
||||
transition: all 0.15s ease-in-out;
|
||||
}
|
||||
|
||||
.build-logs-view .download-button:not(:hover) {
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
.build-logs-view .copy-button:not(.zeroclipboard-is-hover) {
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
<i class="fa fa-clipboard"></i>Copy Logs
|
||||
</button>
|
||||
|
||||
<a id="downloadButton" class="btn btn-primary download-button"
|
||||
ng-href="/buildlogs/{{ currentBuild.id }}"
|
||||
target="_blank">
|
||||
<i class="fa fa-download"></i>Download Logs
|
||||
</a>
|
||||
|
||||
<span class="cor-loader" ng-if="!logEntries"></span>
|
||||
|
||||
<span class="no-logs" ng-if="!logEntries.length && currentBuild.phase == 'waiting'">
|
||||
|
|
Reference in a new issue