MCPcopy Create free account
hub / github.com/TheOrcDev/github-creature / submitGithubForm

Function submitGithubForm

server/ai.ts:247–322  ·  view source on GitHub ↗
(githubProfileUrl: string)

Source from the content-addressed store, hash-verified

245}
246
247export async function submitGithubForm(githubProfileUrl: string) {
248 let username: string;
249 try {
250 username = parseGithubUsernameFromInput(githubProfileUrl);
251 } catch (err) {
252 return {
253 success: false,
254 message:
255 err instanceof Error ? err.message : "Invalid GitHub profile URL",
256 };
257 }
258
259 const canonicalGithubProfileUrl = `https://github.com/${username}`;
260
261 const check = await db.query.creatures.findFirst({
262 where: (creatures, { eq }) =>
263 eq(creatures.githubProfileUrl, canonicalGithubProfileUrl),
264 });
265
266 if (check) {
267 return {
268 success: true,
269 message: "Creature already exists.",
270 redirectUrl: `/${username}`,
271 };
272 }
273
274 let stats: { contributions: number; followers: number; stars: number };
275 try {
276 stats = await fetchGithubStats(username);
277 } catch (err) {
278 return {
279 success: false,
280 message:
281 err instanceof Error ? err.message : "Failed to fetch GitHub stats.",
282 };
283 }
284
285 if (stats.contributions == null || Number.isNaN(stats.contributions)) {
286 return {
287 success: false,
288 message: "Failed to fetch GitHub stats. Is the username valid?",
289 };
290 }
291
292 const { name, description, imagePrompt, powerLevel } = await generateCreature(
293 stats.contributions
294 );
295 const image = await generateCreatureImage(imagePrompt, powerLevel);
296
297 for (const result of image.content) {
298 if (result.type === "file") {
299 const blob = await put(
300 `${username}-generated-creature.png`,
301 Buffer.from(result.file.uint8Array),
302 {
303 access: "public",
304 allowOverwrite: true,

Callers 1

onSubmitFunction · 0.90

Calls 5

saveCreatureFunction · 0.90
fetchGithubStatsFunction · 0.85
generateCreatureFunction · 0.85
generateCreatureImageFunction · 0.85

Tested by

no test coverage detected