vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Manage release channels from the releases page
de72893e35f2fe73bb1741b88dcbabdfb238c8b0 · Keenan Nemetz · 17d ago · parent 529a8457
Manage release channels from the releases page Channels no longer have a separate listing page. Releases shows the channel list, a badge on each target release, and a maintainer form that creates, moves, and clears channels with the same validation and audit record as the CLI.
server/web/channels.go +116−27
| @@ -39,15 +39,18 @@ func (w *Web) channel(m *repo.Meta, name string) (channel.Channel, bool) { | |||
| 39 | 39 | return ch, ok | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | // channelTarget resolves the release a channel names. An annotated tag is | ||
| 43 | // required because a channel is a release alias, and the tag object has to match | ||
| 44 | // the pointer: a rewritten tag is a different release, not a moved channel. | ||
| 42 | // channelTargetFromTag reports whether t is the release ch was recorded against. | ||
| 43 | // An annotated tag is required because a channel is a release alias, and the tag | ||
| 44 | // object has to match the pointer: a rewritten tag is a different release, not a | ||
| 45 | // moved channel. | ||
| 46 | func channelTargetFromTag(t git.Tag, ch channel.Channel) bool { | ||
| 47 | return t.Annotated && ch.ReleaseObject != "" && strings.EqualFold(t.OID, ch.ReleaseObject) | ||
| 48 | } | ||
| 49 | |||
| 50 | // channelTarget resolves the release a channel names. | ||
| 45 | 51 | func (w *Web) channelTarget(g *git.Repo, ch channel.Channel) (git.Tag, bool) { | |
| 46 | 52 | t, err := g.Tag(ch.Release) | |
| 47 | if err != nil || !t.Annotated || ch.ReleaseObject == "" { | ||
| 48 | return git.Tag{}, false | ||
| 49 | } | ||
| 50 | if !strings.EqualFold(t.OID, ch.ReleaseObject) { | ||
| 53 | if err != nil || !channelTargetFromTag(t, ch) { | ||
| 51 | 54 | return git.Tag{}, false | |
| 52 | 55 | } | |
| 53 | 56 | return t, true | |
| @@ -60,29 +63,115 @@ type channelRow struct { | |||
| 60 | 63 | Body template.HTML | |
| 61 | 64 | } | |
| 62 | 65 | ||
| 63 | // Channels lists the repository's stable names. The list is the place to see | ||
| 64 | // what a channel points at without following it. | ||
| 65 | func (w *Web) Channels(rw http.ResponseWriter, r *http.Request) { | ||
| 66 | m, ok := w.open(rw, r) | ||
| 66 | // SetChannel creates or moves a channel from the browser. It is the form of | ||
| 67 | // `vole release channel set`: the same maintain check, annotated-tag requirement, | ||
| 68 | // description bound, and audit record, with the actor taken from the session. | ||
| 69 | func (w *Web) SetChannel(rw http.ResponseWriter, r *http.Request) { | ||
| 70 | ctx, ok := w.beginWrite(rw, r, maxSmallForm) | ||
| 67 | 71 | if !ok { | |
| 68 | 72 | return | |
| 69 | 73 | } | |
| 70 | list := w.channels(m) | ||
| 71 | rows := make([]channelRow, 0, len(list)) | ||
| 72 | for _, ch := range list { | ||
| 73 | _, ok := w.channelTarget(m.Git(), ch) | ||
| 74 | rows = append(rows, channelRow{ | ||
| 75 | Channel: ch, | ||
| 76 | Target: ch.Release, | ||
| 77 | Dangling: !ok, | ||
| 78 | Body: w.renderMarkdown(m.Name, ch.Description), | ||
| 79 | }) | ||
| 80 | } | ||
| 81 | w.render(rw, "channels", struct { | ||
| 82 | Page | ||
| 83 | Name string | ||
| 84 | Channels []channelRow | ||
| 85 | }{w.page(r, m.Name+" · channels"), m.Name, rows}, 0) | ||
| 74 | m := ctx.Repo | ||
| 75 | if !canMaintain(ctx.ACL, ctx.Name) { | ||
| 76 | w.notFound(rw, r) | ||
| 77 | return | ||
| 78 | } | ||
| 79 | if w.ChannelStore == nil { | ||
| 80 | w.serverError(rw, r, "the channel store is not available") | ||
| 81 | return | ||
| 82 | } | ||
| 83 | |||
| 84 | name := strings.TrimSpace(r.PostFormValue("channel")) | ||
| 85 | tag := strings.TrimSpace(r.PostFormValue("tag")) | ||
| 86 | description := r.PostFormValue("description") | ||
| 87 | editing := r.PostFormValue("editing") == "1" | ||
| 88 | |||
| 89 | tags, err := m.Git().Tags() | ||
| 90 | if err != nil { | ||
| 91 | w.serverError(rw, r, "cannot list tags: "+err.Error()) | ||
| 92 | return | ||
| 93 | } | ||
| 94 | view := w.releasesView(r, m, tags) | ||
| 95 | view.ChannelForm = channelForm{Name: name, Tag: tag, Description: description, Editing: editing} | ||
| 96 | fail := func(msg string) { | ||
| 97 | view.ChannelForm.Error = msg | ||
| 98 | w.render(rw, "releases", view, http.StatusBadRequest) | ||
| 99 | } | ||
| 100 | |||
| 101 | if err := channel.ValidName(name); err != nil { | ||
| 102 | fail(err.Error()) | ||
| 103 | return | ||
| 104 | } | ||
| 105 | t, err := m.Git().Tag(tag) | ||
| 106 | if err != nil { | ||
| 107 | fail(fmt.Sprintf("No tag %q in this repository.", tag)) | ||
| 108 | return | ||
| 109 | } | ||
| 110 | if !t.Annotated { | ||
| 111 | fail(fmt.Sprintf("%s is a lightweight tag; a channel names an annotated release.", tag)) | ||
| 112 | return | ||
| 113 | } | ||
| 114 | if len(description) > channel.MaxDescription { | ||
| 115 | fail(fmt.Sprintf("The description is limited to %d bytes.", channel.MaxDescription)) | ||
| 116 | return | ||
| 117 | } | ||
| 118 | |||
| 119 | if err := w.auditBefore("web.channel.set", ctx.Name, m.Name, name+" -> "+tag); err != nil { | ||
| 120 | w.serverError(rw, r, "cannot record the channel move: "+err.Error()) | ||
| 121 | return | ||
| 122 | } | ||
| 123 | if err := w.ChannelStore.Set(m.ID, channel.Channel{ | ||
| 124 | Name: name, | ||
| 125 | Release: tag, | ||
| 126 | ReleaseObject: t.OID, | ||
| 127 | UpdatedBy: ctx.Name, | ||
| 128 | UpdatedAt: time.Now().UTC(), | ||
| 129 | Description: description, | ||
| 130 | }); err != nil { | ||
| 131 | w.serverError(rw, r, "cannot save the channel: "+err.Error()) | ||
| 132 | return | ||
| 133 | } | ||
| 134 | http.Redirect(rw, r, "/"+m.Name+"/releases#channels", http.StatusSeeOther) | ||
| 135 | } | ||
| 136 | |||
| 137 | // ClearChannel removes a channel from the browser. The release and its files are | ||
| 138 | // untouched; only the stable name stops resolving. | ||
| 139 | func (w *Web) ClearChannel(rw http.ResponseWriter, r *http.Request) { | ||
| 140 | ctx, ok := w.beginWrite(rw, r, maxTinyForm) | ||
| 141 | if !ok { | ||
| 142 | return | ||
| 143 | } | ||
| 144 | m := ctx.Repo | ||
| 145 | if !canMaintain(ctx.ACL, ctx.Name) { | ||
| 146 | w.notFound(rw, r) | ||
| 147 | return | ||
| 148 | } | ||
| 149 | if w.ChannelStore == nil { | ||
| 150 | w.serverError(rw, r, "the channel store is not available") | ||
| 151 | return | ||
| 152 | } | ||
| 153 | name := r.PathValue("channel") | ||
| 154 | if err := channel.ValidName(name); err != nil { | ||
| 155 | w.notFound(rw, r) | ||
| 156 | return | ||
| 157 | } | ||
| 158 | if _, found, err := w.ChannelStore.Get(m.ID, name); err != nil { | ||
| 159 | w.serverError(rw, r, "cannot read the channel: "+err.Error()) | ||
| 160 | return | ||
| 161 | } else if !found { | ||
| 162 | w.notFound(rw, r) | ||
| 163 | return | ||
| 164 | } | ||
| 165 | |||
| 166 | if err := w.auditBefore("web.channel.clear", ctx.Name, m.Name, name); err != nil { | ||
| 167 | w.serverError(rw, r, "cannot record the channel change: "+err.Error()) | ||
| 168 | return | ||
| 169 | } | ||
| 170 | if _, err := w.ChannelStore.Clear(m.ID, name); err != nil { | ||
| 171 | w.serverError(rw, r, "cannot clear the channel: "+err.Error()) | ||
| 172 | return | ||
| 173 | } | ||
| 174 | http.Redirect(rw, r, "/"+m.Name+"/releases#channels", http.StatusSeeOther) | ||
| 86 | 175 | } | |
| 87 | 176 | ||
| 88 | 177 | // ChannelView sends a stable channel URL to the release it currently names. The | |