gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5de7f5785de7f578gitoria#47: rate limits per app (429, Retry-After), status read route, statuses and required on the pull, one JSON check for every write routemre5de7f578/lib/api.hl

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

Branches

Latest commits

  • 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
  • 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
  • c6162f00gitoria#46: status badges on /pulls, Required before merge in Settingsmre
  • e5a0b64egitoria#46: PUT statuses/<sha>, required contexts block the merge on the servermre
  • 26a140e3gitoria#44: reviews, inline threads, replies, conversation for apps (merge w44-reviews)mre
  • 888dbf87gitoria#44: unknown API paths answer the contract's JSON 404 and sit above the page routesmre
  • ea587d90gitoria#44: reviews with inline threads, replies, resolve and the PR conversation for apps (lib/reviews.hl, tests/reviews.mjs)mre
  • 49533a50gitoria#43: signed events to connected apps (merge w43-events)mre
  • 1a1e87d5gitoria#43: the sender never writes the apps row; Settings shows the newest deliverymre
  • cd442066gitoria#43: app-auth unit test reads the apps table from its new filemre
  • 5dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre
  • 8c8805f3merge main (gitoria#42), delivery log and redelivery routes, sweep fixmre
  • 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
  • afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
  • 15e01e94gitoria#43: tests/events.mjs and its probemre