Browse Source

queue on dashboard, fixed build-now using a wrong build script

master
Stefan Naumann 5 months ago
parent
commit
a523c0d07a
3 changed files with 59 additions and 6 deletions
  1. +16
    -4
      build/build.go
  2. +38
    -1
      views/dashboard.html
  3. +5
    -1
      web/index.go

+ 16
- 4
build/build.go View File

@@ -4,7 +4,6 @@
package build

import (
"fmt"
"time"
"mvoCI/core"

@@ -13,8 +12,15 @@ import (

// build a repository now (the latest commit, default branch)
func BuildNow ( r core.Repository, db *gorm.DB ) uint {
var bs core.BuildScript
db.Where("repository_id=? AND event_type = ?", r.ID, "push" ).First (&bs );

if bs.ID <= 0 {
// fallback: push event
return 0;
}
b := core.Build { Log: "", CommitSha: "", FinishedAt: time.Unix(0,0),
Branch: r.DefaultBranch,
Branch: r.DefaultBranch, BuildScript: bs,
Repository: r, Status : "enqueued", Event: "User Build"}
db.Create ( &b );
EnqueueBuild ( b );
@@ -25,7 +31,6 @@ func BuildRelease ( db *gorm.DB, r core.Repository, branch string, sha string, a
var bs core.BuildScript
db.Where("repository_id=? AND event_type = ?", r.ID, event ).First (&bs );

fmt.Println("BSID: ", bs.ID);
if bs.ID <= 0 {
// fallback: push event
if event != "push" {
@@ -50,7 +55,13 @@ func BuildSpecific2 ( db *gorm.DB, r core.Repository, branch string, sha string,
db.Where("repository_id=? AND event_type = ?", r.ID, event ).First (&bs );

if bs.ID <= 0 {
return 0;
// fallback: push event
if event != "push" {
db.Where("repository_id=? AND event_type = ?", r.ID, "push" ).First (&bs );
if bs.ID <= 0 {
return 0;
}
}
}
b := core.Build { Log: "", CommitSha: sha, FinishedAt: time.Unix(0,0),
Branch: branch, Repository: r, Status : "enqueued",
@@ -66,6 +77,7 @@ func BuildSpecific ( db *gorm.DB, r core.Repository, branch string, sha string )
db.Where("repository_id=? AND event_type = ?", r.ID, "push" ).First (&bs );

if bs.ID <= 0 {
// fallback: push event
return 0;
}



+ 38
- 1
views/dashboard.html View File

@@ -1,7 +1,44 @@
{{ define "title" }}Dashboard{{ end }}
{{ define "toolbar" }}{{ end }}
{{ define "content" }}
<h2>Dashboard</h2>
<h2>Dashboard</h2>
{{ if .queue }}
<h3>Queue</h3>
{{ range .queue }}
<div class="block-link">
<span class="block">
<span class="left-side">
<span class="block-item block-icon">
{{ build_status .Status }}
</span>
<span class="block-item">
<span class="block-top-item">
<a href="/repo/view/{{ .RepositoryID }}">{{ call $.repoName .RepositoryID }}</a>
</span>
<span class="block-bottom-item block-fa">
{{ .CommitSha }}
</span>
</span>
</span>
<span class="right-side">
<span class="block-item">
<span class="block-top-item block-fa">
<i class="fa fa-calendar-o"></i>{{ render_time .StartedAt }}
</span>
<span class="block-bottom-item block-fa">
<i class="fa fa-calendar-check-o"></i>{{ render_time .FinishedAt }}
</span>
</span>
<span class="block-item dashboard-icons">
<a href="/repo/view/{{ .RepositoryID }}" title="View Repository" class="fa fa-folder"></a>
<a href="/build/{{ .ID }}" title="View Build" class="fa fa-chevron-right"></a>
</span>
</span>
</span>
</div>
{{ end }}
{{ end }}

<h3>Recent Builds</h3>
{{ range .builds }}
<div class="block-link">


+ 5
- 1
web/index.go View File

@@ -14,9 +14,12 @@ import (
func dashboardHandler ( ctx echo.Context, user core.User ) error {
var b []core.Build;
s.db.Select("id, finished_at, started_at, status, commit_sha, branch, repository_id, zip").Order("builds.created_at desc").Limit(10).Find ( &b )

var bs []core.Build
s.db.Select("id, finished_at, started_at, status, commit_sha, branch, repository_id, zip").Where("status='started' OR status='enqueued'").Order("status desc, builds.created_at asc").Limit(10).Find ( &bs )
var repo map[uint]string = make( map[uint]string )
var ids []uint
for _ , el := range b {
for _ , el := range append(b,bs...) {
var in bool = false
for _, ide := range ids {
if el.RepositoryID == ide {
@@ -40,6 +43,7 @@ func dashboardHandler ( ctx echo.Context, user core.User ) error {
"builds" : b,
"navPage": "dashboard",
"user": user,
"queue": bs,
"repoName": func ( id uint ) string {
return repo[id]
},


Loading…
Cancel
Save