gitoria
All repositories: gitoria
17.4 KB
// components/settings.hl — THE SETTINGS of a repo (gitoria#18): `/settings` on <slug>.<domain>. For now one section,// "Tickets": connect the repo to a tickets.worldapi.org project (the owner clicks "Tickets: connect", tickets asks which// project, and brings them back — lib/api.hl /settings/connect and /settings/connected; lib/tickets.hl). Anyone sees// whether the repo is connected; only the owner sees the buttons. Rendered on the server from the request's host.// "Apps" (gitoria#41, lib/apps.hl): the owner connects outside apps to the repo — the confirm card of connect flow A (an app sent the browser// here; lib/api.hl appConnectStart parked the request in the session), the list (Remove, Rotate secret) and Add (the manual way). Key and secret// are shown ONCE, in the page state of the click that made them.// (The main branch is switched on the code page.)parent './repo.hl'import { siteName } from '../project.hl'import { slugOfRequest } from '../lib/orgs.hl'import { userOfSession, userIdOfSession } from '../lib/users.hl'import { titleSlug, repoAt, ownsRepo, setTicketsConnection, setRepoPriv, membersOf, changeMember } from '../lib/repos.hl'import { px } from '../lib/util.hl'import { pageTitle } from '../lib/repos-helpers.hl'import { ticketsUrl } from '../lib/tickets-helpers.hl'import { appRows, addApp, removeApp, rotateSecret, sendPing } from '../lib/apps.hl'import { hostOfUrl } from '../lib/apps-helpers.hl'import { requiredList, requireContext, dropRequired } from '../lib/statuses.hl'host = nullorepo = ''session = nullslug = slugOfRequest(host, orepo)repo = repoAt(slug, session)hasRepo = repo != nullpre = px(slug)connectHref = pre + '/settings/connect'isOwner = repo != null && ownsRepo(slug, session)connected = repo != null && repo.ticketsOnnotConnected = repo != null && !repo.ticketsOnprojectTitle = repo != null ? repo.ticketsTitle : ''projectHref = repo != null && repo.ticketsOn ? ticketsUrl + '/projects/' + repo.ticketsProject : ''connectNote = session != null && session.data != null && session.data.connectNote != null ? session.data.connectNote : ''hasConnectNote = connectNote != ''notOwnerHint = repo != null && !isOwnersettingsError = ''forgetClass = repo != null && repo.ticketsOn ? 'quiet' : 'nomerge'__title = pageTitle(siteName, titleSlug(host, orepo, session), 'Settings')// VISIBILITY AND MEMBERS (GO34): the owner makes the repo private / public and keeps the member list (people who see a private repo and may push)isPrivate = repo != null && repo.isPrivateownPriv = repo != null && repo.isPrivate && !repo.inOrgprivText = repo == null ? '' : (repo.isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.')privButton = repo != null && repo.isPrivate ? 'Make public' : 'Make private'listed = isOwner ? membersOf('r', slug, userIdOfSession(session)) : nullmembers = listed != null && listed.members != null ? listed.members : []noMembers = isOwner && members.length == 0memberName = ''memberError = ''// APPS (gitoria#41): the owner's list; the connect request an app parked in this session (for this repo only); what was just made (shown once)apps = isOwner ? appRows(repo.id) : []noApps = isOwner && apps.length == 0parked = session != null && session.data != null && session.data.appConnect != null && repo != null && session.data.appConnect.slug == slug ? session.data.appConnect : nullhasParked = parked != nullparkedApp = parked != null ? parked.app : ''parkedHost = parked != null ? hostOfUrl(parked.ret) : ''parkedNonce = parked != null ? parked.nonce : ''confirmAction = pre + '/settings/apps/confirm'parkedSignedOut = hasParked && session != null && userIdOfSession(session) == nullparkedNotOwner = hasParked && userIdOfSession(session) != null && !isOwnerparkedOwner = hasParked && isOwner// the Apps section is the owner's; a signed-in non-owner who came to connect an app still gets its message (gitoria#45)showApps = isOwner || hasParkedappName = ''appHook = ''appError = ''hasShown = falseshownName = ''shownKey = ''hasShownKey = falseshownSecret = ''shownText = ''// REQUIRED BEFORE MERGE (gitoria#46): the contexts the owner requires to be success on a pull request's headrequired = isOwner ? requiredList(repo.id) : []noRequired = isOwner && required.length == 0requiredError = ''View {repoPage {if (hasRepo) {repoSettings { id = "settings"section { id = "visibility"h2 { "Visibility" }p { id = "privtext" privText }if (isOwner) { button { id = "togglepriv" type = "button" privButton on click(e) { emit togglePriv() } } }if (isOwner) {h2 { "Members" }p { class = "muted" "Members see this repository even when it is private, and may push to it. Add somebody by the display name they chose." }if (noMembers) { p { id = "nomembers" class = "empty" "No members yet." } }ul { id = "members"for (m of members) {li { span { class = "slug" m.name } button { class = "quiet" type = "button" "Remove" on click(e) { emit removeMember(m.name) } } }}}form { id = "memberform"on submit(e) {e.preventDefault()emit addMember(e)}label { "Display name"input { id = "membername" name = "membername" required = "required" maxlength = "60" autocomplete = "off" }}button { id = "memberadd" type = "submit" "Add member" }p { id = "membererror" class = "message" memberError }}}}if (showApps) {section { id = "apps"h2 { "Apps" }if (parkedSignedOut) { p { id = "appsignin" class = "message" "Sign in with the selector at the top to connect " + parkedApp + " to this repository." } }if (parkedNotOwner) { p { id = "appnotowner" class = "message" "Only the owner of this repository can connect " + parkedApp + "." } }if (parkedOwner) {form { id = "connectapp" method = "post" action = confirmActionp { id = "connectask" "Connect " + parkedApp + " to " + slug + "?" }p { class = "muted" "It will get read access to this repository and may review its pull requests. When you say Yes you go back to " + parkedHost + "." }input { name = "nonce" type = "hidden" value = parkedNonce }button { id = "connectyes" type = "submit" name = "decision" value = "yes" "Yes, connect" }button { id = "connectno" class = "quiet" type = "submit" name = "decision" value = "no" "No" }}}if (hasShown) {div { id = "appshown" class = "message"p { shownText }if (hasShownKey) { p { "Key: " code { id = "shownkey" shownKey } } }p { "Secret: " code { id = "shownsecret" shownSecret } }}}if (isOwner) {p { class = "muted" "An app is an outside program (for example a code reviewer) that works on this repository under its own name. Its key and secret are shown once." }if (noApps) { p { id = "noapps" class = "empty" "No apps connected." } }ul { id = "applist"for (a of apps) {li {span { class = "slug" a.name }span { class = "muted" a.host + " · added " + a.created + " · " + a.status }button { class = "quiet" type = "button" "Send ping" on click(e) { emit pingApp(a.id) } }button { class = "quiet" type = "button" "Rotate secret" on click(e) { emit rotateApp(a.id) } }button { class = "quiet" type = "button" "Remove" on click(e) { emit removeAppRow(a.id) } }}}}form { id = "appform"on submit(e) {e.preventDefault()emit addAppRow(e)}label { "App name"input { id = "appname" name = "appname" required = "required" maxlength = "60" autocomplete = "off" }}label { "Receiver address"input { id = "apphook" name = "apphook" type = "url" required = "required" maxlength = "500" autocomplete = "off" placeholder = "https://…" }}button { id = "appadd" type = "submit" "Add app" }p { id = "apperror" class = "message" appError }}}}}section { id = "required"if (isOwner) {h2 { "Required before merge" }p { class = "muted" "Name the status contexts an app must set to success on a pull request's current head before it can be merged. A push gives the pull request a new head, so the check starts again." }if (noRequired) { p { id = "norequired" class = "empty" "Nothing is required: every pull request can be merged." } }ul { id = "requiredlist"for (r of required) {li {span { class = "slug" r.name }button { class = "quiet" type = "button" "Remove" on click(e) { emit dropRequiredRow(r.id) } }}}}form { id = "requiredform"on submit(e) {e.preventDefault()emit addRequiredRow(e)}label { "Status context"input { id = "requiredcontext" name = "requiredcontext" required = "required" maxlength = "100" autocomplete = "off" }}button { id = "requiredadd" type = "submit" "Require it" }p { id = "requirederror" class = "message" requiredError }}}}section { id = "ticketsettings"h2 { "Tickets" }if (hasConnectNote) { p { id = "connectnote" class = "message" connectNote } }if (connected) {p { id = "connectedto" "Connected to the tickets project " a { id = "projectlink" href = projectHref projectTitle } "." }}if (notConnected) { p { id = "notconnected" class = "muted" "This repository is not connected to a tickets project yet." } }if (isOwner) {p {a { id = "connecttickets" class = "button" href = connectHref "Tickets: connect" }}button { id = "disconnecttickets" class = forgetClass type = "button" "Forget the connection" on click(e) { emit disconnect() } }p { class = "muted" "Connecting asks tickets which project (you must be its admin there). Tickets can also disconnect gitoria from its side." }}if (notOwnerHint) { p { id = "ownerhint" class = "muted" "Only the owner of this repository can connect it." } }p { id = "settingserror" class = "message" settingsError }}}}}}on togglePriv() {memberError = ''r = emit server gitoriaSetPrivate(slug, !isPrivate)if (r == null || r.error != null) {memberError = r != null ? r.error : 'could not change the visibility'return null}isPrivate = r.repo.isPrivateprivText = isPrivate ? 'This repository is private: only its owner and its members can see it.' : 'This repository is public: everybody can read it.'privButton = isPrivate ? 'Make public' : 'Make private'}on addMember(e) {memberError = ''r = emit server gitoriaChangeMember(slug, e.target.elements.membername.value, true)if (r == null || r.error != null) {memberError = r != null ? r.error : 'could not add the member'return null}members = r.membersnoMembers = members.length == 0e.target.elements.membername.value = ''}on removeMember(name) {memberError = ''r = emit server gitoriaChangeMember(slug, name, false)if (r == null || r.error != null) {memberError = r != null ? r.error : 'could not remove the member'return null}members = r.membersnoMembers = members.length == 0}on server gitoriaSetPrivate(slugOf, priv, session) {return setRepoPriv(userIdOfSession(session), slugOf, priv)}on addAppRow(e) {appError = ''r = emit server gitoriaAppAdd(slug, e.target.elements.appname.value, e.target.elements.apphook.value)if (r == null || r.error != null) {appError = r != null ? r.error : 'could not add the app'return null}apps = r.rowsnoApps = apps.length == 0hasShown = trueshownText = 'Connected ' + r.name + '. Copy the key and the secret now: they are not shown again.'shownKey = r.keyhasShownKey = trueshownSecret = r.secrete.target.elements.appname.value = ''e.target.elements.apphook.value = ''}on removeAppRow(id) {appError = ''r = emit server gitoriaAppRemove(slug, id)if (r == null || r.error != null) {appError = r != null ? r.error : 'could not remove the app'return null}apps = r.rowsnoApps = apps.length == 0hasShown = false}on pingApp(id) {appError = ''r = emit server gitoriaAppPing(slug, id)if (r == null || r.error != null) {appError = r != null ? r.error : 'could not send the ping'return null}appError = 'Ping to ' + r.name + ' is on its way. The status of the app shows the answer.'}on rotateApp(id) {appError = ''r = emit server gitoriaAppRotate(slug, id)if (r == null || r.error != null) {appError = r != null ? r.error : 'could not rotate the secret'return null}apps = r.rowshasShown = trueshownText = 'New secret for ' + r.name + '. Copy it now: it is not shown again. The old secret no longer signs anything.'shownKey = ''hasShownKey = falseshownSecret = r.secret}on addRequiredRow(e) {requiredError = ''r = emit server gitoriaRequiredAdd(slug, e.target.elements.requiredcontext.value)if (r == null || r.error != null) {requiredError = r != null ? r.error : 'could not save the setting'return null}required = r.rowsnoRequired = required.length == 0e.target.elements.requiredcontext.value = ''}on dropRequiredRow(id) {requiredError = ''r = emit server gitoriaRequiredRemove(slug, id)if (r == null || r.error != null) {requiredError = r != null ? r.error : 'could not save the setting'return null}required = r.rowsnoRequired = required.length == 0}on server gitoriaRequiredAdd(slugOf, ctxName, session) {return requireContext(userIdOfSession(session), session, slugOf, ctxName)}on server gitoriaRequiredRemove(slugOf, id, session) {return dropRequired(userIdOfSession(session), session, slugOf, id)}on server gitoriaAppAdd(slugOf, name, hook, session) {return addApp(userIdOfSession(session), session, slugOf, name, hook)}on server gitoriaAppRemove(slugOf, id, session) {return removeApp(userIdOfSession(session), session, slugOf, id)}on server gitoriaAppPing(slugOf, id, session) {return sendPing(userIdOfSession(session), session, slugOf, id)}on server gitoriaAppRotate(slugOf, id, session) {return rotateSecret(userIdOfSession(session), session, slugOf, id)}on server gitoriaChangeMember(slugOf, name, add, session) {return changeMember(userIdOfSession(session), 'r', slugOf, name, add)}on disconnect() {settingsError = ''r = emit server gitoriaDisconnectTickets(slug)if (r == null || r.error != null) {settingsError = r != null ? r.error : 'could not disconnect'return null}connected = falsenotConnected = trueforgetClass = 'nomerge'projectTitle = ''projectHref = ''}on server gitoriaDisconnectTickets(slugOf, session) {if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not disconnect' } }if (userOfSession(session) == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change this' } }r = setTicketsConnection(slugOf, '', '', '', '')if (r.error != null) { return { error = r.error } }return { ok = true }}Style {repoSettings {display = 'grid'gap = '1rem'minWidth = '0''> *' {margin = '0'}}#ticketsettings {display = 'grid'gap = '.75rem'justifyItems = 'start''> *' {margin = '0'}}'#disconnecttickets.nomerge' {display = 'none'}#connecttickets {color = 'var(--color-accent-text)'background = 'var(--color-accent)'}#members {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.25rem'maxWidth = '32rem'li {display = 'flex'alignItems = 'center'justifyContent = 'space-between'gap = '.75rem'minHeight = '2.75rem'padding = '0 .5rem 0 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}}#memberform {display = 'grid'gap = '.75rem'margin = '.75rem 0 1.5rem'maxWidth = '32rem'}#apps {display = 'grid'gap = '.75rem'margin = '0 0 1.5rem'justifyItems = 'start''> *' {margin = '0'}}#connectapp {display = 'grid'gap = '.75rem'maxWidth = '32rem'padding = '1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}#appshown {display = 'grid'gap = '.5rem'maxWidth = '100%'code {overflowWrap = 'anywhere'}}#applist {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.25rem'maxWidth = '40rem'width = '100%'li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.5rem .75rem'minHeight = '2.75rem'padding = '.25rem .5rem .25rem 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}}#required {display = 'grid'gap = '.75rem'margin = '0 0 1.5rem'justifyItems = 'start''> *' {margin = '0'}}#requiredlist {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.25rem'maxWidth = '40rem'width = '100%'li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'justifyContent = 'space-between'gap = '.5rem .75rem'minHeight = '2.75rem'padding = '.25rem .5rem .25rem 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}}#requiredform {display = 'grid'gap = '.75rem'maxWidth = '32rem'}#appform {display = 'grid'gap = '.75rem'maxWidth = '32rem'}#togglepriv {justifySelf = 'start'}#visibility {display = 'grid'gap = '.75rem'margin = '0 0 1.5rem'}}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 9f502db1gitoria#46: W46b briefmre
- 9678a8f3gitoria#46: contract v1.4, statuses keyed by app + contextmre
- bdcbbaa9gitoria#47: rate limits, status read route, statuses + required on the pull (merge w47-limits)mre
- 772c401fgitoria#45: W45 report, logmre
- b6b793afgitoria#45: PR page with reviews, threads, conversation, Review again (merge w45-pr-page)mre
- fb9e7554gitoria#45: browser gate: a /pulls title links to the PR pagemre
- f7198131gitoria#45: tests/pr-page.mjs gatemre
- 483141d0gitoria#45: Settings shows the Apps heading only to the ownermre
- e2eff8f6gitoria#45: the PR page /pulls/N with reviews, threads, verdicts, conversation, comment, reply, resolve and Review againmre
- 7a602839gitoria#45: raiseEvent can send to one app only; people's comments, replies and resolving in reviews.hlmre
- 5de7f578gitoria#47: rate limits per app (429, Retry-After), status read route, statuses and required on the pull, one JSON check for every write routemre
- 19edc1f5gitoria#44: contract v1.3.1, what outdated meansmre
- 7c2277ccgitoria#38: worker reports W40–W46, logmre
- 1c3fa842gitoria#45 #47: worker briefsmre
- 0a46bf7dgitoria#47: apps API contract v1.3 (status read route, statuses + required on the pull)mre
- 3373f7c3gitoria#38: push API contract v1.2.1, reviews, worker briefs and logmre
- 34143d2cgitoria#46: closing brace of appComments lost in the mergemre
- 54927c9cgitoria#46: PR statuses and required checks before merge (merge w46-status)mre
- 187e1871gitoria#46: badges without decorative bordersmre
- 6b022798gitoria#46: tests/status.mjs in GATESmre