Can display extraction logs
This commit is contained in:
parent
eacaedeb03
commit
0b16676929
@ -205,6 +205,35 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
|||||||
|
|
||||||
c.JSON(http.StatusOK, result)
|
c.JSON(http.StatusOK, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
repositoriesRoutes.GET("/state-logs", func(c *gin.Context) {
|
||||||
|
repo := c.MustGet("repository").(*Repository)
|
||||||
|
|
||||||
|
tmp := strings.Split(repo.DroneRef, "/")
|
||||||
|
if len(tmp) < 3 {
|
||||||
|
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "No build number. Please try pulling your work."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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.Logs(tmp[0], tmp[1], nbuild, 1, 2)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Unable to retrieve logs."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) > 7 {
|
||||||
|
c.JSON(http.StatusOK, result[7:])
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, result)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func repositoryHandler(c *gin.Context) {
|
func repositoryHandler(c *gin.Context) {
|
||||||
|
@ -12,11 +12,27 @@
|
|||||||
let repo_work = null;
|
let repo_work = null;
|
||||||
let repo_used = null;
|
let repo_used = null;
|
||||||
let remote_repos = [];
|
let remote_repos = [];
|
||||||
|
let repo_pull_state = null;
|
||||||
|
let show_logs = null;
|
||||||
|
|
||||||
|
function updatePullState(repo) {
|
||||||
|
repo_pull_state = repo.getBuildState();
|
||||||
|
repo_pull_state.then((state) => {
|
||||||
|
if (state.status == "pending" || state.status == "running") {
|
||||||
|
setTimeout(() => updatePullState(repo), state.status == "pending" ? 1000 : 2500);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLogs(repo) {
|
||||||
|
show_logs = repo.getBuildLogs()
|
||||||
|
}
|
||||||
|
|
||||||
function refresh_repo_work() {
|
function refresh_repo_work() {
|
||||||
repo_work = getRepositories(work.id);
|
repo_work = getRepositories(work.id);
|
||||||
repo_work.then((repos) => {
|
repo_work.then((repos) => {
|
||||||
repo_used = repos[0];
|
repo_used = repos[0];
|
||||||
|
updatePullState(repos[0])
|
||||||
}, () => {
|
}, () => {
|
||||||
repo_used = new WorkRepository({id_work: work.id});
|
repo_used = new WorkRepository({id_work: work.id});
|
||||||
remote_repos = getRemoteRepositories();
|
remote_repos = getRemoteRepositories();
|
||||||
@ -52,25 +68,27 @@
|
|||||||
<div>
|
<div>
|
||||||
Dépôt lié : <strong style="font-family: monospace">{repo.uri}</strong><br>
|
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>
|
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()}
|
{#if repo_pull_state}
|
||||||
<div class="spinner-grow spinner-grow-sm mx-1" role="status"></div>
|
{#await repo_pull_state}
|
||||||
{:then state}
|
<div class="spinner-grow spinner-grow-sm mx-1" role="status"></div>
|
||||||
{#if state.status == "pending" || state.status == "running"}
|
{:then state}
|
||||||
<div
|
{#if state.status == "pending" || state.status == "running"}
|
||||||
class="spinner-grow spinner-grow-sm mx-1"
|
<div
|
||||||
class:text-secondary={state.status == "pending"}
|
class="spinner-grow spinner-grow-sm mx-1"
|
||||||
class:text-warning={state.status == "running"}
|
class:text-secondary={state.status == "pending"}
|
||||||
title="La récupération est en cours"
|
class:text-warning={state.status == "running"}
|
||||||
role="status"
|
title="La récupération est en cours"
|
||||||
></div>
|
role="status"
|
||||||
{:else if state.status == "success"}
|
></div>
|
||||||
<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 == "success"}
|
||||||
{:else if state.status == "failure"}
|
<i class="bi bi-check-circle-fill text-success mx-1" title="La récupération s'est bien passée"></i>
|
||||||
<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 if state.status == "failure"}
|
||||||
{:else}
|
<i class="bi bi-exclamation-circle-fill text-danger mx-1" title="La récupération ne s'est pas bien passée" style="cursor: pointer" on:click={() => showLogs(repo)}></i>
|
||||||
{state.status}
|
{:else}
|
||||||
{/if}
|
{state.status}
|
||||||
{/await}
|
{/if}
|
||||||
|
{/await}
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex flex-column justify-content-center">
|
<div class="d-flex flex-column justify-content-center">
|
||||||
@ -92,6 +110,13 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{#if show_logs}
|
||||||
|
{#await show_logs then logs}
|
||||||
|
<div class="card-body d-flex justify-content-between bg-dark text-light">
|
||||||
|
<pre class="pb-2">{#each logs as l (l.pos)}{l.out}{/each}</pre>
|
||||||
|
</div>
|
||||||
|
{/await}
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{:catch}
|
{:catch}
|
||||||
|
@ -36,6 +36,17 @@ export class WorkRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBuildLogs() {
|
||||||
|
const res = await fetch(`api/repositories/${this.id}/state-logs`, {
|
||||||
|
headers: {'Accept': 'application/json'}
|
||||||
|
});
|
||||||
|
if (res.status == 200) {
|
||||||
|
return await res.json();
|
||||||
|
} else {
|
||||||
|
throw new Error((await res.json()).errmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async retrieveWork() {
|
async retrieveWork() {
|
||||||
const res = await fetch(`api/repositories/${this.id}/trigger`, {
|
const res = await fetch(`api/repositories/${this.id}/trigger`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
Reference in New Issue
Block a user