Mock repository update
This commit is contained in:
parent
3285d5e896
commit
8d9245f1b1
@ -111,6 +111,22 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
||||
c.JSON(http.StatusOK, nil)
|
||||
}
|
||||
})
|
||||
|
||||
repositoriesRoutes.POST("/trigger", func(c *gin.Context) {
|
||||
repo := c.MustGet("repository").(*Repository)
|
||||
|
||||
now := time.Now()
|
||||
|
||||
if !repo.LastCheck.Before(now.Add(-5 * time.Minute)) {
|
||||
c.AbortWithStatusJSON(http.StatusPaymentRequired, gin.H{"errmsg": "Please wait between two pulls."})
|
||||
return
|
||||
}
|
||||
|
||||
repo.LastCheck = &now
|
||||
repo.Update()
|
||||
|
||||
c.JSON(http.StatusOK, repo)
|
||||
})
|
||||
}
|
||||
|
||||
func repositoryHandler(c *gin.Context) {
|
||||
|
@ -33,7 +33,7 @@
|
||||
}, (error) => {
|
||||
submitInProgress = false;
|
||||
ToastsStore.addErrorToast({
|
||||
msg: "Une erreur s'est produite durant l'envoi de votre clef : " + error,
|
||||
msg: "Une erreur s'est produite durant la création de la liaison au dépôt : " + error,
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -59,7 +59,7 @@
|
||||
type="button"
|
||||
class="btn btn-outline-info float-end mb-1"
|
||||
disable={submitInProgress || readonly}
|
||||
on:click={() => repo.delete().then(() => { refresh_repo_work() })}
|
||||
on:click={() => repo.retrieveWork().then(() => { refresh_repo_work() }, (error) => ToastsStore.addErrorToast({msg: "Une erreur s'est produite : " + error}))}
|
||||
>
|
||||
Mettre à jour
|
||||
</button>
|
||||
@ -67,7 +67,7 @@
|
||||
type="button"
|
||||
class="btn btn-outline-danger float-end mt-1"
|
||||
disable={submitInProgress || readonly}
|
||||
on:click={() => repo.delete().then(() => { refresh_repo_work() })}
|
||||
on:click={() => repo.delete().then(() => { refresh_repo_work() }, (error) => ToastsStore.addErrorToast({msg: "Une erreur s'est produite durant la suppression du lien : " + error}))}
|
||||
>
|
||||
Supprimer cette liaison
|
||||
</button>
|
||||
|
@ -25,6 +25,20 @@ export class WorkRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async retrieveWork() {
|
||||
const res = await fetch(`api/repositories/${this.id}/trigger`, {
|
||||
method: 'POST',
|
||||
headers: {'Accept': 'application/json'}
|
||||
});
|
||||
if (res.status == 200) {
|
||||
const data = await res.json();
|
||||
this.update(data);
|
||||
return data;
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
async save() {
|
||||
const res = await fetch(this.id?`api/repositories/${this.id}`:'api/repositories', {
|
||||
method: this.id?'PUT':'POST',
|
||||
|
Reference in New Issue
Block a user