Retrieve Drone build state
This commit is contained in:
parent
65b62afb82
commit
6245e49be7
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
@ -155,10 +156,10 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
if repo.LastCheck != nil && !repo.LastCheck.Before(now.Add(-5*time.Minute)) {
|
||||
/*if repo.LastCheck != nil && !repo.LastCheck.Before(now.Add(-5*time.Minute)) {
|
||||
c.AbortWithStatusJSON(http.StatusPaymentRequired, gin.H{"errmsg": "Please wait between two pulls."})
|
||||
return
|
||||
}
|
||||
}*/
|
||||
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.BuildCreate("srs", "atsebay.t-worker", "", "master", map[string]string{
|
||||
@ -179,6 +180,27 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
||||
|
||||
c.JSON(http.StatusOK, repo)
|
||||
})
|
||||
|
||||
repositoriesRoutes.GET("/state", func(c *gin.Context) {
|
||||
repo := c.MustGet("repository").(*Repository)
|
||||
|
||||
tmp := strings.Split(repo.DroneRef, "/")
|
||||
nbuild, err := strconv.Atoi(tmp[2])
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Bad build number. Please retry pulling your work."})
|
||||
return
|
||||
}
|
||||
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.Build(tmp[0], tmp[1], nbuild)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Unable to find the referenced extraction."})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func repositoryHandler(c *gin.Context) {
|
||||
@ -252,7 +274,7 @@ func (u *User) getRepository(id int) (r *Repository, err error) {
|
||||
}
|
||||
|
||||
func (u *User) NewRepository(w *Work, uri string) (*Repository, error) {
|
||||
if res, err := DBExec("INSERT INTO user_work_repositories (id_user, id_work, uri) VALUES (?, ?, ?)", u.Id, w.Id, uri); err != nil {
|
||||
if res, err := DBExec("INSERT INTO user_work_repositories (id_user, id_work, uri, droneref) VALUES (?, ?, ?, ?)", u.Id, w.Id, uri, ""); err != nil {
|
||||
return nil, err
|
||||
} else if rid, err := res.LastInsertId(); err != nil {
|
||||
return nil, err
|
||||
|
@ -52,6 +52,25 @@
|
||||
<div>
|
||||
Dépôt lié : <strong style="font-family: monospace">{repo.uri}</strong><br>
|
||||
Dernière récupération : <strong>{#if repo.last_check}<DateFormat date={new Date(repo.last_check)} dateStyle="medium" timeStyle="medium" />{:else}-{/if}</strong>
|
||||
{#await repo.getBuildState()}
|
||||
<div class="spinner-grow spinner-grow-sm mx-1" role="status"></div>
|
||||
{:then state}
|
||||
{#if state.status == "pending" || state.status == "running"}
|
||||
<div
|
||||
class="spinner-grow spinner-grow-sm mx-1"
|
||||
class:text-secondary={state.status == "pending"}
|
||||
class:text-warning={state.status == "running"}
|
||||
title="La récupération est en cours"
|
||||
role="status"
|
||||
></div>
|
||||
{:else if state.status == "success"}
|
||||
<i class="bi bi-check-circle-fill text-success mx-1" title="La récupération s'est bien passée"></i>
|
||||
{:else if state.status == "failure"}
|
||||
<i class="bi bi-exclamation-circle-fill text-danger mx-1" title="La récupération ne s'est pas bien passée"></i>
|
||||
{:else}
|
||||
{state.status}
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-column justify-content-center">
|
||||
|
@ -25,6 +25,17 @@ export class WorkRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async getBuildState() {
|
||||
const res = await fetch(`api/repositories/${this.id}/state`, {
|
||||
headers: {'Accept': 'application/json'}
|
||||
});
|
||||
if (res.status == 200) {
|
||||
return await res.json();
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
async retrieveWork() {
|
||||
const res = await fetch(`api/repositories/${this.id}/trigger`, {
|
||||
method: 'POST',
|
||||
|
Reference in New Issue
Block a user