gitoria
All repositories: gitoria
14.7 KB
// components/pull.hl — ONE PULL REQUEST (gitoria#45, part of the push API #38): `/pulls/N` on <slug>.<domain> and `/<repo>/pulls/N` in an organization.// A function route (lib/api.hl pullPage) renders it only for a PR the viewer may see, so an unknown number is a real 404. Everything comes from lib/prpage.hl// on the SERVER (first HTML and every navigation): the PR, its statuses on the current head, every app's current verdict, the reviews, the threads// (path:line, outdated / resolved marks) and the conversation. Bodies are Markdown as text nodes (components/markdown.hl). A viewer who may write (lib/prpage.hl// mayWritePull) gets the forms and the "Review again" buttons; the faces check it again, so a forged call is refused. Rows are keyed by the PR number and the// thread / comment ids the server gave, never by a position.parent './repo.hl'import Markdown from './markdown.hl'import PullReply from './pull-reply.hl'import { siteName } from '../project.hl'import { slugOfRequest } from '../lib/orgs.hl'import { userIdOfSession } from '../lib/users.hl'import { titleSlug, repoAt } from '../lib/repos.hl'import { pageTitle } from '../lib/repos-helpers.hl'import { px } from '../lib/util.hl'import { prOfRequest, prView, approvalStateFor, approveThePull, mergeThePull, commentOnPull, replyInThread, setThreadResolved, reviewAgain } from '../lib/prpage.hl'host = nullorepo = ''n = nullsession = nullviewerId = userIdOfSession(session)slug = slugOfRequest(host, orepo)repo = repoAt(slug, session)rec = repo != null ? prOfRequest(host, orepo, session, n) : nullv = rec != null ? prView(slug, rec, session) : nullhasPr = v != nullpr = v != null ? v.pr : nullstatuses = v != null ? v.statuses : []hasStatuses = v != null && v.hasStatusesverdicts = v != null ? v.verdicts : []hasVerdicts = v != null && v.hasVerdictsnoVerdicts = v != null && !v.hasVerdictsapps = v != null ? v.apps : []hasApps = v != null && v.hasAppsreviews = v != null ? v.reviews : []hasReviews = v != null && v.hasReviewsnoReviews = v != null && !v.hasReviewsthreads = v != null ? v.threads : []hasThreads = v != null && v.hasThreadsnoThreads = v != null && !v.hasThreadsconversation = v != null ? v.conversation : []hasConversation = v != null && v.hasConversationnoConversation = v != null && !v.hasConversationcanAct = v != null && v.canActmergeClass = v != null ? v.mergeClass : 'nomerge'approvals = v != null ? v.approvals : []approvalHead = v != null ? v.approvalHead : ''approvalLabel = v != null ? v.approvalLabel : 'Approve'approved = v != null && v.approvedcanApprove = v != null && v.canApproveblockText = v != null ? v.blockText : ''readOnly = v != null && v.readOnlycommentBody = ''actError = ''actNotice = ''listHref = px(slug) + '/pulls'titleRepo = repoAt(slugOfRequest(host, orepo), session)__title = pageTitle(siteName, titleSlug(host, orepo, session), 'Pull request ' + (n == null ? '' : '#' + n))View {repoPage {if (hasPr) {pullPage { id = "pullpage"p { a { id = "topulls" href = listHref "← Pull requests" } }h2 { id = "pulltitle"span { Style.spanNumber pr.numberText }for (pt of pr.parts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } }}p { id = "pullmeta"// Runtime row/state classes have no Style-rule selection form.span { id = "pullstate" class = pr.state pr.state }span { id = "pullbranches" strong { pr.source } " → " strong { pr.target } }span { class = "muted" "by " span { id = "pullauthor" pr.author } " · head " code { pr.head } }}if (hasStatuses) {ul { id = "pullstatuses"for (st of statuses) {// Runtime row/state classes have no Style-rule selection form.li { class = st.clsspan { class = "state" st.state }span { class = "label" st.label }span { class = "muted" st.title }}}}}h3 { "Verdicts" }if (hasVerdicts) {ul { id = "pullverdicts"for (vd of verdicts) {// Runtime row/state classes have no Style-rule selection form.li { class = vd.clsstrong { vd.app }span { vd.text }}}}}if (noVerdicts) { p { id = "noapps" class = "empty" "No app is connected to this repository." } }if (canAct) {div { id = "reviewagain"for (ap of apps) {button { class = "quiet" type = "button" value = ap.id "Review again: " ap.name on click(e) { emit askAgain(e.target.value) } }}}}// Runtime row/state classes have no Style-rule selection form.button { id = "mergepull" class = mergeClass type = "button" "Merge" on click(e) { emit mergeIt() } }p { id = "pullnotice" actNotice }p { id = "pullerror" actError }h3 { "People’s approvals" }ul { id = "personApprovals"for (a of approvals) {li { strong { a.name } span { a.words } code { a.head } time { a.created } }}}if (canApprove) { button { id = "approvePull" type = "button" approvalLabel on click(Hybrid e) { emit approveIt() } } }p { id = "mergeWait" blockText }h3 { "Reviews" }if (noReviews) { p { id = "noreviews" class = "empty" "No review yet." } }ol { id = "reviewlist"for (rv of reviews) {// Runtime row/state classes have no Style-rule selection form.li { class = rv.verdictp { Style.pHeadstrong { rv.app }span { Style.spanTag "app" }span { class = "verdict" rv.words }span { class = "muted" rv.head + " · " + rv.earlier + " · " + rv.created }}Markdown { blocks = rv.blocks }}}}h3 { "Threads" }if (noThreads) { p { id = "nothreads" class = "empty" "No inline comments yet." } }ol { id = "threadlist"for (th of threads) {// Runtime row/state classes have no Style-rule selection form.li { class = th.clsp { Style.pHeadcode { Style.codeWhere th.where }span { Style.spanMark th.mark }span { class = "muted" th.app }}ol { Style.olCommentsfor (c of th.comments) {// Runtime row/state classes have no Style-rule selection form.li { class = c.kindp { Style.pHeadstrong { c.author }span { class = "muted" c.created }}Markdown { blocks = c.blocks }}}}if (canAct) {PullReply { threadId = th.id toggleLabel = th.toggleLabel nextState = th.nextState sendReply = replyIt resolveThread = toggleThread }}}}}h3 { "Conversation" }if (noConversation) { p { id = "noconversation" class = "empty" "Nobody has written here yet." } }ol { id = "conversation"for (c of conversation) {// Runtime row/state classes have no Style-rule selection form.li { class = c.kindp { Style.pHeadstrong { c.author }if (c.isApp) { span { Style.spanTag "app" } }span { class = "muted" c.created }}Markdown { blocks = c.blocks }}}}if (canAct) {form { id = "commentform"on submit(e) {e.preventDefault()emit commentIt(e)}label { "Write a comment (Markdown)"textarea { id = "commentbody" name = "body" rows = "4" maxlength = "65536" required = "required" value = commentBody on input(e) { commentBody = e.target.value } }}button { id = "commentsave" type = "submit" "Comment" }}}if (readOnly) { p { id = "readonlyhint" class = "muted" "Only the owner and the members of this repository can comment here." } }}}}}// what a face answers is the page read again: every list is set from itapply = (r) => {if (r == null || r.error != null) {actError = r != null ? r.error : 'that did not work'return false}w = r.viewpr = w.prstatuses = w.statuseshasStatuses = w.hasStatusesverdicts = w.verdictshasVerdicts = w.hasVerdictsnoVerdicts = !w.hasVerdictsreviews = w.reviewshasReviews = w.hasReviewsnoReviews = !w.hasReviewsthreads = w.threadshasThreads = w.hasThreadsnoThreads = !w.hasThreadsconversation = w.conversationhasConversation = w.hasConversationnoConversation = !w.hasConversationmergeClass = w.mergeClassapprovals = w.approvalsapprovalHead = w.approvalHeadapprovalLabel = w.approvalLabelapproved = w.approvedcanApprove = w.canApproveblockText = w.blockTextactError = ''actNotice = r.notice != null ? r.notice : ''return true}on commentIt(e) {r = emit server gitoriaPrComment(slug, n, commentBody)if (apply(r)) { commentBody = '' }}replyIt = (threadId, body) => {r = emit server gitoriaPrReply(slug, n, threadId, body)return apply(r)}toggleThread = (threadId, resolved) => {r = emit server gitoriaPrResolve(slug, n, threadId, resolved)apply(r)}on client gitoriaPullApprovalChanged(String changedSlug, Number number, Hybrid state) {if (changedSlug != slug || pr == null || pr.number != number) { return null }applyApprovalState(state)}on client gitoriaStatusChanged(String changedSlug, String sha) {if (changedSlug != slug || pr == null || sha != approvalHead) { return null }state = emit server gitoriaPrApprovalState(slug, n)if (state != null) { applyApprovalState(state) }}on client gitoriaRequiredChanged(String changedSlug) {if (changedSlug != slug || pr == null) { return null }state = emit server gitoriaPrApprovalState(slug, n)if (state != null) { applyApprovalState(state) }}on server gitoriaPrApprovalState(String slugOf, String nText, Hybrid session) {return approvalStateFor(slugOf, nText, session)}applyApprovalState = (Hybrid state) => {if (state.head != approvalHead) {canApprove = falsemergeClass = 'nomerge'blockText = 'The head changed; read the pull request again before approving.'return null}if (state.statuses != null) {statuses = state.statuseshasStatuses = state.hasStatuses}approvals = state.approvalsapprovalHead = state.headblockText = state.blockTextapproved = falsefor (a of state.approvals) { if (a.userId == viewerId && a.sha == state.head) { approved = true } }approvalLabel = approved ? 'Withdraw approval' : 'Approve'mergeClass = canAct && pr.state == 'open' && blockText == '' ? 'mergepr' : 'nomerge'}on approveIt() {r = emit server gitoriaPrApprove(slug, n, approvalHead, !approved)apply(r)}on server gitoriaPrApprove(String slugOf, String nText, String head, Boolean wanted, session) { return approveThePull(slugOf, nText, session, head, wanted) }on mergeIt() {r = emit server gitoriaPrMerge(slug, n)apply(r)}on askAgain(appId) {r = emit server gitoriaPrAskAgain(slug, n, appId)apply(r)}on server gitoriaPrComment(slugOf, nText, body, session) { return commentOnPull(slugOf, nText, session, body) }on server gitoriaPrReply(slugOf, nText, threadId, body, session) { return replyInThread(slugOf, nText, session, threadId, body) }on server gitoriaPrResolve(slugOf, nText, threadId, resolved, session) { return setThreadResolved(slugOf, nText, session, threadId, resolved) }on server gitoriaPrMerge(slugOf, nText, session) { return mergeThePull(slugOf, nText, session) }on server gitoriaPrAskAgain(slugOf, nText, appId, session) { return reviewAgain(slugOf, nText, session, appId) }Style {#personApprovals {listStyle = 'none'margin = '0'padding = '0'li {display = 'flex'flexWrap = 'wrap'gap = '.25rem .6rem'}}pullPage {display = 'grid'gap = '1rem'minWidth = '0'overflowWrap = 'anywhere'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}// Runtime and theme class predicates have no bare selector form.'.nomerge' {display = 'none'}// Runtime and theme class predicates have no bare selector form.'.muted' {fontSize = '.875rem'}}#pullmeta {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.25rem .8rem'}#pullstatuses {display = 'flex'flexWrap = 'wrap'gap = '.25rem .5rem'margin = '0'padding = '0'listStyle = 'none'li {display = 'inline-flex'flexWrap = 'wrap'gap = '0 .4rem'padding = '.1rem .6rem'fontSize = '.8125rem'background = 'var(--color-background-sunken)'borderRadius = 'var(--radius-large)'}// Runtime and theme class predicates have no bare selector form.'.success' {color = 'var(--color-success)'}// Runtime and theme class predicates have no bare selector form.'.failure' {color = 'var(--color-danger)'}}#pullverdicts {display = 'grid'gap = '.25rem'margin = '0'padding = '0'listStyle = 'none'li {display = 'flex'flexWrap = 'wrap'gap = '0 .6rem'}// Runtime and theme class predicates have no bare selector form.'.approve' {color = 'var(--color-success)'}// Runtime and theme class predicates have no bare selector form.'.request_changes' {color = 'var(--color-danger)'}}#reviewagain {display = 'flex'flexWrap = 'wrap'gap = '.5rem'}#reviewlist {display = 'grid'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'li {padding = '.5rem 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}}#threadlist {display = 'grid'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'// Direct-child and sibling combinators have no bare language form.'> li' {padding = '.5rem 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}// Runtime and theme class predicates have no bare selector form.'.resolved' {opacity = '.75'}}#conversation {display = 'grid'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'li {padding = '.5rem 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}}#commentform {display = 'grid'gap = '.75rem'}spanNumber {marginRight = '.5rem'color = 'var(--color-text-muted)'fontWeight = '400'}spanTag {padding = '0 .4rem'fontSize = '.75rem'background = 'var(--color-background-sunken)'borderRadius = 'var(--radius-large)'}pHead {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.25rem .6rem'}spanMark {fontSize = '.875rem'color = 'var(--color-text-muted)'}olComments {display = 'grid'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'}codeWhere {fontWeight = '600'}#pullnotice {margin = '0'color = 'var(--color-success)'}#pullerror {margin = '0'color = 'var(--color-danger)'empty { display = 'none' }}}on client repoChanged(Hybrid row) {if (titleRepo != null && row.id == titleRepo.id) { __title = pageTitle(siteName, row.heading, 'Pull request ' + (n == null ? '' : '#' + n)) }}
Branches
Latest commits
- fe209ffeMerge branch 'w56-owner-members' into mainGitoria
- fa0754c8|||PR repository owner transfer and members API (#55)mre
- 8862e537Merge branch 'w55-rename-org' into mainGitoria
- 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
- 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
- 499f25f2Review fixes for the Settings organization move (#53)mre
- ed3b922b|||PR move a repository into an organization in Settings (#53)mre
- 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