gitoria
All repositories: gitoria
11.6 KB
// components/codebrowser.hl — THE CODE BROWSER (ticket #9, gitoria#16), composed into the three code pages:// code.hl (/code, /code/<path>: the main branch), branch.hl (/branch/<name>[/<path>]), commit.hl// (/commit/<id>[/<path>]); `kind` ('code' | 'branch' | 'commit') and `rest` (the part after /<kind>/) come from the// page. Rendered on the SERVER with its content: the repo from the request's host, the tree / file / branches /// commits from git (lib/code.hl browseNow — hl:proc run() waits, hybriel#80) — in the first HTML and in every hl:web navigation.import { slugOfRequest } from '../lib/orgs.hl'import { userOfSession } from '../lib/users.hl'import { repoAt, ownsRepo } from '../lib/repos.hl'import { browseNow, makeMain } from '../lib/code.hl'import { withRefParts } from '../lib/tickets-helpers.hl'host = nullorepo = ''session = nullkind = 'code'rest = ''slug = slugOfRequest(host, orepo)repo = repoAt(slug, session)hasRepo = repo != nullcodeData = repo != null ? withRefParts(browseNow(slug, kind, rest, repo.branch, ownsRepo(slug, session)), repo.ticketsProject) : nullcodeShown = codeData != null && !codeData.isMessagecodeMessage = codeData != null && codeData.isMessagecodeText = codeData != null && codeData.isMessage ? codeData.message : ''codeError = ''View {codeView {if (hasRepo) {if (codeMessage) { p { id = "codemessage" class = "empty" codeText } }if (codeShown) {codeBrowser {codeHead {span { id = "codekind" class = "muted" codeData.kindLabel }strong { id = "coderef" codeData.refLabel }latestCommit {a { id = "commitlink" href = codeData.commitHref codeData.short }span { id = "commitsubject" for (pt of codeData.subjectParts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } } }span { class = "muted" codeData.author }time { codeData.date }}}pathCrumbs { id = "crumbs" class = "crumbs"for (c of codeData.crumbs) {if (c.linked) { a { href = c.href c.name } span { class = "muted" "/" } }if (c.last) { strong { c.name } }}}if (codeData.isTree) {if (codeData.noEntries) { p { id = "noentries" class = "empty" "This folder is empty." } }ul { id = "entries"for (e of codeData.entries) {li {if (e.isDir) { a { Style.aDir href = e.href e.name } }if (e.isFile) { a { class = "file" href = e.href e.name } }if (e.isOther) { span { Style.spanFile e.name } }span { class = "muted" e.size }}}}}if (codeData.isFile) {codeFile { id = "codefile"p { class = "muted" codeData.fileSize }if (codeData.binary) { p { id = "binary" class = "empty" "This file is not text (or not UTF-8) — not shown." } }if (codeData.tooBig) { p { id = "toobig" class = "empty" "This file is too large to show here." } }ol { id = "lines"for (ln of codeData.lines) { li { code { ln.text } } }}if (codeData.truncated) { p { id = "linestruncated" class = "muted" "Only the first lines are shown." } }}}codeSide {section { id = "branches"h2 { "Branches" }ul {for (b of codeData.branches) {li {if (b.isCurrent) { strong { b.name } }if (b.notCurrent) { a { href = b.href b.name } }if (b.isDefault) { span { class = "muted" "main branch" } }if (b.canSet) { button { class = "quiet setmain" type = "button" value = b.name "Make main" on click(e) { emit setMain(e.target.value) } } }}}}p { id = "codeerror" codeError }}section { id = "commits"h2 { "Latest commits" }ul {for (c of codeData.commits) {li {a { href = c.href c.short }span { for (pt of c.parts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } } }span { class = "muted" c.author }time { c.date }}}}}}}}}}}// "Make main" (the owner): the face answers with the same view, read again with the new main branchon setMain(name) {codeError = ''r = emit server gitoriaSetBranch(slug, name, kind, rest)if (r == null || r.error != null) {codeError = r != null ? r.error : 'could not change the main branch'return null}codeData = r.resultcodeShown = !r.result.isMessagecodeMessage = r.result.isMessagecodeText = r.result.isMessage ? r.result.message : ''}on server gitoriaSetBranch(slugOf, name, kindOf, restOf, session) {if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not change the main branch' } }if (kindOf != 'code' && kindOf != 'branch' && kindOf != 'commit') { return { error = 'could not change the main branch' } }if (restOf == null || hlTypeName(restOf) != 'String' || restOf.length > 500 || name == null || hlTypeName(name) != 'String') { return { error = 'could not change the main branch' } }u = userOfSession(session)if (u == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change the main branch' } }return makeMain(u.id, slugOf, name, kindOf, restOf)}Style {codeView {display = 'grid'gap = '1rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}codeBrowser {display = 'grid'gap = '1rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}@media {minWidth = '60rem'gridTemplateColumns = 'minmax(0, 1fr) 18rem'alignItems = 'start'columnGap = '2rem'// Direct-child and sibling combinators have no bare language form.'> *' {gridColumn = '1'}// Direct-child and sibling combinators have no bare language form.'> code-side' {gridColumn = '2'gridRow = '1 / span 4'}}}codeHead {display = 'grid'gap = '.3rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}codeFile {display = 'grid'gap = '.5rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}codeSide {display = 'grid'gap = '1rem'minWidth = '0'section {display = 'grid'gap = '.4rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '0 .8rem'margin = '0'padding = '0 .5rem'overflowWrap = 'anywhere'borderRadius = 'var(--radius-small)'// Direct-child and sibling combinators have no bare language form.'> a' {display = 'inline-flex'alignItems = 'center'minWidth = '2.75rem'minHeight = '2.75rem'firstChild {font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'}}// Direct-child and sibling combinators have no bare language form.'> strong' {display = 'inline-flex'alignItems = 'center'minWidth = '2.75rem'minHeight = '2.75rem'}}ul {display = 'grid'margin = '0'padding = '0'listStyle = 'none'}h2 {fontSize = '1.05rem'}// This selector condition takes arguments and has no bare form.'li:nth-child(odd)' {background = 'var(--color-background-sunken)'}}latestCommit {display = 'flex'flexWrap = 'wrap'gap = '0 .8rem'alignItems = 'center'minWidth = '0'padding = '.1rem .8rem .4rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'a {font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'}// Direct-child and sibling combinators have no bare language form.'> a' {firstChild {order = '1'}display = 'inline-flex'alignItems = 'center'minHeight = '2.75rem'}// Direct-child and sibling combinators have no bare language form.'> time' {order = '2'marginLeft = 'auto'}// This selector condition takes arguments and has no bare form.'> span:nth-child(2)' {order = '3'flex = '1 1 100%'minWidth = '0'paddingBlock = '.1rem'}// Direct-child and sibling combinators have no bare language form.'> span.muted' {order = '4'flex = '1 1 100%'fontSize = '.875rem'}}// This selector condition takes arguments and has no bare form.'path-crumbs:has(> strong:only-child)' {display = 'none'}#commits {li {// Direct-child and sibling combinators have no bare language form.'> a' {firstChild {order = '1'}}// Direct-child and sibling combinators have no bare language form.'> time' {order = '2'marginLeft = 'auto'}// This selector condition takes arguments and has no bare form.'> span:nth-child(2)' {order = '3'flex = '1 1 100%'minWidth = '0'paddingBlock = '.1rem'}// Direct-child and sibling combinators have no bare language form.'> span.muted' {order = '4'flex = '1 1 100%'fontSize = '.875rem'}}}pathCrumbs {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '0 .1rem'minWidth = '0'overflowWrap = 'anywhere'a {display = 'inline-flex'alignItems = 'center'justifyContent = 'center'minWidth = '2.75rem'minHeight = '2.75rem'padding = '0 .4rem'borderRadius = 'var(--radius-small)'hover {background = 'var(--color-surface)'}}}#entries {display = 'grid'margin = '0'padding = '0'listStyle = 'none'li {display = 'flex'alignItems = 'center'justifyContent = 'space-between'gap = '1rem'margin = '0'paddingRight = '.8rem'borderRadius = 'var(--radius-small)'// Direct-child and sibling combinators have no bare language form.'> a' {flex = '1 1 auto'display = 'flex'alignItems = 'center'minWidth = '0'minHeight = '2.75rem'padding = '0 .8rem'overflowWrap = 'anywhere'}// Direct-child and sibling combinators have no bare language form.'> span.muted' {flex = 'none'whiteSpace = 'nowrap'fontSize = '.875rem'}}// This selector condition takes arguments and has no bare form.'li:nth-child(odd)' {background = 'var(--color-background-sunken)'}// Pseudo-elements and parts have no bare language form.'a.dir::after' {content = '"/"'}}#lines {margin = '0'padding = '.5rem 0'overflowX = 'auto'listStyle = 'none'counterReset = 'line'background = 'var(--color-background-sunken)'borderRadius = 'var(--radius-large)'font = '.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'li {counterIncrement = 'line'whiteSpace = 'pre'minHeight = '1.5em'margin = '0'padding = '0 .8rem 0 0'width = 'max-content'minWidth = '100%'}// Pseudo-elements and parts have no bare language form.'li::before' {content = 'counter(line)'display = 'inline-block'width = '4ch'marginRight = '.8rem'paddingLeft = '.5rem'boxSizing = 'content-box'textAlign = 'right'color = 'var(--color-text-muted)'userSelect = 'none'}code {padding = '0'font = 'inherit'color = 'var(--color-text-strong)'background = 'transparent'}}aDir {fontWeight = '700'}spanFile {flex = '1 1 auto'display = 'flex'alignItems = 'center'minWidth = '0'minHeight = '2.75rem'padding = '0 .8rem'overflowWrap = 'anywhere'}#codeerror {margin = '0'color = 'var(--color-danger)'empty { display = 'none' }}}
Branches
Latest commits
- 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
- 9f7ce8d8Preserve rename compatibility and live page titlesmre
- c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
- ce08920dMerge branch 'w52c-header-phone' into mainGitoria
- 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
- e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
- c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
- 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
- 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
- 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
- 155861f6Merge branch 'w52-person-approval' into mainGitoria
- b5435de8|||PR person approvals: second Kunibert round (#52)mre
- 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre
- 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
- 83f0c953Report person approval verificationmre
- 3ae94b86Record browser failures and verify owned tab cleanupmre
- 54eec687Gate person approvals and merge alternativesmre
- 12b08829Add person approvals for pull request headsmre
- 55c84779Merge branch 'gp-gate-ports' into mainGitoria
- 57af42bbREADME: point to deploy.sh for the port listmre