Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
25 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1import { redirect } from "react-router";
2
3import type { Route } from "./+types/github-install";
4import { INSTALL_COOKIE, cookie, installCookieValue, newState } from "../lib/github";
5import { githubApp } from "../lib/github.server";
6import { requireUser, roleIn } from "../lib/session.server";
7
8/**
9 * Sends a workspace owner to GitHub to install g1t's GitHub App on an
10 * account or organization. GitHub returns to /integrations/github/setup
11 * with the state, which must match the cookie set here.
12 */
13export async function loader({ request, context }: Route.LoaderArgs) {
14 const user = requireUser(context, request);
15 const workspace = (new URL(request.url).searchParams.get("workspace") ?? "").toLowerCase();
16 if (roleIn(user, workspace) !== "owner") throw redirect(`/new/github?workspace=${encodeURIComponent(workspace)}`);
17 const status = await githubApp.status(user, workspace);
18 if (!status.ok || !status.value.installUrl) throw redirect("/new");
19 const state = newState();
20 const target = new URL(status.value.installUrl);
21 target.searchParams.set("state", state);
22 throw redirect(target.toString(), {
23 headers: { "set-cookie": cookie(INSTALL_COOKIE, installCookieValue(state, workspace), 1800) },
24 });
25}

This file's history is long; its oldest lines are credited to the oldest commit read.