gitoria
All repositories: gitoria
10.8 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 { siteName } from '../project.hl'import { slugOfRequest } from '../lib/orgs.hl'import { titleSlug, repoAt } from '../lib/repos.hl'import { pageTitle } from '../lib/repos-helpers.hl'import { px } from '../lib/util.hl'import { prOfRequest, prView, mergeThePull, commentOnPull, replyInThread, setThreadResolved, reviewAgain } from '../lib/prpage.hl'host = nullorepo = ''n = nullsession = nullslug = 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'readOnly = v != null && v.readOnlyactError = ''actNotice = ''listHref = px(slug) + '/pulls'__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 { class = "number" 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"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) {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) {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) } }}}}button { id = "mergepull" class = mergeClass type = "button" "Merge" on click(e) { emit mergeIt() } }p { id = "pullnotice" class = "notice" actNotice }p { id = "pullerror" class = "message" actError }h3 { "Reviews" }if (noReviews) { p { id = "noreviews" class = "empty" "No review yet." } }ol { id = "reviewlist"for (rv of reviews) {li { class = rv.verdictp { class = "head"strong { rv.app }span { class = "tag" "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) {li { class = th.clsp { class = "head"code { class = "where" th.where }span { class = "mark" th.mark }span { class = "muted" th.app }}ol { class = "comments"for (c of th.comments) {li { class = c.kindp { class = "head"strong { c.author }span { class = "muted" c.created }}Markdown { blocks = c.blocks }}}}if (canAct) {form { class = "replyform"on submit(e) {e.preventDefault()emit replyIt(e, th.id)}label { "Reply"textarea { name = "body" rows = "3" maxlength = "65536" required = "required" }}button { type = "submit" "Reply" }button { class = "quiet" type = "button" th.toggleLabel on click(e) { emit toggleThread(th.id, th.nextState) } }}}}}}h3 { "Conversation" }if (noConversation) { p { id = "noconversation" class = "empty" "Nobody has written here yet." } }ol { id = "conversation"for (c of conversation) {li { class = c.kindp { class = "head"strong { c.author }if (c.isApp) { span { class = "tag" "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" }}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.mergeClassactError = ''actNotice = r.notice != null ? r.notice : ''return true}on commentIt(e) {f = e.target.elementsr = emit server gitoriaPrComment(slug, n, f.body.value)if (apply(r)) { f.body.value = '' }}on replyIt(e, threadId) {f = e.target.elementsr = emit server gitoriaPrReply(slug, n, threadId, f.body.value)if (apply(r)) { f.body.value = '' }}on toggleThread(threadId, resolved) {r = emit server gitoriaPrResolve(slug, n, threadId, resolved)apply(r)}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 {pullPage {display = 'grid'gap = '1rem'minWidth = '0'overflowWrap = 'anywhere''> *' {margin = '0'}'.nomerge' {display = 'none'}'.number' {marginRight = '.5rem'color = 'var(--color-text-muted)'fontWeight = '400'}'.muted' {fontSize = '.875rem'}'.tag' {padding = '0 .4rem'fontSize = '.75rem'background = 'var(--color-background-sunken)'borderRadius = 'var(--radius-large)'}'.head' {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.25rem .6rem'}'.mark' {fontSize = '.875rem'color = 'var(--color-text-muted)'}}#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)'}'.success' {color = 'var(--color-success)'}'.failure' {color = 'var(--color-danger)'}}#pullverdicts {display = 'grid'gap = '.25rem'margin = '0'padding = '0'listStyle = 'none'li {display = 'flex'flexWrap = 'wrap'gap = '0 .6rem'}'.approve' {color = 'var(--color-success)'}'.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''> li' {padding = '.5rem 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}'.resolved' {opacity = '.75'}'.comments' {display = 'grid'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'}'.where' {fontWeight = '600'}}#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'}'.replyform' {display = 'grid'gap = '.5rem'justifyItems = 'start'}}
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
- 65d5f80alogmre
- dab74b0dW49 report, logmre
- fd4fc028Exercise member status reads with a populated check statemre
- 536ca6f9Allow repository members to read pull workflow APIs with user tokensmre
- 705dd834W49 missionmre
- b554cd5flogmre
- f4c9440ddeploy.sh: tar --hard-dereference for the live data backupmre
- 1a687b15Merge branch 'w48-member-merge'mre
- 166c775fW48 report, logmre
- 1b4623f0Members merge pull requests: API route, button on /pulls and /pulls/N, one shared merge pathmre
- 1075c38cW48 mission, logmre
- 17bdd0d6V37/V39 missions, logmre
- 146de5f8Re-vendor gitoria to Hybriel set-day39 (51e921d7)mre
- e874e44dtests/status-keyed: app token lives 60 s so it outlives the gate's two restartsmre
- 270b8d61deploy.sh: DEPLOY_STOP_START=1 stops, waits for the old pid, then starts (mpackdb freeze, replaces the standby swap)mre
- 3f9235b8project.hl: drop the dummy /pulls/:n component route (hybriel#294 is fixed in day37)mre
- c90daf19Re-vendor gitoria to Hybriel set-day37 (f6b3d45b)mre
- 03b5bb08W39 report to reports/, drop scratch repro, mission + logmre
- 154d333fMerge w39-create-api: POST /api/repos with a user token (#39)mre
- 149dd512Rewrite W39 reportmre