oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/chat"
5 "amadan.net/oficina/equipo/internal/wire"
6 "context"
7 "github.com/go-chi/chi/v5"
8 "net/http"
9 "strconv"
10)
11
12type placementView struct {
13 Task wire.Task
14 Repos []string
15 New, Restart, Ended, Merging bool
16}
17
18func (a *application) projectPlacement(w http.ResponseWriter, r *http.Request) {
19 ctx, person, ok := sessionContext(r)
20 if !ok {
21 a.failure(w, r, ErrForbidden)
22 return
23 }
24 id := chi.URLParam(r, "id")
25 choices, err := a.store.Chat().MoveChoices(ctx, person, id)
26 if err != nil {
27 a.failure(w, r, chatError(err))
28 return
29 }
30 task, err := a.store.Chat().Task(ctx, person, id)
31 if err != nil {
32 a.failure(w, r, chatError(err))
33 return
34 }
35 data, err := a.page(r, "tasks")
36 if err != nil {
37 a.failure(w, r, err)
38 return
39 }
40 v := placementView{Task: task, New: r.URL.Query().Get("new") == "1", Ended: wire.FinalStage(task.Stage), Merging: task.Stage == wire.StageMerging}
41 for _, repo := range choices {
42 if repo != task.Repo {
43 v.Repos = append(v.Repos, chat.ProjectName(repo))
44 }
45 }
46 for _, st := range task.Steps {
47 if st.Specialist == wire.SpecialistEngineering {
48 v.Restart = true
49 }
50 }
51 data.Placement = v
52 w.Header().Set("Cache-Control", "no-store")
53 render(w, "placement", data)
54}
55
56func (a *application) moveProject(w http.ResponseWriter, r *http.Request) {
57 id := chi.URLParam(r, "id")
58 a.chatActionTo(w, r, "/tasks/"+id, func(ctx context.Context, person string) error {
59 rev, err := strconv.ParseInt(r.FormValue("revision"), 10, 64)
60 if err != nil {
61 return chat.ErrInvalid
62 }
63 if r.FormValue("abandon") == "1" {
64 return a.store.Chat().AbandonMove(ctx, person, id, rev)
65 }
66 in := wire.MoveTask{Repo: r.FormValue("repo"), Revision: rev}
67 if r.FormValue("new") == "1" {
68 return a.store.Chat().RequestNewProjectMove(ctx, person, id, in)
69 }
70 return a.store.Chat().MoveTask(ctx, person, id, in)
71 })
72}
73
74func placementPendingLine(t wire.Task) string {
75 if t.Stopping {
76 return copyText("roster.stopping")
77 }
78 if t.MoveHoldReason != "" {
79 return copyText("placement.held_" + t.MoveHoldReason)
80 }
81 if t.PreparingProject {
82 return copyText("placement.preparing")
83 }
84 return copyText("placement.pending")
85}
86
87func (a *application) removePlacementNote(w http.ResponseWriter, r *http.Request) {
88 a.chatActionTo(w, r, "/conversation/settings/notebook", func(ctx context.Context, person string) error {
89 return a.store.Chat().RemovePlacementNote(ctx, person, chi.URLParam(r, "id"))
90 })
91}
92