Compare commits
2 commits
f79c7b43cd
...
7cdfafc329
Author | SHA1 | Date | |
---|---|---|---|
7cdfafc329 | |||
569d44880c |
4 changed files with 69 additions and 14 deletions
|
@ -60,6 +60,13 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
|||
|
||||
for _, r := range repositories {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +121,13 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
|||
repositoriesRoutes.GET("", func(c *gin.Context) {
|
||||
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)
|
||||
})
|
||||
repositoriesRoutes.PUT("", func(c *gin.Context) {
|
||||
|
@ -264,7 +278,7 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
|||
router.POST("/callbacks/trigger.json", func(c *gin.Context) {
|
||||
// Check event type
|
||||
if c.Request.Header.Get("X-Gitlab-Event") != "Tag Push Hook" {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "This trigger is limited to Tag Push event. Please edit your trigger."})
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "This trigger is limited to Tag Push event. Please edit your trigger on GitLab."})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -284,7 +298,6 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
|||
|
||||
var repo *Repository
|
||||
for _, r := range repos {
|
||||
log.Println("Received trigger")
|
||||
if len(r.Secret) == 0 || base64.StdEncoding.EncodeToString(r.Secret) == c.Request.Header.Get("X-Gitlab-Token") {
|
||||
repo = r
|
||||
break
|
||||
|
@ -318,10 +331,29 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
|||
return
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(tmp[2], work.Tag) {
|
||||
// Allow to use a secret for another tag
|
||||
if len(repos) > 1 {
|
||||
for _, r := range repos {
|
||||
w, err := getWork(int(r.IdWork))
|
||||
if err != nil {
|
||||
log.Println("Unable to getWork:", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(tmp[2], w.Tag) {
|
||||
repo = r
|
||||
work = w
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(tmp[2], work.Tag) {
|
||||
c.AbortWithStatusJSON(http.StatusOK, gin.H{"errmsg": fmt.Sprintf("Ignore ref %q has it doesn't start with %s. Check submission instructions if this is not expected.", tmp[2], work.Tag)})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
TriggerTagUpdate(c, work, repo, user, &tmp[2])
|
||||
})
|
||||
|
@ -406,6 +438,7 @@ type Repository struct {
|
|||
Secret []byte `json:"secret,omitempty"`
|
||||
LastCheck *time.Time `json:"last_check"`
|
||||
DroneRef string `json:"drone_ref,omitempty"`
|
||||
AlreadyUsed bool `json:"already_used,omitempty"`
|
||||
}
|
||||
|
||||
func (u *User) GetRepositories() (repositories []*Repository, err error) {
|
||||
|
@ -474,7 +507,7 @@ func (u *User) NewRepository(w *Work, uri string) (*Repository, error) {
|
|||
} else if rid, err := res.LastInsertId(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Repository{rid, u.Id, w.Id, uri, secret, nil, ""}, nil
|
||||
return &Repository{rid, u.Id, w.Id, uri, secret, nil, "", false}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
let remote_repos = [];
|
||||
let repo_pull_state = null;
|
||||
let show_logs = null;
|
||||
export let already_used = false;
|
||||
|
||||
function updatePullState(repo) {
|
||||
repo_pull_state = repo.getBuildState();
|
||||
|
@ -45,9 +46,11 @@
|
|||
}
|
||||
repo_work.then((repos) => {
|
||||
repo_used = repos[0];
|
||||
already_used = repos[0].already_used == true;
|
||||
updatePullState(repos[0])
|
||||
}, () => {
|
||||
repo_used = new WorkRepository({id_work: work.id});
|
||||
already_used = false;
|
||||
remote_repos = getRemoteRepositories(user?user.id:null);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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_user = id_user;
|
||||
this.id_work = id_work;
|
||||
this.uri = uri;
|
||||
this.secret = secret;
|
||||
this.last_check = last_check;
|
||||
this.already_used = already_used == true;
|
||||
}
|
||||
|
||||
async delete() {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
export let work = null;
|
||||
let edit = false;
|
||||
let my_submission = null;
|
||||
let warn_already_used = false;
|
||||
|
||||
work.then((w) => {
|
||||
refresh_submission(w);
|
||||
|
@ -159,7 +160,7 @@
|
|||
{/if}
|
||||
|
||||
{#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-body d-flex justify-content-between">
|
||||
<div>
|
||||
|
@ -211,6 +212,23 @@
|
|||
</div>
|
||||
{/await}
|
||||
{: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 :
|
||||
<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 :
|
||||
<pre class="mx-2 my-1">
|
||||
42sh$ git checkout renduY
|
||||
-- ou --
|
||||
42sh$ git checkout master
|
||||
</pre>
|
||||
</div>
|
||||
{/if}
|
||||
<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 : <code>{w.tag}</code>. Par exemple <code>{w.tag}v1.0</code>, <code>{w.tag}v1.1</code>, …{/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>
|
||||
|
|
Reference in a new issue