Skip to content

g1t/apps/web/app/routes/repo/star.ts

25 lines1,147 bytesCodeBlame

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.

Merge branch 'main' into worktree-agent-a69aeabc4b0deeb971/**
2 * Starring a repository, or taking the star back (`intent` star or
3 * unstar), from the Star button in the project's header
4 * (components/star-button.tsx).
5 */
6import { data } from "react-router";
7
8import type { Route } from "./+types/star";
9import { repos } from "../../lib/services.server";
10import { assertSameOrigin, requireUser } from "../../lib/session.server";
11
12export async function action({ request, params, context }: Route.ActionArgs) {
13 assertSameOrigin(request);
14 const user = requireUser(context, request);
15 const form = await request.formData();
16 const intent = form.get("intent");
17 if (intent !== "star" && intent !== "unstar") return data({ error: "Nothing to do.", stars: null }, { status: 400 });
18 try {
19 const found = await repos.star(user, { namespace: params.owner, name: params.repo }, intent === "star");
20 if (!found.ok) return data({ error: found.error.message, stars: null }, { status: found.error.code === "not_found" ? 404 : 403 });
21 return { error: null, stars: found.value };
22 } catch {
23 return data({ error: "That did not save. Try again in a moment.", stars: null }, { status: 503 });
24 }
25}

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