vole
Clone
Read only, no credentials:
https://rodent.software/git/vole.git
Write over SSH with a registered key:
git clone ssh://git@0.0.0.0:2222/vole.git
A free and open-source forge that lives in your Git repo.
Merge change request 01M70WES5ZZDJ6RP226WB11BBZ: Let people rename and remove their own passkeys
keenan · 1h ago
4b8c9e1d
| 1 | package web |
| 2 | |
| 3 | // CI actions on one run: cancel it while it waits, ask a running job to stop, or |
| 4 | // enqueue the same pinned job again. A running job is stopped by its runner at the |
| 5 | // next heartbeat; the queue cannot kill a process it does not own, but it can say |
| 6 | // that a maintainer asked. |
| 7 | |
| 8 | import ( |
| 9 | "net/http" |
| 10 | "time" |
| 11 | |
| 12 | "rodent.software/vole/ci/runs" |
| 13 | "rodent.software/vole/forge/repo" |
| 14 | ) |
| 15 | |
| 16 | func (w *Web) runAction(rw http.ResponseWriter, r *http.Request) (*repo.Meta, *runs.Run, string, bool) { |
| 17 | ctx, ok := w.beginWrite(rw, r, maxSmallForm) |
| 18 | if !ok { |
| 19 | return nil, nil, "", false |
| 20 | } |
| 21 | if w.Runs == nil { |
| 22 | w.notFound(rw, r) |
| 23 | return nil, nil, "", false |
| 24 | } |
| 25 | // Managing a run is the maintainer capability, not triage of one item. |
| 26 | if !canMaintain(ctx.ACL, ctx.Name) { |
| 27 | w.refuse(rw, r, "only a maintainer or admin may manage CI") |
| 28 | return nil, nil, "", false |
| 29 | } |
| 30 | run, err := w.Runs.Get(r.PathValue("id")) |
| 31 | if err != nil || run == nil || run.Repo != ctx.Repo.Name { |
| 32 | w.notFound(rw, r) |
| 33 | return nil, nil, "", false |
| 34 | } |
| 35 | return ctx.Repo, run, ctx.Name, true |
| 36 | } |
| 37 | |
| 38 | func (w *Web) CancelRun(rw http.ResponseWriter, r *http.Request) { |
| 39 | m, run, accountID, ok := w.runAction(rw, r) |
| 40 | if !ok { |
| 41 | return |
| 42 | } |
| 43 | now := time.Now().UTC() |
| 44 | var canceled bool |
| 45 | var err error |
| 46 | switch run.Status { |
| 47 | case runs.StatusQueued: |
| 48 | // Waiting work is retired outright: no runner has it, so nothing needs to be |
| 49 | // asked to stop. |
| 50 | canceled, err = w.Runs.CancelQueued(run.ID, m.Name, accountID, now) |
| 51 | case runs.StatusRunning: |
| 52 | // The runner holds the lease and learns about this on its next heartbeat. The |
| 53 | // run is not canceled yet: it becomes canceled when the attempt comes back. |
| 54 | canceled, err = w.Runs.CancelRunning(run.ID, m.Name, accountID, now) |
| 55 | default: |
| 56 | http.Error(rw, "only a queued or running run can be canceled", http.StatusBadRequest) |
| 57 | return |
| 58 | } |
| 59 | if err != nil { |
| 60 | w.serverError(rw, r, "cannot cancel the run: "+err.Error()) |
| 61 | return |
| 62 | } |
| 63 | if !canceled { |
| 64 | http.Error(rw, "this run has already finished; nothing was canceled", http.StatusBadRequest) |
| 65 | return |
| 66 | } |
| 67 | w.audit("run.cancel", accountID, m.Name, run.ID) |
| 68 | http.Redirect(rw, r, "/"+m.Name+"/runs/"+run.ID, http.StatusSeeOther) |
| 69 | } |
| 70 | |
| 71 | func (w *Web) Rerun(rw http.ResponseWriter, r *http.Request) { |
| 72 | m, run, accountID, ok := w.runAction(rw, r) |
| 73 | if !ok { |
| 74 | return |
| 75 | } |
| 76 | if run.Status == runs.StatusQueued || run.Status == runs.StatusRunning { |
| 77 | http.Error(rw, "this run has not finished yet", http.StatusBadRequest) |
| 78 | return |
| 79 | } |
| 80 | queued, err := w.Runs.Requeue(run.ID, m.Name, time.Now().UTC()) |
| 81 | if err != nil { |
| 82 | w.serverError(rw, r, "cannot queue the run: "+err.Error()) |
| 83 | return |
| 84 | } |
| 85 | if !queued { |
| 86 | http.Error(rw, "only a finished run can be rerun", http.StatusBadRequest) |
| 87 | return |
| 88 | } |
| 89 | w.audit("run.rerun", accountID, m.Name, run.ID) |
| 90 | http.Redirect(rw, r, "/"+m.Name+"/runs/"+run.ID, http.StatusSeeOther) |
| 91 | } |
| 92 |