| 1 | // Package server is de webinterface, de git-HTTP-server en de API. |
| 2 | package server |
| 3 | |
| 4 | import ( |
| 5 | "context" |
| 6 | "crypto/rand" |
| 7 | "embed" |
| 8 | "encoding/hex" |
| 9 | "fmt" |
| 10 | "gitlab.com/Timfa/bluegit/internal/langpick" |
| 11 | "gitlab.com/Timfa/bluegit/internal/readcache" |
| 12 | "gitlab.com/Timfa/bluegit/internal/runnercfg" |
| 13 | "html/template" |
| 14 | "io/fs" |
| 15 | "log/slog" |
| 16 | "net/http" |
| 17 | "net/url" |
| 18 | "strings" |
| 19 | "sync" |
| 20 | "time" |
| 21 | "unicode/utf8" |
| 22 | |
| 23 | "gitlab.com/Timfa/bluegit/internal/access" |
| 24 | "gitlab.com/Timfa/bluegit/internal/activity" |
| 25 | "gitlab.com/Timfa/bluegit/internal/auth" |
| 26 | "gitlab.com/Timfa/bluegit/internal/backup" |
| 27 | "gitlab.com/Timfa/bluegit/internal/card" |
| 28 | "gitlab.com/Timfa/bluegit/internal/cispec" |
| 29 | "gitlab.com/Timfa/bluegit/internal/config" |
| 30 | "gitlab.com/Timfa/bluegit/internal/gitgraph" |
| 31 | "gitlab.com/Timfa/bluegit/internal/i18n" |
| 32 | "gitlab.com/Timfa/bluegit/internal/realip" |
| 33 | "gitlab.com/Timfa/bluegit/internal/runner" |
| 34 | "gitlab.com/Timfa/bluegit/internal/store" |
| 35 | ) |
| 36 | |
| 37 | //go:embed templates/*.html static/*.css static/*.js static/*.svg static/*.ttf static/*.txt |
| 38 | var webFS embed.FS |
| 39 | |
| 40 | // Server bedient BlueGit. |
| 41 | type Server struct { |
| 42 | Cfg config.Config |
| 43 | Store *store.Store |
| 44 | Auth auth.Provider |
| 45 | Mail auth.Mailer |
| 46 | Dev bool |
| 47 | Git string |
| 48 | HookBin string |
| 49 | Runner *runner.Runner |
| 50 | Log *slog.Logger |
| 51 | // hookSink vangt de JSON-body af in tests, vóór het HTTP-verzoek. |
| 52 | hookSink func([]byte) |
| 53 | // StateDir is de map met database en het bestand storage_path. |
| 54 | StateDir string |
| 55 | // AfterStorage krijgt het nieuwe datadisk-pad, voor runner en SSH. |
| 56 | AfterStorage func(path string) |
| 57 | // UpdateStarter start bluegit-update.service. Nil gebruikt systemctl. |
| 58 | UpdateStarter UpdateStarter |
| 59 | updateHits updateLimiter |
| 60 | tmpl *template.Template |
| 61 | byLang map[string]*template.Template |
| 62 | |
| 63 | storageMu sync.RWMutex |
| 64 | storage string |
| 65 | storageSet bool |
| 66 | usageMu sync.Mutex |
| 67 | usage dirUsage |
| 68 | usageDone chan struct{} |
| 69 | cards *card.Cache |
| 70 | // mergingMR zijn merge requests die opMergeMR nu zelf afrondt. |
| 71 | // AfterPush mag hun bronbranch niet alvast verwijderen. |
| 72 | mergingMR sync.Map |
| 73 | |
| 74 | cacheMu sync.RWMutex |
| 75 | rcache *readcache.Cache |
| 76 | |
| 77 | graphOnce sync.Once |
| 78 | graphCache *gitgraph.Cache |
| 79 | |
| 80 | gitMaint gitMaintState |
| 81 | |
| 82 | // RequestRestart herstart het proces (main: opnieuw exec'en). Nodig na |
| 83 | // het uitpakken van een backup. Nil: alleen bij de volgende start. |
| 84 | RequestRestart func() |
| 85 | backupOnce sync.Once |
| 86 | backupMgr *backup.Manager |
| 87 | backupNote *backup.Notifier |
| 88 | backupHTTP *http.Client |
| 89 | restoring sync.Mutex |
| 90 | } |
| 91 | |
| 92 | type principal struct { |
| 93 | User store.User |
| 94 | Session store.Session |
| 95 | OK bool |
| 96 | } |
| 97 | |
| 98 | type ctxKey struct{} |
| 99 | |
| 100 | // Handler is de HTTP-handler met sessies en koppen. |
| 101 | func (s *Server) Handler() http.Handler { |
| 102 | s.mustTemplates() |
| 103 | mux := http.NewServeMux() |
| 104 | mux.HandleFunc("GET /assets/{file}", s.asset) |
| 105 | mux.HandleFunc("GET /-/info", s.infoPage) |
| 106 | mux.HandleFunc("GET /help", s.helpIndex) |
| 107 | mux.HandleFunc("GET /help/{doc}", s.helpPage) |
| 108 | s.mountRunnerAdmin(mux) |
| 109 | s.mountAdmin(mux) |
| 110 | mux.HandleFunc("POST /-/lang", s.switchLang) |
| 111 | mux.HandleFunc("GET /-/card.png", s.cardPNG) |
| 112 | mux.HandleFunc("GET /api/v1/oembed", s.oembed) |
| 113 | s.mountAPI(mux) |
| 114 | mux.HandleFunc("GET /api/v1/admin/self-update", s.selfUpdateStatus) |
| 115 | mux.HandleFunc("POST /api/v1/admin/self-update", s.selfUpdate) |
| 116 | mux.HandleFunc("GET /api/v1/webhooks/openapi.json", s.webhookSpec) |
| 117 | mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { |
| 118 | w.WriteHeader(http.StatusOK) |
| 119 | _, _ = w.Write([]byte("ok\n")) |
| 120 | }) |
| 121 | mux.HandleFunc("GET /login", s.login) |
| 122 | mux.HandleFunc("GET /auth/callback", s.callback) |
| 123 | mux.HandleFunc("POST /logout", s.logout) |
| 124 | mux.HandleFunc("GET /{$}", s.home) |
| 125 | mux.HandleFunc("GET /new", s.newPage) |
| 126 | mux.HandleFunc("GET /new/slug", s.slugPreview) |
| 127 | mux.HandleFunc("POST /new/repo", s.createRepo) |
| 128 | mux.HandleFunc("POST /new/group", s.createGroup) |
| 129 | mux.HandleFunc("GET /setup", s.setupPage) |
| 130 | mux.HandleFunc("POST /setup", s.setupSave) |
| 131 | mux.HandleFunc("POST /setup/cache", s.setupCacheSave) |
| 132 | mux.HandleFunc("POST /setup/cache/clear", s.setupCacheClear) |
| 133 | s.routeRunners(mux) |
| 134 | mux.HandleFunc("GET /settings", s.account) |
| 135 | mux.HandleFunc("POST /settings/language", s.saveLanguage) |
| 136 | mux.HandleFunc("POST /settings/profile", s.saveProfile) |
| 137 | mux.HandleFunc("POST /settings/tokens", s.createToken) |
| 138 | mux.HandleFunc("POST /settings/tokens/delete", s.deleteToken) |
| 139 | mux.HandleFunc("POST /settings/ssh", s.addSSH) |
| 140 | mux.HandleFunc("POST /settings/ssh/delete", s.deleteSSH) |
| 141 | mux.HandleFunc("GET /settings/export", s.export) |
| 142 | mux.HandleFunc("GET /users/{username}", s.profile) |
| 143 | mux.HandleFunc("GET /users/{username}/avatar", s.userAvatar) |
| 144 | mux.HandleFunc("GET /users/{username}/{$}", s.trimSlash) |
| 145 | mux.HandleFunc("GET /{name}", s.userShort) |
| 146 | mux.HandleFunc("GET /{name}/{$}", s.userShort) |
| 147 | mux.HandleFunc("GET /groups/{path}/{$}", s.trimSlash) |
| 148 | mux.HandleFunc("GET /groups/{path}", s.groupPage) |
| 149 | mux.HandleFunc("GET /groups/{path}/logo", s.groupLogo) |
| 150 | mux.HandleFunc("POST /groups/{path}/settings", s.saveGroup) |
| 151 | mux.HandleFunc("POST /groups/{path}/approvals", s.saveGroupApproval) |
| 152 | mux.HandleFunc("POST /groups/{path}/owner", s.transferGroup) |
| 153 | mux.HandleFunc("POST /groups/{path}/delete", s.deleteGroup) |
| 154 | mux.HandleFunc("POST /groups/{path}/logo", s.uploadGroupLogo) |
| 155 | mux.HandleFunc("POST /groups/{path}/members", s.groupMember) |
| 156 | mux.HandleFunc("POST /groups/{path}/members/remove", s.groupMemberRemove) |
| 157 | mux.HandleFunc("POST /groups/{path}/secrets", s.groupSecret) |
| 158 | mux.HandleFunc("POST /groups/{path}/secrets/reveal", s.groupSecretReveal) |
| 159 | mux.HandleFunc("POST /groups/{path}/secrets/delete", s.groupSecretDelete) |
| 160 | mux.HandleFunc("POST /groups/{path}/webhooks", s.groupWebhook) |
| 161 | mux.HandleFunc("POST /groups/{path}/webhooks/delete", s.groupWebhookDelete) |
| 162 | mux.HandleFunc("POST /groups/{path}/webhooks/copy", s.groupWebhookCopy) |
| 163 | |
| 164 | mux.HandleFunc("GET /{owner}/{repo}/info/refs", s.gitHTTP) |
| 165 | mux.HandleFunc("POST /{owner}/{repo}/git-upload-pack", s.gitHTTP) |
| 166 | mux.HandleFunc("POST /{owner}/{repo}/git-receive-pack", s.gitHTTP) |
| 167 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/releases", s.createRelease) |
| 168 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/jobs/{id}/log", s.jobLogAPI) |
| 169 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/commits/{sha}/diff", s.commitDiffAPI) |
| 170 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/merge-requests/{number}/diff", s.mrDiffAPI) |
| 171 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/issues", s.issuesAPI) |
| 172 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/issues", s.issuesAPI) |
| 173 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/issues/{number}", s.issueAPI) |
| 174 | mux.HandleFunc("PUT /api/v1/repos/{owner}/{repo}/issues/{number}", s.issueAPI) |
| 175 | mux.HandleFunc("DELETE /api/v1/repos/{owner}/{repo}/issues/{number}", s.issueAPI) |
| 176 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/issues/{number}/notes", s.issueNoteAPI) |
| 177 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/labels", s.labelsAPI) |
| 178 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/labels", s.labelsAPI) |
| 179 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/milestones", s.milestonesAPI) |
| 180 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/milestones", s.milestonesAPI) |
| 181 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/webhook-secrets", s.repoWebhookSecrets) |
| 182 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/webhooks", s.repoWebhookAPI) |
| 183 | mux.HandleFunc("PUT /api/v1/repos/{owner}/{repo}/webhooks/{id}", s.repoWebhookUpdate) |
| 184 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/secrets", s.repoSecretsAPI) |
| 185 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/secrets", s.repoSecretCreateAPI) |
| 186 | mux.HandleFunc("GET /api/v1/repos/{owner}/{repo}/secrets/{name}", s.repoSecretRevealAPI) |
| 187 | mux.HandleFunc("PUT /api/v1/repos/{owner}/{repo}/secrets/{name}", s.repoSecretUpdateAPI) |
| 188 | mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/secrets/{name}/replace", s.repoSecretReplaceAPI) |
| 189 | mux.HandleFunc("DELETE /api/v1/repos/{owner}/{repo}/secrets/{name}", s.repoSecretDeleteAPI) |
| 190 | mux.HandleFunc("GET /api/v1/groups/{path}/webhook-secrets", s.groupWebhookSecrets) |
| 191 | mux.HandleFunc("POST /api/v1/groups/{path}/hooks", s.groupWebhookAPI) |
| 192 | mux.HandleFunc("PUT /api/v1/groups/{path}/hooks/{id}", s.groupWebhookUpdate) |
| 193 | mux.HandleFunc("GET /api/v1/groups/{path}/secrets", s.groupSecretsAPI) |
| 194 | mux.HandleFunc("POST /api/v1/groups/{path}/secrets", s.groupSecretCreateAPI) |
| 195 | mux.HandleFunc("GET /api/v1/groups/{path}/secrets/{name}", s.groupSecretRevealAPI) |
| 196 | mux.HandleFunc("PUT /api/v1/groups/{path}/secrets/{name}", s.groupSecretUpdateAPI) |
| 197 | mux.HandleFunc("POST /api/v1/groups/{path}/secrets/{name}/replace", s.groupSecretReplaceAPI) |
| 198 | mux.HandleFunc("DELETE /api/v1/groups/{path}/secrets/{name}", s.groupSecretDeleteAPI) |
| 199 | mux.HandleFunc("GET /{owner}/{repo}", s.repoHome) |
| 200 | mux.HandleFunc("GET /{owner}/{repo}/{$}", s.repoRootAlias) |
| 201 | mux.HandleFunc("GET /{owner}/{repo}/-", s.repoRootAlias) |
| 202 | mux.HandleFunc("GET /{owner}/{repo}/-/{$}", s.repoRootAlias) |
| 203 | mux.HandleFunc("GET /{owner}/{repo}/-/tree", s.treeRoot) |
| 204 | mux.HandleFunc("GET /{owner}/{repo}/-/tree/{path...}", s.tree) |
| 205 | mux.HandleFunc("GET /{owner}/{repo}/-/blob/{path...}", s.blob) |
| 206 | mux.HandleFunc("GET /{owner}/{repo}/-/raw/{path...}", s.raw) |
| 207 | mux.HandleFunc("GET /{owner}/{repo}/-/commits", s.commits) |
| 208 | mux.HandleFunc("GET /{owner}/{repo}/-/tags", s.tags) |
| 209 | mux.HandleFunc("POST /{owner}/{repo}/-/tags", s.createTag) |
| 210 | mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag) |
| 211 | mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive) |
| 212 | mux.HandleFunc("GET /{owner}/{repo}/-/archive/{rev}/{file}", s.commitArchive) |
| 213 | mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit) |
| 214 | mux.HandleFunc("GET /{owner}/{repo}/-/branches/archive", s.branchArchive) |
| 215 | mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches) |
| 216 | mux.HandleFunc("POST /{owner}/{repo}/-/branches", s.createBranch) |
| 217 | mux.HandleFunc("POST /{owner}/{repo}/-/branches/delete", s.deleteBranch) |
| 218 | mux.HandleFunc("POST /{owner}/{repo}/-/branches/rename", s.renameBranch) |
| 219 | mux.HandleFunc("GET /{owner}/{repo}/-/compare", s.compare) |
| 220 | mux.HandleFunc("POST /{owner}/{repo}/-/markdown", s.previewMarkdown) |
| 221 | mux.HandleFunc("POST /{owner}/{repo}/-/tasks", s.toggleTask) |
| 222 | mux.HandleFunc("GET /{owner}/{repo}/-/merge-requests", s.mergeRequests) |
| 223 | mux.HandleFunc("GET /{owner}/{repo}/-/merge-requests/new", s.newMR) |
| 224 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests", s.createMR) |
| 225 | mux.HandleFunc("GET /{owner}/{repo}/-/merge-requests/{number}", s.showMR) |
| 226 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}", s.updateMR) |
| 227 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/merge", s.mergeMR) |
| 228 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/close", s.closeMR) |
| 229 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/reopen", s.reopenMR) |
| 230 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/reviews", s.postReview) |
| 231 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/reviews/dismiss", s.dismissReview) |
| 232 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/notes", s.createNote) |
| 233 | mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/suggestions", s.applySuggestions) |
| 234 | mux.HandleFunc("GET /{owner}/{repo}/-/issues", s.issuesPage) |
| 235 | mux.HandleFunc("GET /{owner}/{repo}/-/issues/new", s.newIssue) |
| 236 | mux.HandleFunc("POST /{owner}/{repo}/-/issues", s.createIssue) |
| 237 | mux.HandleFunc("POST /{owner}/{repo}/-/issues/labels", s.createIssueLabel) |
| 238 | mux.HandleFunc("POST /{owner}/{repo}/-/issues/milestones", s.createIssueMilestone) |
| 239 | mux.HandleFunc("GET /{owner}/{repo}/-/issues/{number}", s.showIssue) |
| 240 | mux.HandleFunc("POST /{owner}/{repo}/-/issues/{number}", s.postIssue) |
| 241 | mux.HandleFunc("GET /{owner}/{repo}/-/pipelines", s.pipelines) |
| 242 | mux.HandleFunc("POST /{owner}/{repo}/-/pipelines", s.runPipeline) |
| 243 | mux.HandleFunc("GET /{owner}/{repo}/-/pipelines/{id}", s.pipeline) |
| 244 | mux.HandleFunc("GET /{owner}/{repo}/-/pipelines/{id}/jobs/{job}", s.showJob) |
| 245 | mux.HandleFunc("GET /{owner}/{repo}/-/pipelines/{id}/jobs/{job}/log", s.jobLog) |
| 246 | mux.HandleFunc("POST /{owner}/{repo}/-/pipelines/{id}/jobs/{job}/play", s.playJob) |
| 247 | mux.HandleFunc("POST /{owner}/{repo}/-/pipelines/{id}/jobs/{job}/cancel", s.cancelJobWeb) |
| 248 | mux.HandleFunc("POST /{owner}/{repo}/-/pipelines/{id}/cancel", s.cancelPipelineWeb) |
| 249 | mux.HandleFunc("POST /{owner}/{repo}/-/pipelines/{id}/retry", s.retryPipeline) |
| 250 | mux.HandleFunc("GET /{owner}/{repo}/-/ci/editor", s.ciEditor) |
| 251 | mux.HandleFunc("POST /{owner}/{repo}/-/ci/editor", s.saveCIEditor) |
| 252 | mux.HandleFunc("POST /{owner}/{repo}/-/ci/lint", s.lintCI) |
| 253 | mux.HandleFunc("GET /{owner}/{repo}/-/releases", s.releases) |
| 254 | mux.HandleFunc("GET /{owner}/{repo}/-/releases/{$}", s.releasesSlash) |
| 255 | mux.HandleFunc("GET /{owner}/{repo}/-/releases/{tag}/assets/{name}", s.releaseAsset) |
| 256 | mux.HandleFunc("POST /{owner}/{repo}/-/releases/{tag}/assets/{name}/delete", s.uiDeleteReleaseAsset) |
| 257 | mux.HandleFunc("POST /{owner}/{repo}/-/releases/{tag}/delete", s.uiDeleteRelease) |
| 258 | mux.HandleFunc("GET /{owner}/{repo}/-/logo", s.repoLogo) |
| 259 | mux.HandleFunc("POST /{owner}/{repo}/-/logo", s.uploadRepoLogo) |
| 260 | mux.HandleFunc("POST /{owner}/{repo}/-/star", s.toggleStar) |
| 261 | mux.HandleFunc("POST /{owner}/{repo}/-/fork", s.forkPost) |
| 262 | mux.HandleFunc("POST /{owner}/{repo}/-/sync-upstream", s.syncUpstreamPost) |
| 263 | mux.HandleFunc("POST /{owner}/{repo}/-/upstream-merge-requests", s.forkMRPost) |
| 264 | mux.HandleFunc("GET /{owner}/{repo}/-/forks", s.forksPage) |
| 265 | mux.HandleFunc("GET /{owner}/{repo}/-/settings", s.settings) |
| 266 | mux.HandleFunc("POST /{owner}/{repo}/-/settings", s.updateRepo) |
| 267 | mux.HandleFunc("POST /{owner}/{repo}/-/approvals", s.saveRepoApproval) |
| 268 | mux.HandleFunc("POST /{owner}/{repo}/-/members", s.repoMember) |
| 269 | mux.HandleFunc("POST /{owner}/{repo}/-/members/remove", s.repoMemberRemove) |
| 270 | mux.HandleFunc("POST /{owner}/{repo}/-/protected", s.addProtected) |
| 271 | mux.HandleFunc("POST /{owner}/{repo}/-/protected/remove", s.removeProtected) |
| 272 | mux.HandleFunc("POST /{owner}/{repo}/-/protected-tags", s.addProtectedTag) |
| 273 | mux.HandleFunc("POST /{owner}/{repo}/-/protected-tags/remove", s.removeProtectedTag) |
| 274 | mux.HandleFunc("POST /{owner}/{repo}/-/secrets", s.repoSecret) |
| 275 | mux.HandleFunc("POST /{owner}/{repo}/-/secrets/reveal", s.repoSecretReveal) |
| 276 | mux.HandleFunc("POST /{owner}/{repo}/-/secrets/delete", s.repoSecretDelete) |
| 277 | mux.HandleFunc("POST /{owner}/{repo}/-/webhooks", s.repoWebhook) |
| 278 | mux.HandleFunc("POST /{owner}/{repo}/-/webhooks/delete", s.repoWebhookDelete) |
| 279 | mux.HandleFunc("POST /{owner}/{repo}/-/webhooks/copy", s.repoWebhookCopy) |
| 280 | mux.HandleFunc("POST /{owner}/{repo}/-/delete", s.deleteRepo) |
| 281 | |
| 282 | s.mountBackup(mux) |
| 283 | return s.realIP(s.withSession(s.secure(s.backupWatch(s.gate(mux))))) |
| 284 | } |
| 285 | |
| 286 | func (s *Server) realIP(next http.Handler) http.Handler { |
| 287 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 288 | realip.Apply(r, s.Cfg.ProxySet()) |
| 289 | next.ServeHTTP(w, r) |
| 290 | }) |
| 291 | } |
| 292 | |
| 293 | func (s *Server) mustTemplates() { |
| 294 | if s.byLang != nil { |
| 295 | return |
| 296 | } |
| 297 | s.byLang = map[string]*template.Template{} |
| 298 | for _, lang := range i18n.All() { |
| 299 | l := lang |
| 300 | s.byLang[string(l)] = template.Must(template.New("web").Funcs(template.FuncMap{ |
| 301 | "tip": func(key string) template.HTML { return runnercfg.Tip(l, key) }, |
| 302 | "admintabs": adminTabs, |
| 303 | "adminpage": isAdminPage, |
| 304 | "short": func(v string) string { |
| 305 | if len(v) > 10 { |
| 306 | return v[:10] |
| 307 | } |
| 308 | return v |
| 309 | }, |
| 310 | "join": strings.Join, |
| 311 | "initial": func(s string) string { |
| 312 | s = strings.TrimSpace(s) |
| 313 | if s == "" { |
| 314 | return "?" |
| 315 | } |
| 316 | r, _ := utf8.DecodeRuneInString(s) |
| 317 | return strings.ToUpper(string(r)) |
| 318 | }, |
| 319 | "tileHue": tileHue, |
| 320 | "splitPath": func(p string) []string { |
| 321 | if p == "" { |
| 322 | return nil |
| 323 | } |
| 324 | return strings.Split(p, "/") |
| 325 | }, |
| 326 | "iconOf": func(name string) string { return fileIcon(name, "blob") }, |
| 327 | "t": func(key string, args ...any) string { return i18n.T(l, key, args...) }, |
| 328 | "bgprotocol": backup.Protocol, |
| 329 | "bgminprotocol": backup.MinProtocol, |
| 330 | "date": func(t time.Time) string { return i18n.FormatDate(l, t) }, |
| 331 | "tn": func(n int, one, many string) string { |
| 332 | key := many |
| 333 | if n == 1 { |
| 334 | key = one |
| 335 | } |
| 336 | return i18n.T(l, key, n) |
| 337 | }, |
| 338 | "roleName": func(r access.Role) string { return i18n.T(l, "role."+string(r)) }, |
| 339 | "visName": func(v string) string { return i18n.T(l, "vis."+v) }, |
| 340 | "pushedLabel": func(r store.Repo) string { return pushedLabel(l, r) }, |
| 341 | "presetName": func(id string) string { |
| 342 | label := i18n.T(l, "set.preset."+id) |
| 343 | if label == "set.preset."+id { |
| 344 | return id |
| 345 | } |
| 346 | return label |
| 347 | }, |
| 348 | "printf": fmt.Sprintf, |
| 349 | "mb": func(n int64) float64 { return float64(n) / (1 << 20) }, |
| 350 | "dict": func(kv ...any) (map[string]any, error) { |
| 351 | if len(kv)%2 != 0 { |
| 352 | return nil, fmt.Errorf("dict") |
| 353 | } |
| 354 | m := make(map[string]any, len(kv)/2) |
| 355 | for i := 0; i < len(kv); i += 2 { |
| 356 | key, ok := kv[i].(string) |
| 357 | if !ok { |
| 358 | return nil, fmt.Errorf("dict") |
| 359 | } |
| 360 | m[key] = kv[i+1] |
| 361 | } |
| 362 | return m, nil |
| 363 | }, |
| 364 | }).ParseFS(webFS, "templates/*.html")) |
| 365 | } |
| 366 | s.tmpl = s.byLang[string(i18n.EN)] |
| 367 | } |
| 368 | |
| 369 | func (s *Server) asset(w http.ResponseWriter, r *http.Request) { |
| 370 | name := r.PathValue("file") |
| 371 | if name == "" || strings.Contains(name, "/") || strings.Contains(name, "..") { |
| 372 | http.NotFound(w, r) |
| 373 | return |
| 374 | } |
| 375 | sub, err := fs.Sub(webFS, "static") |
| 376 | if err != nil { |
| 377 | http.Error(w, "assets", http.StatusInternalServerError) |
| 378 | return |
| 379 | } |
| 380 | // CSS/JS moeten na een self-update niet uit een oude cache komen: |
| 381 | // een achtergebleven stylesheet zet de tekst over de lanes. |
| 382 | if strings.HasSuffix(name, ".css") || strings.HasSuffix(name, ".js") { |
| 383 | w.Header().Set("Cache-Control", "no-cache") |
| 384 | } |
| 385 | http.ServeFileFS(w, r, sub, name) |
| 386 | } |
| 387 | |
| 388 | func (s *Server) secure(next http.Handler) http.Handler { |
| 389 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 390 | w.Header().Set("X-Content-Type-Options", "nosniff") |
| 391 | w.Header().Set("X-Frame-Options", "DENY") |
| 392 | w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin") |
| 393 | w.Header().Set("Content-Security-Policy", "default-src 'self'; img-src 'self' https: data:; style-src 'self'; form-action 'self'; base-uri 'self'; frame-ancestors 'none'") |
| 394 | next.ServeHTTP(w, r) |
| 395 | }) |
| 396 | } |
| 397 | |
| 398 | func (s *Server) withSession(next http.Handler) http.Handler { |
| 399 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 400 | p := principal{} |
| 401 | if c, err := r.Cookie("bluegit_session"); err == nil && c.Value != "" { |
| 402 | sess, err := s.Store.Session(r.Context(), c.Value) |
| 403 | if err == nil && sess.ExpiresAt.After(time.Now()) { |
| 404 | p.Session = sess |
| 405 | p.User = sess.User |
| 406 | p.OK = true |
| 407 | s.maybeExtend(r.Context(), sess) |
| 408 | } |
| 409 | } |
| 410 | next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), ctxKey{}, p))) |
| 411 | }) |
| 412 | } |
| 413 | |
| 414 | func (s *Server) maybeExtend(ctx context.Context, sess store.Session) { |
| 415 | if time.Until(sess.ExpiresAt) > 6*time.Hour { |
| 416 | return |
| 417 | } |
| 418 | sec, err := s.Auth.Extend(ctx, sess.AccessToken) |
| 419 | if err != nil || sec <= 0 { |
| 420 | return |
| 421 | } |
| 422 | _ = s.Store.UpdateSessionExpiry(ctx, sess.ID, time.Now().Add(time.Duration(sec)*time.Second)) |
| 423 | } |
| 424 | |
| 425 | func (s *Server) who(r *http.Request) principal { |
| 426 | p, _ := r.Context().Value(ctxKey{}).(principal) |
| 427 | return p |
| 428 | } |
| 429 | |
| 430 | func (s *Server) csrfOK(w http.ResponseWriter, r *http.Request) bool { |
| 431 | if err := r.ParseForm(); err != nil { |
| 432 | http.Error(w, s.tr(r, "err.badForm"), http.StatusBadRequest) |
| 433 | return false |
| 434 | } |
| 435 | p := s.who(r) |
| 436 | if !p.OK || r.FormValue("csrf") == "" || r.FormValue("csrf") != p.Session.CSRF { |
| 437 | http.Error(w, s.tr(r, "err.badCSRF"), http.StatusBadRequest) |
| 438 | return false |
| 439 | } |
| 440 | return true |
| 441 | } |
| 442 | |
| 443 | func (s *Server) loginRequired(w http.ResponseWriter, r *http.Request) (store.User, bool) { |
| 444 | p := s.who(r) |
| 445 | if !p.OK { |
| 446 | http.Redirect(w, r, "/login", http.StatusFound) |
| 447 | return store.User{}, false |
| 448 | } |
| 449 | return p.User, true |
| 450 | } |
| 451 | |
| 452 | func (s *Server) setSessionCookie(w http.ResponseWriter, id string, exp time.Time) { |
| 453 | http.SetCookie(w, &http.Cookie{ |
| 454 | Name: "bluegit_session", |
| 455 | Value: id, |
| 456 | Path: "/", |
| 457 | HttpOnly: true, |
| 458 | SameSite: http.SameSiteLaxMode, |
| 459 | Secure: strings.HasPrefix(s.Cfg.BaseURL, "https://"), |
| 460 | Expires: exp, |
| 461 | }) |
| 462 | } |
| 463 | |
| 464 | func (s *Server) flash(w http.ResponseWriter, notice, problem string) { |
| 465 | secure := strings.HasPrefix(s.Cfg.BaseURL, "https://") |
| 466 | if notice != "" { |
| 467 | http.SetCookie(w, &http.Cookie{Name: "bluegit_notice", Value: url.QueryEscape(notice), Path: "/", MaxAge: 120, HttpOnly: true, Secure: secure, SameSite: http.SameSiteLaxMode}) |
| 468 | } |
| 469 | if problem != "" { |
| 470 | http.SetCookie(w, &http.Cookie{Name: "bluegit_error", Value: url.QueryEscape(problem), Path: "/", MaxAge: 120, HttpOnly: true, Secure: secure, SameSite: http.SameSiteLaxMode}) |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | func (s *Server) takeFlash(w http.ResponseWriter, r *http.Request) (string, string) { |
| 475 | notice, problem := flashVal(r, "bluegit_notice"), flashVal(r, "bluegit_error") |
| 476 | if notice != "" { |
| 477 | http.SetCookie(w, &http.Cookie{Name: "bluegit_notice", Value: "", Path: "/", MaxAge: -1}) |
| 478 | } |
| 479 | if problem != "" { |
| 480 | http.SetCookie(w, &http.Cookie{Name: "bluegit_error", Value: "", Path: "/", MaxAge: -1}) |
| 481 | } |
| 482 | return notice, problem |
| 483 | } |
| 484 | |
| 485 | func cookieVal(r *http.Request, name string) string { |
| 486 | c, err := r.Cookie(name) |
| 487 | if err != nil { |
| 488 | return "" |
| 489 | } |
| 490 | return c.Value |
| 491 | } |
| 492 | |
| 493 | func flashVal(r *http.Request, name string) string { |
| 494 | raw := cookieVal(r, name) |
| 495 | if raw == "" { |
| 496 | return "" |
| 497 | } |
| 498 | v, err := url.QueryUnescape(raw) |
| 499 | if err != nil { |
| 500 | return raw |
| 501 | } |
| 502 | return v |
| 503 | } |
| 504 | |
| 505 | func (s *Server) redirect(w http.ResponseWriter, r *http.Request, path, notice, problem string) { |
| 506 | s.flash(w, notice, problem) |
| 507 | http.Redirect(w, r, path, http.StatusSeeOther) |
| 508 | } |
| 509 | |
| 510 | func (s *Server) langOf(r *http.Request) i18n.Lang { |
| 511 | if p := s.who(r); p.OK { |
| 512 | return i18n.Parse(p.User.Language) |
| 513 | } |
| 514 | if c, err := r.Cookie("bluegit_lang"); err == nil { |
| 515 | return i18n.Parse(c.Value) |
| 516 | } |
| 517 | return i18n.EN |
| 518 | } |
| 519 | |
| 520 | // switchLang is de taalkiezer in de kopbalk: ingelogd slaat hij de taal op |
| 521 | // het account op, anoniem in een cookie. back is altijd een lokaal pad. |
| 522 | func (s *Server) switchLang(w http.ResponseWriter, r *http.Request) { |
| 523 | lang := i18n.Parse(r.FormValue("lang")) |
| 524 | back := langpick.SafeBack(r.FormValue("back")) |
| 525 | if p := s.who(r); p.OK { |
| 526 | if !s.csrfOK(w, r) { |
| 527 | return |
| 528 | } |
| 529 | if _, err := s.opSetLanguage(r.Context(), p.User, string(lang)); err != nil { |
| 530 | s.redirect(w, r, back, "", s.trErr(r, err)) |
| 531 | return |
| 532 | } |
| 533 | } else { |
| 534 | http.SetCookie(w, &http.Cookie{Name: "bluegit_lang", Value: string(lang), Path: "/", MaxAge: 365 * 86400, HttpOnly: true, SameSite: http.SameSiteLaxMode, Secure: strings.HasPrefix(s.Cfg.BaseURL, "https://")}) |
| 535 | } |
| 536 | http.Redirect(w, r, back, http.StatusSeeOther) |
| 537 | } |
| 538 | |
| 539 | func (s *Server) tr(r *http.Request, key string, args ...any) string { |
| 540 | return i18n.T(s.langOf(r), key, args...) |
| 541 | } |
| 542 | |
| 543 | func (s *Server) trErr(r *http.Request, err error) string { |
| 544 | return i18n.Text(s.langOf(r), err) |
| 545 | } |
| 546 | |
| 547 | func (s *Server) view(w http.ResponseWriter, r *http.Request, title string) View { |
| 548 | notice, problem := s.takeFlash(w, r) |
| 549 | lang := s.langOf(r) |
| 550 | if strings.HasPrefix(title, "title.") { |
| 551 | title = i18n.T(lang, title) |
| 552 | } |
| 553 | name := strings.TrimSpace(s.Cfg.Runner.Name) |
| 554 | if name == "" { |
| 555 | name = "Steve" |
| 556 | } |
| 557 | v := View{ |
| 558 | Title: title, BaseURL: s.Cfg.BaseURL, RunnerName: name, Notice: notice, Err: problem, |
| 559 | StorageUnset: s.StoragePath() == "", Lang: string(lang), HTMLLang: htmlLang(lang), |
| 560 | Cunei: lang == i18n.Cuneiform, |
| 561 | } |
| 562 | for _, l := range i18n.All() { |
| 563 | v.Langs = append(v.Langs, LangChoice{Code: string(l), Label: l.Name()}) |
| 564 | } |
| 565 | if p := s.who(r); p.OK && !isCrawler(r) { |
| 566 | u := p.User |
| 567 | v.User = &u |
| 568 | v.CSRF = p.Session.CSRF |
| 569 | } |
| 570 | back := r.URL.Path |
| 571 | if r.URL.RawQuery != "" { |
| 572 | back += "?" + r.URL.RawQuery |
| 573 | } |
| 574 | csrfField := "" |
| 575 | if v.User != nil { |
| 576 | csrfField = "csrf" |
| 577 | } |
| 578 | v.LangPick = langpick.HTML(lang, "/-/lang", back, csrfField, v.CSRF) |
| 579 | pic := s.cardForPath(r.Context(), r.URL.Path, r.URL.RawQuery, r.URL.Fragment) |
| 580 | v.Social = &pic.Meta |
| 581 | return v |
| 582 | } |
| 583 | |
| 584 | func htmlLang(l i18n.Lang) string { |
| 585 | switch l { |
| 586 | case i18n.NL: |
| 587 | return "nl" |
| 588 | case i18n.DE: |
| 589 | return "de" |
| 590 | case i18n.FR: |
| 591 | return "fr" |
| 592 | default: |
| 593 | return "en" |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | func (s *Server) render(w http.ResponseWriter, name string, v View) { |
| 598 | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 599 | tmpl := s.byLang[v.Lang] |
| 600 | if tmpl == nil { |
| 601 | tmpl = s.tmpl |
| 602 | } |
| 603 | if v.User != nil && v.User.InstanceAdmin { |
| 604 | v.BackupCompat = s.backupCompatIssues() |
| 605 | } |
| 606 | if err := tmpl.ExecuteTemplate(w, name, v); err != nil && s.Log != nil { |
| 607 | s.Log.Error("sjabloon", "name", name, "err", err) |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | func randomState() (string, error) { |
| 612 | b := make([]byte, 32) |
| 613 | if _, err := rand.Read(b); err != nil { |
| 614 | return "", err |
| 615 | } |
| 616 | return hex.EncodeToString(b), nil |
| 617 | } |
| 618 | |
| 619 | // View is de gegevensset voor elk scherm. |
| 620 | type View struct { |
| 621 | Backup *BackupView |
| 622 | BackupCompat []BackupCompatIssue |
| 623 | RunnerList []RunnerView |
| 624 | RunnerPref string |
| 625 | NewRunnerToken string |
| 626 | BuiltinFirst bool |
| 627 | RunnerOptIn bool |
| 628 | GroupRepoCount int |
| 629 | OptInNames []string |
| 630 | Title string |
| 631 | BaseURL string |
| 632 | RunnerName string |
| 633 | User *store.User |
| 634 | CSRF string |
| 635 | Notice string |
| 636 | Err string |
| 637 | Repos []store.Repo |
| 638 | Groups []store.Group |
| 639 | Repo *store.Repo |
| 640 | Role access.Role |
| 641 | CanWrite bool |
| 642 | CanAdmin bool |
| 643 | CanMerge bool |
| 644 | CanForce bool |
| 645 | CanComment bool |
| 646 | CanApply bool |
| 647 | Commits []CommitRow |
| 648 | CommitDays []CommitDay |
| 649 | CommitPrev string |
| 650 | CommitNext string |
| 651 | Commit *CommitRow |
| 652 | CommitDiff *CommitDiff |
| 653 | Entries []EntryRow |
| 654 | TreePath string |
| 655 | Blob string |
| 656 | BlobPath string |
| 657 | Binary bool |
| 658 | Branches []BranchRow |
| 659 | Branch *BranchBoard |
| 660 | MRs []store.MergeRequest |
| 661 | Flow *FlowBoard |
| 662 | MR *store.MergeRequest |
| 663 | Banner *MRBanner |
| 664 | MRPipe *PipeRow |
| 665 | MergeBlocks []string |
| 666 | Approval *ApprovalView |
| 667 | Reviews []ReviewRow |
| 668 | CanReview bool |
| 669 | CanApprove bool |
| 670 | CanDismiss bool |
| 671 | CanClose bool |
| 672 | CanReopen bool |
| 673 | IsOwner bool |
| 674 | Candidates []store.Member |
| 675 | Diff string |
| 676 | DiffFiles []DiffFileView |
| 677 | Pipes []store.Pipeline |
| 678 | PipeRows []PipeRow |
| 679 | Pipe *store.Pipeline |
| 680 | PipeSource string |
| 681 | PipeStatus string |
| 682 | PipeLabel string |
| 683 | PipeJobs []JobLink |
| 684 | PipeStages []StageView |
| 685 | PipeFailed bool |
| 686 | // PipeWait: waarom deze pipeline wacht (doNotInterrupt in een oudere pipeline). |
| 687 | PipeWait string |
| 688 | // PipeCancel: annuleerknop met bevestiging, nil als annuleren niet kan. |
| 689 | PipeCancel *CancelView |
| 690 | Live bool |
| 691 | LiveURL string |
| 692 | Jobs []store.Job |
| 693 | JobPage *JobPage |
| 694 | Editor *CIEditor |
| 695 | Releases []store.Release |
| 696 | Members []store.Member |
| 697 | Secrets []store.SecretMeta |
| 698 | Inherited []InheritedSecret |
| 699 | HookSecrets []SecretChoice |
| 700 | Hooks []HookView |
| 701 | HookTargets []HookTarget |
| 702 | HookEdit HookDraft |
| 703 | Patterns []string |
| 704 | TagPatterns []string |
| 705 | Tags []TagRow |
| 706 | Tokens []store.TokenInfo |
| 707 | ShowExpiry bool |
| 708 | Keys []store.SSHKey |
| 709 | CloneHTTP string |
| 710 | CloneSSH string |
| 711 | Group *store.Group |
| 712 | Tab string |
| 713 | Rev string |
| 714 | NewToken string |
| 715 | StorageUnset bool |
| 716 | StoragePath string |
| 717 | StorageFree string |
| 718 | StorageUsed string |
| 719 | StorageTotal string |
| 720 | StoragePercent int |
| 721 | StorageBlueGit string |
| 722 | StoragePartial bool |
| 723 | Cache map[string]any |
| 724 | StorageReserved string |
| 725 | HasReserved bool |
| 726 | MinFree string |
| 727 | Wide bool |
| 728 | Info bool |
| 729 | Help bool |
| 730 | HelpDocs []HelpDoc |
| 731 | HelpDoc *HelpDoc |
| 732 | RunnerUI template.HTML |
| 733 | AdminUsers []AdminUserRow |
| 734 | StaleDays int // Beheer > Pipelines: instance-instelling; repo-instellingen: eigen waarde (-1 = volgen) |
| 735 | StaleDaysDefault int |
| 736 | ReleaseOnly bool |
| 737 | ShowReleases bool |
| 738 | ReleaseRepos []store.Repo |
| 739 | LangPick template.HTML |
| 740 | ShowUpdate bool |
| 741 | Update *UpdateView |
| 742 | HookDoc string |
| 743 | Spec cispec.Doc |
| 744 | SpecJSON template.JS |
| 745 | APIJSON template.JS |
| 746 | Page string |
| 747 | Lang string |
| 748 | HTMLLang string |
| 749 | Cunei bool |
| 750 | Langs []LangChoice |
| 751 | Query string |
| 752 | SortDir string |
| 753 | SortBy string |
| 754 | MoreRepos int |
| 755 | MoreGroups int |
| 756 | DashTab string |
| 757 | DashPage int |
| 758 | DashPages int |
| 759 | DashPrev int |
| 760 | DashNext int |
| 761 | DashRepoN int |
| 762 | DashGroupN int |
| 763 | Fork ForkInfo |
| 764 | Stars int |
| 765 | Starred bool |
| 766 | ForkTargets []ForkTarget |
| 767 | ForkList []store.Repo |
| 768 | UpstreamBranches []string |
| 769 | FlipDir string |
| 770 | Cards []RepoCard |
| 771 | Head *CommitRow |
| 772 | Files []FileRow |
| 773 | Tree []FileRow |
| 774 | Readme template.HTML |
| 775 | MDView bool |
| 776 | ReadmeName string |
| 777 | LicensePath string |
| 778 | NCommits int |
| 779 | NBranches int |
| 780 | NTags int |
| 781 | NReleases int |
| 782 | Created string |
| 783 | Lines []CodeLine |
| 784 | BlobSize string |
| 785 | IsSVG bool |
| 786 | IsImage bool // rasterafbeelding met kloppende magic bytes |
| 787 | FileName string |
| 788 | RevProtected bool |
| 789 | Graph *GraphView |
| 790 | Heat *activity.Calendar |
| 791 | Notes []NoteRow |
| 792 | Profile *store.User |
| 793 | Card *ProfileCard |
| 794 | DescHTML template.HTML |
| 795 | Timeline []TimelineItem |
| 796 | CompareFrom string |
| 797 | CompareTo string |
| 798 | FormTitle string |
| 799 | Labels []string |
| 800 | CanEditMR bool |
| 801 | Issues *IssueBoard |
| 802 | IssueDoc string |
| 803 | DescTpls []string |
| 804 | TplPick string |
| 805 | FormBody string |
| 806 | Social *card.Meta |
| 807 | } |
| 808 | |
| 809 | // LangChoice is één taal in de instellingen. |
| 810 | type LangChoice struct { |
| 811 | Code, Label string |
| 812 | } |
| 813 | |
| 814 | // RepoCard is een repository in een groepslijst. |
| 815 | type RepoCard struct { |
| 816 | Repo store.Repo |
| 817 | Stars int |
| 818 | Starred bool |
| 819 | URL string |
| 820 | When string |
| 821 | Pushed string |
| 822 | } |
| 823 | |
| 824 | // AccountLink is een naam die naar een profiel wijst. |
| 825 | type AccountLink struct { |
| 826 | Name string |
| 827 | URL string |
| 828 | } |
| 829 | |
| 830 | // ProfileCard is het blok over een gebruiker, boven de activiteitenkalender. |
| 831 | type ProfileCard struct { |
| 832 | User store.User |
| 833 | Name, Since, Bio, URL string |
| 834 | Heading string |
| 835 | Repos, Groups, Contrib int |
| 836 | Own bool |
| 837 | } |
| 838 | |
| 839 | // NoteRow is een reactie in de interface. |
| 840 | type NoteRow struct { |
| 841 | ID int64 |
| 842 | Author, AuthorURL, Body, When, Path string |
| 843 | Start, End int |
| 844 | HasSuggestion bool |
| 845 | ParentID int64 |
| 846 | HTML template.HTML |
| 847 | Replies []NoteRow |
| 848 | At time.Time |
| 849 | } |
| 850 | |
| 851 | // DiffFileView is één bestand in de merge-request-diff. |
| 852 | type DiffFileView struct { |
| 853 | Path string |
| 854 | Lines []DiffLineView |
| 855 | } |
| 856 | |
| 857 | // DiffLineView is één diffregel, met de reacties die op het nieuwe regelnummer eindigen. |
| 858 | type DiffLineView struct { |
| 859 | Kind string |
| 860 | Text string |
| 861 | Old int |
| 862 | New int |
| 863 | Notes []NoteRow |
| 864 | } |
| 865 | |
| 866 | // TagRow is één tag op de tagspagina. |
| 867 | type TagRow struct { |
| 868 | Name, Message, SHA, Short, Subject, Date, When string |
| 869 | Annotated, Protected, HasRelease, CanDelete bool |
| 870 | ZipURL, TarURL string |
| 871 | } |
| 872 | |
| 873 | // FileRow is een rij in de bestandstabel of de boom. |
| 874 | type FileRow struct { |
| 875 | Name, Path, Icon, Subject, When, SHA string |
| 876 | Dir bool |
| 877 | Depth int |
| 878 | Active bool |
| 879 | // Open geldt voor een map die het huidige pad bevat. De browser |
| 880 | // onthoudt afwijkingen daarvan per repository. |
| 881 | Open bool |
| 882 | } |
| 883 | |
| 884 | // CodeLine is één regel broncode. |
| 885 | type CodeLine struct { |
| 886 | N int |
| 887 | HTML template.HTML |
| 888 | } |
| 889 | |
| 890 | // CommitRow is een commit in de interface. |
| 891 | // Author is de gekoppelde gebruiker, of anders de ruwe git-naam. |
| 892 | // RawName en PushedBy zijn gezet als de pusher de fallback is en de git-naam afwijkt. |
| 893 | type CommitRow struct { |
| 894 | SHA, Short, Author, Who, Date, Subject, Body, When string |
| 895 | UserURL, WhoURL, Avatar, Initial, RawName, PushedBy string |
| 896 | Ident template.HTML |
| 897 | PipeID int64 |
| 898 | PipeStatus, PipeLabel, PipeDuration string |
| 899 | PipeStages []StageView |
| 900 | PipeLive, PipeFailed bool |
| 901 | } |
| 902 | |
| 903 | // CommitDay is één dag op de commitlijst, nieuwste dag eerst. |
| 904 | type CommitDay struct { |
| 905 | Label string |
| 906 | Items []CommitRow |
| 907 | } |
| 908 | |
| 909 | // EntryRow is een bestand of map. |
| 910 | type EntryRow struct { |
| 911 | Name, Type, Path string |
| 912 | } |
| 913 | |
| 914 | // BranchRow is een branch, met of zonder bescherming. |
| 915 | type BranchRow struct { |
| 916 | Name, SHA, Short, Subject, When, WhenTitle string |
| 917 | RepoPath, ZipURL, TarURL string |
| 918 | Protected, Default, CanEdit bool |
| 919 | Target string |
| 920 | Ahead, Behind int |
| 921 | Unix int64 |
| 922 | PipeID int64 |
| 923 | PipeStatus, PipeLabel string |
| 924 | OpenMRs []int64 |
| 925 | } |
| 926 | |
| 927 | // BranchBoard is de gegroepeerde branches-pagina. |
| 928 | type BranchBoard struct { |
| 929 | State string |
| 930 | ShowActive, ShowStale bool |
| 931 | Active, Stale []BranchRow |
| 932 | } |
| 933 | |
| 934 | // TimelineItem is één gebeurtenis of reactie op een merge request. |
| 935 | type TimelineItem struct { |
| 936 | ID int64 |
| 937 | Kind string |
| 938 | Actor, ActorURL, Text string |
| 939 | When string |
| 940 | Body string |
| 941 | HTML template.HTML |
| 942 | URL string |
| 943 | Replies []TimelineItem |
| 944 | At time.Time |
| 945 | Rank int |
| 946 | } |
| 947 | |
| 948 | // HookView is een webhook plus de laatste pogingen. |
| 949 | type HookView struct { |
| 950 | ID int64 |
| 951 | Name string |
| 952 | Preset string |
| 953 | URL string |
| 954 | Method string |
| 955 | Filter string |
| 956 | Events string |
| 957 | Badges []string |
| 958 | Deliveries []store.Delivery |
| 959 | } |
| 960 | |
| 961 | // HookDraft vult het webhookformulier bij bewerken. ID 0 is een nieuw formulier. |
| 962 | type HookDraft struct { |
| 963 | ID int64 |
| 964 | Name string |
| 965 | Preset string |
| 966 | Filter string |
| 967 | URL string |
| 968 | Username string |
| 969 | Avatar string |
| 970 | Icon string |
| 971 | Alias string |
| 972 | Token string |
| 973 | Chat string |
| 974 | Server string |
| 975 | Topic string |
| 976 | Home string |
| 977 | Room string |
| 978 | Method string |
| 979 | CType string |
| 980 | Headers string |
| 981 | Body string |
| 982 | OnPush bool |
| 983 | OnMR bool |
| 984 | OnOK bool |
| 985 | OnFail bool |
| 986 | OnRel bool |
| 987 | OnIssue bool |
| 988 | Extra []HookEventChoice |
| 989 | } |
| 990 | |
| 991 | // HookEventChoice is een fijner event als vinkje in het webhookformulier. |
| 992 | type HookEventChoice struct { |
| 993 | Name string |
| 994 | Key string |
| 995 | On bool |
| 996 | } |
| 997 | |
| 998 | func repoURL(repo store.Repo) string { return "/" + repo.FullPath() } |