Skip to content

Commit 95fb0b3

Browse files
author
Wilfried OLLIVIER
committed
Merge logs file with application/task file
1 parent 791756b commit 95fb0b3

File tree

2 files changed

+37
-45
lines changed

2 files changed

+37
-45
lines changed

application/logs.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

application/task.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package application
22

33
import (
4+
"bytes"
5+
"context"
46
"encoding/json"
7+
"fmt"
8+
"html/template"
59
"net/http"
610
"net/url"
711
"os"
812
"time"
913

1014
"github.com/docker/docker/pkg/stdcopy"
1115
_claims "github.com/factorysh/microdensity/claims"
16+
"github.com/factorysh/microdensity/html"
1217
"github.com/factorysh/microdensity/task"
1318
"github.com/go-chi/chi/v5"
1419
"github.com/go-chi/render"
1520
"github.com/google/uuid"
21+
"github.com/robert-nix/ansihtml"
1622
"go.uber.org/zap"
1723
)
1824

@@ -267,3 +273,34 @@ func (a *Application) TaskLogsHandler(latest bool) func(http.ResponseWriter, *ht
267273
}
268274
}
269275
}
276+
277+
func (a *Application) renderLogsPageForTask(ctx context.Context, t *task.Task, w http.ResponseWriter) error {
278+
279+
reader, err := t.Logs(ctx, false)
280+
if err != nil {
281+
return err
282+
}
283+
284+
var buffer bytes.Buffer
285+
_, err = stdcopy.StdCopy(&buffer, &buffer, reader)
286+
if err != nil {
287+
return err
288+
}
289+
290+
data, err := NewTaskPage(t, template.HTML(fmt.Sprintf("<pre>%s</pre>", ansihtml.ConvertToHTML(buffer.Bytes()))), a.GitlabURL, "Task Logs", "terminal")
291+
if err != nil {
292+
return err
293+
}
294+
295+
p := html.Page{
296+
Domain: a.Domain,
297+
Detail: fmt.Sprintf("%s / %s - logs", t.Service, t.Commit),
298+
Partial: html.Partial{
299+
Template: taskTemplate,
300+
Data: data,
301+
},
302+
}
303+
304+
w.WriteHeader(http.StatusOK)
305+
return p.Render(w)
306+
}

0 commit comments

Comments
 (0)