gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfb9e7554fb9e7554gitoria#45: browser gate: a /pulls title links to the PR pagemrefb9e7554/login.js

3.0 KB

  1. // login.js — the small bridge between ident's <ident-selector> and gitoria's shell (components/main.hl;
  2. // gitoria#14, the same as tickets' login.js). Plain JS because hl:web cannot listen to a custom DOM event:
  3. // `ident-login` (event.detail.code, the one-time code) goes into the hidden input #identcode, whose `change`
  4. // the shell handles (→ face gitoriaLogin, server-side exchange). The shell keeps the selector element's class
  5. // at `in` / `out`; it is mirrored here into the selector's `loggedIn` (false = back to "choose ident").
  6. // ident answers the selector only for a REGISTERED origin — the main address and (the wildcard origin) every repo address.
  7. // BACK TO THE PAGE: the "Log in with ident" click gets `?next=<this page>` in its return URL — a path on the main
  8. // address, the full URL on a repo address (project.hl safeNext checks both). At the click, so it is the page the
  9. // address bar shows after any hl:web navigation.
  10. // RUNS ONCE PER DOCUMENT: hl:web re-creates the header and its <script>s when the login state flips, the
  11. // selector element is then a NEW one; listeners sit on `document`, the CURRENT #selector is looked up each
  12. // time, and a one-time code is handed to the shell at most once.
  13. (() => {
  14. if (window.__gitoriaLogin) { window.__gitoriaLogin.sync(); return; }
  15. const sync = () => {
  16. const sel = document.getElementById('selector');
  17. // not upgraded yet: a property set now would shadow the element's own accessor
  18. if (!sel || !window.customElements || !customElements.get('ident-selector')) return;
  19. const want = sel.classList.contains('in');
  20. if (sel.loggedIn !== want) sel.loggedIn = want;
  21. };
  22. new MutationObserver(sync).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['class'] });
  23. if (window.customElements) customElements.whenDefined('ident-selector').then(sync);
  24. const handed = new Set();
  25. document.addEventListener('ident-login', (e) => {
  26. const code = e.detail && e.detail.code;
  27. const input = document.getElementById('identcode');
  28. if (!input || !code || handed.has(code)) return; // a one-time code is exchanged once
  29. handed.add(code);
  30. input.value = code;
  31. input.dispatchEvent(new Event('change', { bubbles: true }));
  32. });
  33. const withNext = (a) => {
  34. try {
  35. const u = new URL(a.href);
  36. const ret = new URL(u.searchParams.get('return'));
  37. const main = ret.host === location.host;
  38. const here = main ? location.pathname + location.search : location.href;
  39. ret.search = '';
  40. if (here !== '/' && here.length <= 500) ret.searchParams.set('next', here);
  41. u.searchParams.set('return', ret.href);
  42. a.href = u.href;
  43. } catch (err) { /* keep the server's href: the login still works, it returns to / */ }
  44. };
  45. const onButton = (e) => {
  46. const a = e.target && e.target.closest && e.target.closest('#loginbutton');
  47. if (a) withNext(a);
  48. };
  49. for (const t of ['click', 'auxclick', 'contextmenu']) document.addEventListener(t, onButton, true);
  50. window.__gitoriaLogin = { sync };
  51. })();

Branches

Latest commits

  • 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
  • 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