gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit54927c9c54927c9cgitoria#46: PR statuses and required checks before merge (merge w46-status)mre54927c9c/lib/api.hl

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

Branches

Latest commits

  • 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
  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • b5d696fegitoria#42: app tokens (gat_, one hour), appOfRequest, app token as the git read passwordmre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
  • 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre