gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2175e48c2175e48clogmre2175e48c/lib/api.hl

22.7 KB

  1. // lib/api.hl — THE FUNCTION ROUTES (project.hl wires them): thin wrappers — check the request and the session, call the
  2. // topic, answer. The plumbing (JSON / Markdown / plain answers, redirects, the ssh guard, `?next=`) is lib/api-helpers.hl.
  3. // /api/repos, /api/repos/:slug the public reads (repos.hl; Accept: text/markdown → the Markdown read view)
  4. // /login/callback the login button's return (users.hl)
  5. // /settings/connect, /settings/connected connecting a repo to a tickets project (tickets.hl)
  6. // /api/apps/token an app trades its key for a one-hour token (app-tokens.hl, gitoria#42)
  7. // /settings/apps/connect, /settings/apps/confirm, /api/apps/exchange connecting an app to a repo (apps.hl, gitoria#41)
  8. // /api/pulls… an app reads PRs, posts reviews with inline threads, replies, resolves, comments (reviews.hl, gitoria#44)
  9. // /__git/keys, /__git/access what the sshd container asks (sshkeys.hl, repos.hl)
  10. // (The git protocol's routes are lib/transport.hl gitTransport.)
  11. // A route that WRITES THE SESSION gets the request and the framework's session store BY REFERENCE (`&req`, `&sessions`,
  12. // from project.hl): copied into a second call, the session inside `req` would be a copy too and the write would be lost.
  13. import { Response } from 'hl:http1'
  14. import { randomBytes } from 'hl:crypto'
  15. import { NL, px, slugOfHost } from './util.hl'
  16. import { userOfLoginCode } from './users.hl'
  17. import { repoRows, repoRow, repoBySlug, repoFor, orgFor, ownsRepo, mayPush, mayRead } from './repos.hl'
  18. import { fullNameError, repoDocument, listDocument } from './repos-helpers.hl'
  19. import { forwardOf } from './forwards.hl'
  20. import { userIdOfSession } from './users.hl'
  21. import { connectHref, finishConnect } from './tickets.hl'
  22. import { keyLine } from './sshkeys.hl'
  23. import { urlAllowed, withQuery, formFields } from './apps-helpers.hl'
  24. import { nameError, makeCode, exchangeCode, appOfKey } from './apps.hl'
  25. import { issueToken } from './app-tokens.hl'
  26. import { bearerOf, unauthorized, notFound, tooMany, appOfRequest } from './app-auth.hl'
  27. import { answerOf, jsonOfRequest, reply, fail, apiError, wantsMarkdown, markdownReply, textReply, goTo, sshGuard, repoOfRequest, safeNext } from './api-helpers.hl'
  28. import { ensurePulls } from './pullsync.hl'
  29. import { prOfRequest } from './prpage.hl'
  30. import { listPulls, getPull, postReview, listReviews, listThreads, postReply, resolveThread, listComments, postComment } from './reviews.hl'
  31. import { putStatus, listStatuses } from './statuses.hl'
  32. import { limitCheck } from './limits.hl'
  33. import { syncAndRaise, deliveryPage, redeliver } from './events.hl'
  34. import { notifyPush } from './tickets.hl'
  35. // ---- the API: reads are public (creating a repo is a web action for now) ------------------------
  36. static apiRepos = (route, req) => {
  37. if (req.method != 'GET') { return fail(405, 'GET only') }
  38. rows = repoRows(userIdOfSession(req.session))
  39. if (wantsMarkdown(req)) { return markdownReply(listDocument(rows)) }
  40. return reply(200, { repos = rows })
  41. }
  42. static apiRepo = (route, req) => {
  43. if (req.method != 'GET') { return fail(405, 'GET only') }
  44. row = repoRow(route.params.slug, userIdOfSession(req.session))
  45. if (row == null) { return fail(404, 'no such repository') }
  46. if (wantsMarkdown(req)) { return markdownReply(repoDocument(row)) }
  47. return reply(200, row)
  48. }
  49. // ---- NOTHING ELSE (mission MG, as ident's notFoundPage): the last route of project.hl answers a path no route knows with the
  50. // shell's 404 page (components/notfound.hl) — status 404, the page rendered by the framework with the request's session and host
  51. static notFoundPage = (route, req, &srv, pageComponent) => {
  52. m = { route = { pattern = route.route.pattern component = pageComponent } kind = 'component' params = { path = req.path } path = req.path }
  53. res = srv.page(m, req.session, srv.hostOf(req.headers['host']), srv.requestHeaders(req.headers))
  54. res.status = 404
  55. return res
  56. }
  57. // `/:orepo` (GO34): on an organization's address (one the viewer may see) the first segment is a repo's Readme page, rendered like the 404 page is (a function route:
  58. // a stray single-segment path on any other address keeps its real 404 status — /.env, /host.js, a private organization's /x)
  59. static orgRepoPage = (route, req, &srv, pageComponent, missingComponent) => {
  60. h = req.headers['host']
  61. label = slugOfHost(h == null ? '' : h.split(':')[0])
  62. if (label == '' || orgFor(label, userIdOfSession(req.session)) == null) { return notFoundPage(route, req, &srv, missingComponent) }
  63. m = { route = { pattern = route.route.pattern component = pageComponent } kind = 'component' params = { orepo = req.path.slice(1) } path = req.path }
  64. return srv.page(m, req.session, srv.hostOf(h), srv.requestHeaders(req.headers))
  65. }
  66. // `/pulls/:n` and `/:orepo/pulls/:n` (gitoria#45): the PR's page when the repo is visible to the viewer and the number is one of its pull requests, else the
  67. // shell's 404 page (a function route, so the status is a real 404 for an unknown number)
  68. static pullPage = (route, req, &srv, pageComponent, missingComponent) => {
  69. h = req.headers['host']
  70. host = h == null ? '' : h.split(':')[0]
  71. orepo = route.params.orepo != null ? route.params.orepo : ''
  72. nText = route.params.n
  73. if (prOfRequest(host, orepo, req.session, nText) == null) { return notFoundPage(route, req, &srv, missingComponent) }
  74. m = { route = { pattern = route.route.pattern component = pageComponent } kind = 'component' params = { orepo = orepo n = nText } path = req.path }
  75. return srv.page(m, req.session, srv.hostOf(h), srv.requestHeaders(req.headers))
  76. }
  77. // any other /api path: the contract's JSON 404 (docs/apps-api.md §6)
  78. static notFoundApi = (route, req) => { return apiError(404, 'not_found', 'no such endpoint', null) }
  79. // ---- THE LOGIN BUTTON'S RETURN (ident README "How apps use ident") ----------------------------
  80. // ident sends the browser back with ?ident_code= (and our ?next=); the code is exchanged here (users.hl userOfLoginCode),
  81. // the user goes into THIS browser's session (`req.session`, the cookie's — hybriel #11; minted when it brought none),
  82. // then → `?next=` (api-helpers.hl safeNext). A FAILED LOGIN is a page (components/loginfailed.hl): the reason is parked
  83. // in the session, then → /login/failed.
  84. static loginFailed = (&req, &sessions, why) => {
  85. let s = req.session
  86. fresh = s == null
  87. if (fresh) { s = sessions.mint() }
  88. s.data.loginError = why
  89. sessions.save(s)
  90. res = new Response('login failed: ' + why, { status = 302 headers = { 'Location' = '/login/failed' 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } })
  91. if (fresh) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id) }
  92. return res
  93. }
  94. static loginCallback = (route, &req, &sessions) => {
  95. if (req.method != 'GET') { return loginFailed(&req, &sessions, 'GET only') }
  96. q = req.query != null ? req.query : {}
  97. code = q.ident_code
  98. if (code == null || code == '') { return loginFailed(&req, &sessions, 'ident sent no login code') }
  99. x = userOfLoginCode(code)
  100. if (x.error != null) { return loginFailed(&req, &sessions, x.error) }
  101. // THE SAME SESSION, NEVER SIGNED OUT (ident#28): a good code signs the session the browser already has in (a second tab or an installed
  102. // app may not store a new cookie, and a session we signed out would leave it anonymous); none yet → minted here
  103. let s = req.session
  104. if (s == null) { s = sessions.mint() }
  105. s.user = { id = x.user.id }
  106. s.data.tag = randomBytes(16)
  107. s.data.loginError = null
  108. sessions.save(s)
  109. res = new Response('logged in', { status = 302 headers = { 'Location' = safeNext(q.next) 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' 'Set-Cookie' = sessions.cookieHeader(s.id) } })
  110. return res
  111. }
  112. // ---- ONE LOGIN FOR THE MAIN ADDRESS AND EVERY REPO ADDRESS ---------------------------------------------------------------------
  113. // Nothing here: hl:web (batch 20) does it. The session cookie carries `Domain=.<host>` (project.hl sessionDomain); among several gitoriasid
  114. // cookies the signed-in one wins and is re-issued with the Domain (the stray host-only copy expires), and a signed-in cookie is re-issued when its
  115. // attributes change (a login from before the Domain was set moves to it on its next request) and otherwise once a day. Gate: tests/browser.mjs "gitoria#24".
  116. // ---- CONNECT A REPO TO A TICKETS PROJECT (gitoria#18; tickets.hl, components/settings.hl) ----------------------------
  117. // /settings/connect: the owner's click → a fresh nonce parked in the session (bound to the repo) → tickets' /connect.
  118. // /settings/connected: tickets' return with ?code&state → tickets.hl finishConnect (nonce, exchange, key stored per
  119. // repo) → back to /settings. A failure is a note on the settings page.
  120. static connectStart = (route, &req, &sessions) => {
  121. if (req.method != 'GET') { return fail(405, 'GET only') }
  122. repo = repoOfRequest(route, req)
  123. if (repo == null) { return fail(404, 'no such repository') }
  124. s = req.session
  125. if (s == null || !ownsRepo(repo.slug, s)) { return goTo(px(repo.slug) + '/settings') }
  126. nonce = randomBytes(16)
  127. s.data.connectState = repo.slug + '.' + nonce
  128. s.data.connectNote = null
  129. sessions.save(s)
  130. return goTo(connectHref(repo.slug, nonce))
  131. }
  132. // One log line for every end of the connect flow (docker logs of the gitoria container): "connect-back <slug> <outcome> ..." and
  133. // never the code, the state value or a key. `state` only says whether tickets brought one.
  134. static connectLog = (slug, outcome, hasState) => {
  135. console.log('connect-back ' + slug + ' ' + outcome + ' state=' + (hasState ? 'present' : 'absent'))
  136. }
  137. static notSignedInNote = 'The connection to tickets did not finish: this browser is not signed in to gitoria as the repo owner. Sign in and press Connect again.'
  138. static connectBack = (route, &req, &sessions) => {
  139. if (req.method != 'GET') { return fail(405, 'GET only') }
  140. repo = repoOfRequest(route, req)
  141. if (repo == null) { return fail(404, 'no such repository') }
  142. q = req.query != null ? req.query : {}
  143. hasState = q.state != null
  144. let s = req.session
  145. if (s == null || userIdOfSession(s) == null || !ownsRepo(repo.slug, s)) {
  146. // nothing is exchanged; the code is dropped. The browser is told why on the settings page: a session-less browser gets a fresh
  147. // session that carries the note (like loginFailed), a session that exists keeps itself and gets the note
  148. why = s == null ? 'no-session' : (userIdOfSession(s) == null ? 'session-not-signed-in' : 'not-owner')
  149. connectLog(repo.slug, 'refused reason=' + why, hasState)
  150. fresh = s == null
  151. if (fresh) { s = sessions.mint() }
  152. s.data.connectNote = notSignedInNote
  153. sessions.save(s)
  154. res = goTo(px(repo.slug) + '/settings')
  155. if (fresh) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id) }
  156. return res
  157. }
  158. want = s.data.connectState
  159. s.data.connectState = null
  160. note = finishConnect(repo.slug, want, q)
  161. s.data.connectNote = note == '' ? null : note
  162. sessions.save(s)
  163. if (note == '') {
  164. connectLog(repo.slug, 'connected', hasState)
  165. } else if (q.error != null && q.code == null) {
  166. connectLog(repo.slug, 'tickets-error', hasState)
  167. } else if (want == null || want != repo.slug + '.' + q.state) {
  168. connectLog(repo.slug, 'state-mismatch', hasState)
  169. } else {
  170. connectLog(repo.slug, 'exchange-failed', hasState)
  171. }
  172. return goTo(px(repo.slug) + '/settings')
  173. }
  174. // ---- WHAT THE SSHD CONTAINER ASKS (ticket gitoria#7; docker/sshd) — only with the shared secret (api-helpers.hl sshGuard)
  175. // GET /__git/keys?type=<ssh-ed25519>&key=<base64> sshd AuthorizedKeysCommand: the authorized_keys line for a known key
  176. // (sshkeys.hl keyLine), empty for an unknown one
  177. // GET /__git/access?user=<id>&slug=<slug>&write=0|1 gitoria-shell before it starts git: `ok` or 403. Read = every repo (public);
  178. // write = the repo's owner only (repos.hl mayPush — the same rule as the token on HTTPS, transport.hl)
  179. static gitKeys = (route, req) => {
  180. no = sshGuard(req)
  181. if (no != null) { return no }
  182. q = req.query != null ? req.query : {}
  183. return textReply(200, keyLine(q.type, q.key))
  184. }
  185. // GET /__git/pushed?user=<id>&slug=<slug>&phase=before|after gitoria-shell around a push over ssh (what transport.hl does for HTTPS):
  186. // before → the repo's existing pull requests are numbered (ensurePulls); after (git exited 0) → notifyPush + syncPulls for that user. `ok`; never an error for the push.
  187. static gitPushed = (route, req) => {
  188. no = sshGuard(req)
  189. if (no != null) { return no }
  190. q = req.query != null ? req.query : {}
  191. slug = q.slug
  192. if (slug == null || hlTypeName(slug) != 'String' || fullNameError(slug) != null) { return textReply(404, 'no such repository' + NL) }
  193. let repo = repoBySlug(slug)
  194. if (repo == null && forwardOf(slug) != null) { repo = repoBySlug(forwardOf(slug)) }
  195. if (repo == null || !mayPush(q.user, repo)) { return textReply(403, 'not allowed' + NL) }
  196. if (q.phase == 'before') { ensurePulls(repo.slug) }
  197. else if (q.phase == 'after') {
  198. notifyPush(repo.slug, false)
  199. syncAndRaise(repo.slug, q.user)
  200. } else { return textReply(400, 'phase is before or after' + NL) }
  201. return textReply(200, 'ok' + NL)
  202. }
  203. static gitAccess = (route, req) => {
  204. no = sshGuard(req)
  205. if (no != null) { return no }
  206. q = req.query != null ? req.query : {}
  207. slug = q.slug
  208. if (slug == null || hlTypeName(slug) != 'String' || fullNameError(slug) != null) { return textReply(404, 'no such repository' + NL) }
  209. let repo = repoBySlug(slug)
  210. if (repo == null && forwardOf(slug) != null) { repo = repoBySlug(forwardOf(slug)) }
  211. // the asker is the key's user: a repo they may not see does not exist for them (404, as over HTTPS)
  212. if (repo == null || !mayRead(q.user, repo)) { return textReply(404, 'no such repository' + NL) }
  213. if (q.write == '1' && !mayPush(q.user, repo)) { return textReply(403, 'only the owner or a member of this repository can push to it' + NL) }
  214. // the sshd container runs git in the repo's real folder: tell it the name (it differs after a move)
  215. return textReply(200, 'ok ' + repo.slug + NL)
  216. }
  217. // ---- CONNECT AN APP TO A REPO (gitoria#41; apps.hl, docs/apps-api.md §1 flow A) ----------------------------------------------------
  218. // /settings/apps/connect?app&hook&return&state: the app sends the owner's browser here. The four values are checked (the URL allow-list:
  219. // anything else is 400 invalid_url) and PARKED in the session with a nonce; then → the repo's settings page, which asks the person to sign in
  220. // (the same session goes on after the login) and, for the owner, shows "Connect <app> to <repo>?" with a Yes / No form.
  221. // /settings/apps/confirm (POST): the form's answer → the owner check, the nonce, a one-time code → redirect to return?code&state (No: return?error=denied&state).
  222. static appConnectStart = (route, &req, &sessions) => {
  223. if (req.method != 'GET') { return apiError(405, 'invalid', 'GET only', null) }
  224. repo = repoOfRequest(route, req)
  225. if (repo == null) { return apiError(404, 'not_found', 'no such repository', null) }
  226. q = req.query != null ? req.query : {}
  227. if (!urlAllowed(q.hook)) { return apiError(400, 'invalid_url', 'hook is not an allowed receiver address', { field = 'hook' }) }
  228. if (!urlAllowed(q['return'])) { return apiError(400, 'invalid_url', 'return is not an allowed address', { field = 'return' }) }
  229. bad = nameError(q.app)
  230. if (bad != null) { return apiError(422, 'invalid', bad, { field = 'app' }) }
  231. if (q.state == null || hlTypeName(q.state) != 'String' || q.state.length == 0 || q.state.length > 200) { return apiError(422, 'invalid', 'state is missing or too long', { field = 'state' }) }
  232. let s = req.session
  233. fresh = s == null
  234. if (fresh) { s = sessions.mint() }
  235. s.data.appConnect = { slug = repo.slug app = ('' + q.app).trim() hook = q.hook ret = q['return'] state = q.state nonce = randomBytes(16) }
  236. sessions.save(s)
  237. res = goTo(px(repo.slug) + '/settings')
  238. if (fresh) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id) }
  239. return res
  240. }
  241. static appConnectConfirm = (route, &req, &sessions) => {
  242. if (req.method != 'POST') { return apiError(405, 'invalid', 'POST only', null) }
  243. repo = repoOfRequest(route, req)
  244. if (repo == null) { return apiError(404, 'not_found', 'no such repository', null) }
  245. home = px(repo.slug) + '/settings'
  246. let s = req.session
  247. if (s == null || userIdOfSession(s) == null || !ownsRepo(repo.slug, s)) { return goTo(home) }
  248. p = s.data.appConnect
  249. f = formFields(req.body)
  250. if (p == null || p.slug != repo.slug || f.nonce == null || f.nonce != p.nonce) { return goTo(home) }
  251. // one try: the parked request goes whatever the answer is
  252. s.data.appConnect = null
  253. sessions.save(s)
  254. if (f.decision != 'yes') { return goTo(withQuery(p.ret, { error = 'denied' state = p.state })) }
  255. code = makeCode(repo, p.app, p.hook, userIdOfSession(s))
  256. if (code == null) { return goTo(home) }
  257. return goTo(withQuery(p.ret, { code = code state = p.state }))
  258. }
  259. // POST /api/apps/exchange {"code"} (no auth): the app's server trades the code → { key, secret, api, repo, app } (apps.hl exchangeCode)
  260. static appExchange = (route, req) => {
  261. if (req.method != 'POST') { return apiError(405, 'invalid', 'POST only', null) }
  262. repo = repoOfRequest(route, req)
  263. if (repo == null) { return apiError(404, 'not_found', 'no such repository', null) }
  264. j = jsonOfRequest(req)
  265. if (j.error != null) { return j.error }
  266. x = exchangeCode(repo, j.json.code)
  267. if (x.notFound == true) { return apiError(404, 'not_found', 'unknown, used or expired code', null) }
  268. return reply(200, x.body)
  269. }
  270. // POST {api}/apps/token Authorization: Bearer gak_… → 200 { token, expires } (app-tokens.hl); the key must be the key of the repo the address names
  271. static appToken = (route, req) => {
  272. if (req.method != 'POST') { return apiError(405, 'invalid', 'POST only', null) }
  273. app = appOfKey(bearerOf(req))
  274. if (app == null) { return unauthorized() }
  275. repo = repoOfRequest(route, req)
  276. if (repo == null || repo.id != app.repo) { return notFound() }
  277. wait = limitCheck(app.id, req.method)
  278. if (wait > 0) { return tooMany(wait) }
  279. t = issueToken(app)
  280. if (t.error != null) { return apiError(500, 'internal', 'could not make a token', null) }
  281. return reply(200, { token = t.token expires = t.expires })
  282. }
  283. // GET {api}/deliveries?cursor=&limit= → { deliveries: [{ id, event, action, time, status, tries, lastCode }], next } — the app's OWN deliveries (events.hl)
  284. static appDeliveries = (route, req) => {
  285. if (req.method != 'GET') { return apiError(405, 'invalid', 'GET only', null) }
  286. who = appOfRequest(route, req)
  287. if (who.error != null) { return who.error }
  288. q = req.query != null ? req.query : {}
  289. return reply(200, deliveryPage(who.app.id, q.cursor, q.limit == null ? null : toNumber(q.limit)))
  290. }
  291. // POST {api}/deliveries/:id/redeliver → 202; the same delivery id goes out again. Another app's delivery (or none) is a 404, like any foreign thing
  292. static appRedeliver = (route, req) => {
  293. if (req.method != 'POST') { return apiError(405, 'invalid', 'POST only', null) }
  294. who = appOfRequest(route, req)
  295. if (who.error != null) { return who.error }
  296. if (!redeliver(who.app.id, route.params.id)) { return apiError(404, 'not_found', 'no such delivery', null) }
  297. return reply(202, { accepted = true })
  298. }
  299. // ---- the apps API's PR routes (gitoria#44; lib/reviews.hl does the work, these only check the method and the app, and answer)
  300. // GET {api}/pulls?state=&cursor=&limit=
  301. static appPulls = (route, req) => {
  302. if (req.method != 'GET') { return apiError(405, 'invalid', 'GET only', null) }
  303. who = appOfRequest(route, req)
  304. if (who.error != null) { return who.error }
  305. return answerOf(listPulls(who.repo, req.query))
  306. }
  307. // GET {api}/pulls/N
  308. static appPull = (route, req) => {
  309. if (req.method != 'GET') { return apiError(405, 'invalid', 'GET only', null) }
  310. who = appOfRequest(route, req)
  311. if (who.error != null) { return who.error }
  312. return answerOf(getPull(who.repo, route.params.n))
  313. }
  314. // GET / POST {api}/pulls/N/reviews
  315. static appReviews = (route, req) => {
  316. if (req.method != 'GET' && req.method != 'POST') { return apiError(405, 'invalid', 'GET or POST only', null) }
  317. who = appOfRequest(route, req)
  318. if (who.error != null) { return who.error }
  319. if (req.method == 'GET') { return answerOf(listReviews(who.app, who.repo, route.params.n, req.query)) }
  320. j = jsonOfRequest(req)
  321. if (j.error != null) { return j.error }
  322. return answerOf(postReview(who.app, who.repo, route.params.n, j.json))
  323. }
  324. // GET {api}/pulls/N/threads
  325. static appThreads = (route, req) => {
  326. if (req.method != 'GET') { return apiError(405, 'invalid', 'GET only', null) }
  327. who = appOfRequest(route, req)
  328. if (who.error != null) { return who.error }
  329. return answerOf(listThreads(who.app, who.repo, route.params.n, req.query))
  330. }
  331. // POST {api}/pulls/N/threads/:id/replies
  332. static appReply = (route, req) => {
  333. if (req.method != 'POST') { return apiError(405, 'invalid', 'POST only', null) }
  334. who = appOfRequest(route, req)
  335. if (who.error != null) { return who.error }
  336. j = jsonOfRequest(req)
  337. if (j.error != null) { return j.error }
  338. return answerOf(postReply(who.app, who.repo, route.params.n, route.params.id, j.json))
  339. }
  340. // POST {api}/pulls/N/threads/:id/resolve
  341. static appResolve = (route, req) => {
  342. if (req.method != 'POST') { return apiError(405, 'invalid', 'POST only', null) }
  343. who = appOfRequest(route, req)
  344. if (who.error != null) { return who.error }
  345. j = jsonOfRequest(req)
  346. if (j.error != null) { return j.error }
  347. return answerOf(resolveThread(who.app, who.repo, route.params.n, route.params.id, j.json))
  348. }
  349. // GET / POST {api}/pulls/N/comments (the PR's conversation)
  350. static appComments = (route, req) => {
  351. if (req.method != 'GET' && req.method != 'POST') { return apiError(405, 'invalid', 'GET or POST only', null) }
  352. who = appOfRequest(route, req)
  353. if (who.error != null) { return who.error }
  354. if (req.method == 'GET') { return answerOf(listComments(who.repo, route.params.n, req.query)) }
  355. j = jsonOfRequest(req)
  356. if (j.error != null) { return j.error }
  357. return answerOf(postComment(who.app, who.repo, route.params.n, j.json))
  358. }
  359. // PUT {api}/statuses/<sha> {"context","state","title","summary","url"} → 200 { status } (statuses.hl): the app sets the state of a commit, a newer PUT replaces the older one
  360. static appStatus = (route, req) => {
  361. if (req.method != 'PUT' && req.method != 'GET') { return apiError(405, 'invalid', 'GET or PUT only', null) }
  362. who = appOfRequest(route, req)
  363. if (who.error != null) { return who.error }
  364. // GET (v1.3): every context on that sha, from every app; a sha this repo does not have is 404 not_found (§6 shape)
  365. if (req.method == 'GET') {
  366. l = listStatuses(who.repo, route.params.sha)
  367. if (l.unknown == true) { return apiError(404, 'not_found', 'that sha is not a commit of this repository', null) }
  368. return reply(200, { statuses = l.statuses })
  369. }
  370. j = jsonOfRequest(req)
  371. if (j.error != null) { return j.error }
  372. r = putStatus(who.repo, who.app, route.params.sha, j.json)
  373. if (r.invalid != null) { return apiError(422, 'invalid', 'the status is not valid', r.invalid) }
  374. if (r.unknown == true) { return apiError(422, 'invalid', 'that sha is not a commit of this repository', [{ field = 'sha' reason = 'no_such_commit' }]) }
  375. return reply(200, { status = r.status })
  376. }

Branches

Latest commits

  • 2175e48clogmre
  • 40eb3ca1gitoria#38: review package, logmre
  • 06a5a50egitoria#38: deploy b8252ca, logmre
  • b8252ca0gitoria#46: W46b report, logmre
  • 50093aafgitoria#46: statuses keyed by app + context (merge w46b-keyed)mre
  • dd0267edgitoria#46: fix a label in the keyed gatemre
  • b1dcb580gitoria#46: statuses keyed by app + context, required = app + context, old rows still readmre
  • 2287363egitoria#47: W47 report, logmre
  • 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