Skip to content
Permalink
Browse files

Adding more information on builds

  • Loading branch information...
Depado committed Feb 10, 2016
1 parent 4cc5159 commit 327c3024e26dc1bc58eeb03c0918a8394c1ccd23
Showing with 91 additions and 24 deletions.
  1. +5 −0 admin/admin.go
  2. +1 −5 main.go
  3. +67 −7 models/build.go
  4. +12 −6 models/service.go
  5. +6 −6 templates/index.tmpl
@@ -2,22 +2,27 @@ package admin

import "github.com/gin-gonic/gin"

// Root is the main route
func Root(c *gin.Context) {

}

// Hosts lists the services
func Hosts(c *gin.Context) {

}

// NewHost displays the form to add a service
func NewHost(c *gin.Context) {

}

// PostNewHost handles the form submit
func PostNewHost(c *gin.Context) {

}

// DeleteHost allows to delete a service
func DeleteHost(c *gin.Context) {

}
@@ -1,7 +1,6 @@
package main

import (
"crypto/tls"
"fmt"
"log"
"net/http"
@@ -19,12 +18,9 @@ var all models.Services

func periodicHostUpdate() {
tc := time.NewTicker(30 * time.Minute)
client := &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
for {
for _, host := range all {
go host.Check(client)
go host.Check()
}
<-tc.C
}
@@ -1,15 +1,17 @@
package models

// Build represents the builds
type Build struct {
import "time"

// UnparsedBuild represents the unparsed response from the CI
type UnparsedBuild struct {
ID int `json:"id"`
Number int `json:"number"`
Event string `json:"event"`
Status string `json:"status"`
EnqueuedAt int `json:"enqueued_at"`
CreatedAt int `json:"created_at"`
StartedAt int `json:"started_at"`
FinishedAt int `json:"finished_at"`
EnqueuedAt int64 `json:"enqueued_at"`
CreatedAt int64 `json:"created_at"`
StartedAt int64 `json:"started_at"`
FinishedAt int64 `json:"finished_at"`
DeployTo string `json:"deploy_to"`
Commit string `json:"commit"`
Branch string `json:"branch"`
@@ -18,12 +20,70 @@ type Build struct {
Remote string `json:"remote"`
Title string `json:"title"`
Message string `json:"message"`
Timestamp int `json:"timestamp"`
Timestamp int64 `json:"timestamp"`
Author string `json:"author"`
AuthorAvatar string `json:"author_avatar"`
AuthorEmail string `json:"author_email"`
LinkURL string `json:"link_url"`
}

// UnparsedBuilds represents a list of UnparsedBuild
type UnparsedBuilds []UnparsedBuild

// Build is the parsed CI response
type Build struct {
ID int
Number int
Event string
Status string
EnqueuedAt time.Time
CreatedAt time.Time
StartedAt time.Time
FinishedAt time.Time
DeployTo string
Commit string
Branch string
Ref string
Refspec string
Remote string
Title string
Message string
Timestamp time.Time
Author string
AuthorAvatar string
AuthorEmail string
LinkURL string
Duration time.Duration
}

// Parse parses the times in the UnparsedBuild and returns a Build
func (u UnparsedBuild) Parse() Build {
b := Build{
ID: u.ID,
Number: u.Number,
Event: u.Event,
Status: u.Status,
EnqueuedAt: time.Unix(u.EnqueuedAt, 0),
CreatedAt: time.Unix(u.CreatedAt, 0),
StartedAt: time.Unix(u.StartedAt, 0),
FinishedAt: time.Unix(u.FinishedAt, 0),
DeployTo: u.DeployTo,
Commit: u.Commit,
Branch: u.Branch,
Ref: u.Ref,
Refspec: u.Refspec,
Remote: u.Remote,
Title: u.Title,
Message: u.Message,
Timestamp: time.Unix(u.Timestamp, 0),
Author: u.Author,
AuthorAvatar: u.AuthorAvatar,
AuthorEmail: u.AuthorEmail,
LinkURL: u.LinkURL,
}
b.Duration = b.FinishedAt.Sub(b.StartedAt)
return b
}

// Builds represent multiple builds
type Builds []Build
@@ -1,6 +1,7 @@
package models

import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
@@ -9,8 +10,6 @@ import (
"time"
)

const ghAPI = "/"

// Service is a single service
type Service struct {
Name string
@@ -69,17 +68,24 @@ func (s *Service) CheckBuild(client *http.Client) {
return
}
defer resp.Body.Close()
var all Builds
var all UnparsedBuilds
if err = json.NewDecoder(resp.Body).Decode(&all); err != nil {
log.Printf("[%s][ERROR] Couldn't decode response : %v\n", s.Name, err)
return
}
s.LastBuilds = all
s.LastBuild = all[0].Status
pall := make(Builds, len(all))
for i, b := range all {
pall[i] = b.Parse()
}
s.LastBuilds = pall
s.LastBuild = pall[0].Status
}

// Check updates the status of the Host
func (s *Service) Check(client *http.Client) {
func (s *Service) Check() {
client := &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
if s.URL != "" {
go s.CheckStatus(client)
}
@@ -49,11 +49,11 @@
{{ end }}
</a>
</div>
<div class="extra text">
<i class="fork icon"></i> {{ .Branch }}
</div>
<div class="meta">
<a href="{{ .LinkURL }}" target="_blank">{{ .Message }}</a>
<i class="clock icon"></i> {{ .StartedAt }}<br />
<i class="fork icon" style="margin-left: 0;"></i> {{ .Event }} on {{ .Branch }} branch<br />
<i class="refresh icon" style="margin-left: 0;"></i> {{ .Duration }}<br />
<a href="{{ .LinkURL }}" target="_blank" style="margin-left: 0;"><i class="chat icon"></i> {{ .Message }}</a>
</div>
</div>
</div>
@@ -82,8 +82,8 @@
</div>
<div class="meta">
<i class="clock icon"></i> {{ .Commit.Author.Date }}<br />
<i class="chat icon" style="margin-left: 0;"></i> {{ .Commit.CommentCount }} Comments<br />
<a href="{{ .HTMLURL }}" target="_blank" style="margin-left: 0;"><i class="fork icon"></i> {{ .Commit.Message }}</a>
<i class="comments icon" style="margin-left: 0;"></i> {{ .Commit.CommentCount }} Comments<br />
<a href="{{ .HTMLURL }}" target="_blank" style="margin-left: 0;"><i class="chat icon"></i> {{ .Commit.Message }}</a>
</div>
</div>
</div>

0 comments on commit 327c302

Please sign in to comment.
You can’t perform that action at this time.