Warn and give hint when using an already used repo for another work
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-09-30 12:41:34 +02:00
parent 569d44880c
commit 7cdfafc329
4 changed files with 47 additions and 10 deletions

View File

@ -60,6 +60,13 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
for _, r := range repositories { for _, r := range repositories {
if r.IdWork == work.(*Work).Id { if r.IdWork == work.(*Work).Id {
// Is the URL used elsewhere?
repos, _ := getRepositoriesByURI(r.URI)
log.Println(repos)
if len(repos) > 1 {
r.AlreadyUsed = true
}
res = append(res, r) res = append(res, r)
} }
} }
@ -114,6 +121,13 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
repositoriesRoutes.GET("", func(c *gin.Context) { repositoriesRoutes.GET("", func(c *gin.Context) {
repo := c.MustGet("repository").(*Repository) repo := c.MustGet("repository").(*Repository)
// Is the URL used elsewhere?
repos, _ := getRepositoriesByURI(repo.URI)
log.Println(repos)
if len(repos) > 1 {
repo.AlreadyUsed = true
}
c.JSON(http.StatusOK, repo) c.JSON(http.StatusOK, repo)
}) })
repositoriesRoutes.PUT("", func(c *gin.Context) { repositoriesRoutes.PUT("", func(c *gin.Context) {
@ -417,13 +431,14 @@ func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag
} }
type Repository struct { type Repository struct {
Id int64 `json:"id"` Id int64 `json:"id"`
IdUser int64 `json:"id_user"` IdUser int64 `json:"id_user"`
IdWork int64 `json:"id_work"` IdWork int64 `json:"id_work"`
URI string `json:"uri"` URI string `json:"uri"`
Secret []byte `json:"secret,omitempty"` Secret []byte `json:"secret,omitempty"`
LastCheck *time.Time `json:"last_check"` LastCheck *time.Time `json:"last_check"`
DroneRef string `json:"drone_ref,omitempty"` DroneRef string `json:"drone_ref,omitempty"`
AlreadyUsed bool `json:"already_used,omitempty"`
} }
func (u *User) GetRepositories() (repositories []*Repository, err error) { func (u *User) GetRepositories() (repositories []*Repository, err error) {
@ -492,7 +507,7 @@ func (u *User) NewRepository(w *Work, uri string) (*Repository, error) {
} else if rid, err := res.LastInsertId(); err != nil { } else if rid, err := res.LastInsertId(); err != nil {
return nil, err return nil, err
} else { } else {
return &Repository{rid, u.Id, w.Id, uri, secret, nil, ""}, nil return &Repository{rid, u.Id, w.Id, uri, secret, nil, "", false}, nil
} }
} }

View File

@ -20,6 +20,7 @@
let remote_repos = []; let remote_repos = [];
let repo_pull_state = null; let repo_pull_state = null;
let show_logs = null; let show_logs = null;
export let already_used = false;
function updatePullState(repo) { function updatePullState(repo) {
repo_pull_state = repo.getBuildState(); repo_pull_state = repo.getBuildState();
@ -45,9 +46,11 @@
} }
repo_work.then((repos) => { repo_work.then((repos) => {
repo_used = repos[0]; repo_used = repos[0];
already_used = repos[0].already_used == true;
updatePullState(repos[0]) updatePullState(repos[0])
}, () => { }, () => {
repo_used = new WorkRepository({id_work: work.id}); repo_used = new WorkRepository({id_work: work.id});
already_used = false;
remote_repos = getRemoteRepositories(user?user.id:null); remote_repos = getRemoteRepositories(user?user.id:null);
}); });
} }

View File

@ -5,13 +5,14 @@ export class WorkRepository {
} }
} }
update({ id, id_user, id_work, uri, secret, last_check }) { update({ id, id_user, id_work, uri, secret, last_check, already_used }) {
this.id = id; this.id = id;
this.id_user = id_user; this.id_user = id_user;
this.id_work = id_work; this.id_work = id_work;
this.uri = uri; this.uri = uri;
this.secret = secret; this.secret = secret;
this.last_check = last_check; this.last_check = last_check;
this.already_used = already_used == true;
} }
async delete() { async delete() {

View File

@ -24,6 +24,7 @@
export let work = null; export let work = null;
let edit = false; let edit = false;
let my_submission = null; let my_submission = null;
let warn_already_used = false;
work.then((w) => { work.then((w) => {
refresh_submission(w); refresh_submission(w);
@ -159,7 +160,7 @@
{/if} {/if}
{#if w.submission_url != "-"} {#if w.submission_url != "-"}
<WorkRepository class="mb-3" readonly={w.corrected || new Date(w.end_availability) <= new Date()} work={w} on:update_submission={() => refresh_submission(w)} /> <WorkRepository class="mb-3" readonly={w.corrected || new Date(w.end_availability) <= new Date()} work={w} on:update_submission={() => refresh_submission(w)} bind:already_used={warn_already_used} />
<div class="card mb-3"> <div class="card mb-3">
<div class="card-body d-flex justify-content-between"> <div class="card-body d-flex justify-content-between">
<div> <div>
@ -211,6 +212,23 @@
</div> </div>
{/await} {/await}
{:else if w.submission_url != "-"} {:else if w.submission_url != "-"}
{#if warn_already_used}
<div class="alert alert-danger">
<strong>Vous avez déjà utilisé ce dépôt pour rendre un autre travail.</strong> Pour conserver ce que vous avez fait, tout en respectant l'arborescence de rendu attendue, vous devriez partir d'une nouvelle branche vide&nbsp;:
<pre class="mx-2 mt-1 mb-2">
42sh$ git checkout --orphan renduX
42sh$ git reset
42sh$ rm -r *
# Créez l'arborescence de rendu ensuite</pre>
Pour retrouver ensuite vos rendus des travaux précédents&nbsp;:
<pre class="mx-2 my-1">
42sh$ git checkout renduY
-- ou --
42sh$ git checkout master
</pre>
</div>
{/if}
<div class="alert alert-warning"> <div class="alert alert-warning">
Pour être reconnu, vous devez pousser un tag <strong><a href="keys">signé</a></strong> sur votre dépôt. {#if w.tag}Le tag attendu doit commencer par&nbsp;: <code>{w.tag}</code>. Par exemple <code>{w.tag}v1.0</code>, <code>{w.tag}v1.1</code>, &hellip;{/if} Seul le dernier tag <strong>alphabétique</strong> que vous envoyez avant la date du rendu sera pris en compte. Vous pouvez donc faire autant de tag que vous le souhaitez d'ici la date du rendu. Pour être reconnu, vous devez pousser un tag <strong><a href="keys">signé</a></strong> sur votre dépôt. {#if w.tag}Le tag attendu doit commencer par&nbsp;: <code>{w.tag}</code>. Par exemple <code>{w.tag}v1.0</code>, <code>{w.tag}v1.1</code>, &hellip;{/if} Seul le dernier tag <strong>alphabétique</strong> que vous envoyez avant la date du rendu sera pris en compte. Vous pouvez donc faire autant de tag que vous le souhaitez d'ici la date du rendu.
</div> </div>