Skip to content

Commit 44d2068

Browse files
committed
Support downloading raw task logs
1 parent 520eb57 commit 44d2068

File tree

7 files changed

+47
-2
lines changed

7 files changed

+47
-2
lines changed

modules/actions/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func WriteLogs(ctx context.Context, filename string, offset int64, rows []*runne
5757
}
5858

5959
func ReadLogs(ctx context.Context, inStorage bool, filename string, offset, limit int64) ([]*runnerv1.LogRow, error) {
60-
f, err := openLogs(ctx, inStorage, filename)
60+
f, err := OpenLogs(ctx, inStorage, filename)
6161
if err != nil {
6262
return nil, err
6363
}
@@ -125,7 +125,7 @@ func RemoveLogs(ctx context.Context, inStorage bool, filename string) error {
125125
return nil
126126
}
127127

128-
func openLogs(ctx context.Context, inStorage bool, filename string) (io.ReadSeekCloser, error) {
128+
func OpenLogs(ctx context.Context, inStorage bool, filename string) (io.ReadSeekCloser, error) {
129129
if !inStorage {
130130
name := DBFSPrefix + filename
131131
f, err := dbfs.Open(ctx, name)

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ concept_user_organization = Organization
128128
show_timestamps = Show timestamps
129129
show_log_seconds = Show seconds
130130
show_full_screen = Show full screen
131+
download_logs = Download logs
131132

132133
[aria]
133134
navbar = Navigation Bar

routers/web/repo/actions/view.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,41 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob) erro
310310
return nil
311311
}
312312

313+
func Logs(ctx *context_module.Context) {
314+
runIndex := ctx.ParamsInt64("run")
315+
jobIndex := ctx.ParamsInt64("job")
316+
317+
job, _ := getRunJobs(ctx, runIndex, jobIndex)
318+
if ctx.Written() {
319+
return
320+
}
321+
if job.TaskID == 0 {
322+
ctx.Error(http.StatusNotFound, "job is not started")
323+
return
324+
}
325+
326+
task, err := actions_model.GetTaskByID(ctx, job.TaskID)
327+
if err != nil {
328+
ctx.Error(http.StatusInternalServerError, err.Error())
329+
return
330+
}
331+
332+
reader, err := actions.OpenLogs(ctx, task.LogInStorage, task.LogFilename)
333+
if err != nil {
334+
ctx.Error(http.StatusInternalServerError, err.Error())
335+
return
336+
}
337+
defer reader.Close()
338+
339+
ctx.ServeContent(reader, &context_module.ServeHeaderOptions{
340+
Filename: job.Name + ".txt",
341+
ContentLength: &task.LogSize,
342+
ContentType: "text/plain",
343+
ContentTypeCharset: "utf-8",
344+
Disposition: "attachment",
345+
})
346+
}
347+
313348
func Cancel(ctx *context_module.Context) {
314349
runIndex := ctx.ParamsInt64("run")
315350

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ func registerRoutes(m *web.Route) {
11941194
Get(actions.View).
11951195
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
11961196
m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne)
1197+
m.Get("/logs", actions.Logs)
11971198
})
11981199
m.Post("/cancel", reqRepoActionsWriter, actions.Cancel)
11991200
m.Post("/approve", reqRepoActionsWriter, actions.Approve)

templates/repo/actions/view.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
data-locale-show-timestamps="{{.locale.Tr "show_timestamps"}}"
2323
data-locale-show-log-seconds="{{.locale.Tr "show_log_seconds"}}"
2424
data-locale-show-full-screen="{{.locale.Tr "show_full_screen"}}"
25+
data-locale-download-logs="{{.locale.Tr "download_logs"}}"
2526
>
2627
</div>
2728
</div>

web_src/js/components/RepoActionView.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
<SvgIcon name="octicon-gear" :size="18"/>
7575
</button>
7676
<div class="menu transition action-job-menu" :class="{visible: menuVisible}" v-if="menuVisible" v-cloak>
77+
<a class="item" :href="run.link+'/jobs/'+jobIndex+'/logs'" target="_blank">
78+
<i class="icon"><SvgIcon name="octicon-download"/></i>
79+
{{ locale.downloadLogs }}
80+
</a>
7781
<a class="item" @click="toggleTimeDisplay('seconds')">
7882
<i class="icon"><SvgIcon v-show="timeVisible['log-time-seconds']" name="octicon-check"/></i>
7983
{{ locale.showLogSeconds }}
@@ -455,6 +459,7 @@ export function initRepositoryActionView() {
455459
showTimeStamps: el.getAttribute('data-locale-show-timestamps'),
456460
showLogSeconds: el.getAttribute('data-locale-show-log-seconds'),
457461
showFullScreen: el.getAttribute('data-locale-show-full-screen'),
462+
downloadLogs: el.getAttribute('data-locale-download-logs'),
458463
status: {
459464
unknown: el.getAttribute('data-locale-status-unknown'),
460465
waiting: el.getAttribute('data-locale-status-waiting'),

web_src/js/svg.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import octiconDiffModified from '../../public/img/svg/octicon-diff-modified.svg'
2222
import octiconDiffRemoved from '../../public/img/svg/octicon-diff-removed.svg';
2323
import octiconDiffRenamed from '../../public/img/svg/octicon-diff-renamed.svg';
2424
import octiconDotFill from '../../public/img/svg/octicon-dot-fill.svg';
25+
import octiconDownload from '../../public/img/svg/octicon-download.svg';
2526
import octiconEye from '../../public/img/svg/octicon-eye.svg';
2627
import octiconFile from '../../public/img/svg/octicon-file.svg';
2728
import octiconFileDirectoryFill from '../../public/img/svg/octicon-file-directory-fill.svg';
@@ -91,6 +92,7 @@ const svgs = {
9192
'octicon-diff-removed': octiconDiffRemoved,
9293
'octicon-diff-renamed': octiconDiffRenamed,
9394
'octicon-dot-fill': octiconDotFill,
95+
'octicon-download': octiconDownload,
9496
'octicon-eye': octiconEye,
9597
'octicon-file': octiconFile,
9698
'octicon-file-directory-fill': octiconFileDirectoryFill,

0 commit comments

Comments
 (0)