New route to retrieve gradation status
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2023-03-06 03:44:39 +01:00
parent 1515140c09
commit 184daa4cab
3 changed files with 65 additions and 8 deletions

View File

@ -320,6 +320,36 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
TriggerTests(c, work, repo, u)
})
repositoriesRoutes.GET("/gradation_status", func(c *gin.Context) {
loggeduser := c.MustGet("LoggedUser").(*User)
if !loggeduser.IsAdmin {
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "Permission denied."})
return
}
repo := c.MustGet("repository").(*Repository)
slug := strings.Split(repo.TestsRef, "/")
if len(slug) < 3 {
return
}
buildn, err := strconv.ParseInt(slug[2], 10, 32)
if err != nil {
return
}
client := drone.NewClient(droneEndpoint, droneConfig)
build, err := client.Build(slug[0], slug[1], int(buildn))
if err != nil {
log.Println("Unable to communicate with Drone:", err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to communicate with Drone"})
return
}
c.JSON(http.StatusOK, build)
})
repositoriesRoutes.GET("/traces", func(c *gin.Context) {
repo := c.MustGet("repository").(*Repository)

View File

@ -88,6 +88,18 @@ export class WorkRepository {
}
}
async gradationStatus() {
const res = await fetch(this.id_work?`api/works/${this.id_work}/repositories/${this.id}/gradation_status`:`api/repositories/${this.id}/gradation_status`, {
method: 'GET',
headers: {'Accept': 'application/json'},
});
if (res.status == 200) {
return await res.json();
} else {
throw new Error((await res.json()).errmsg);
}
}
async save(user) {
let url = this.id?`repositories/${this.id}`:'repositories';

View File

@ -140,14 +140,29 @@
>
<i class="bi bi-trash"></i>
</button>
<button
class="btn btn-sm btn-success mr-1"
class:disabled={!show_dl_btn[user.id]}
title="Relancer les tests"
on:click={() => { repo.runGradation(); }}
>
<i class="bi bi-play"></i>
</button>
{#await repo.gradationStatus()}
<button
class="btn btn-sm btn-outline-success mr-1"
class:disabled={!show_dl_btn[user.id]}
title="Relancer les tests"
on:click={() => { repo.runGradation(); }}
>
<div class="spinner-border spinner-border-sm" role="status"></div>
</button>
{:then status}
<button
class="btn btn-sm mr-1"
class:btn-success={status.status == "success"}
class:btn-danger={status.status == "failure"}
class:btn-outline-danger={status.status == "killed"}
class:btn-outline-warning={status.status == "pending" || status.status == "running"}
class:disabled={!show_dl_btn[user.id]}
title="Relancer les tests"
on:click={() => { repo.runGradation(); }}
>
<i class="bi bi-play"></i>
</button>
{/await}
<a
href="/api/users/{user.id}/works/{w.id}/repositories/{repo.id}/traces"
target="_blank"