Commit with GitHub user email (needed for vercel deployment)
This commit is contained in:
@@ -33,6 +33,7 @@ import { getEnvVar } from "../utils/read_env";
|
||||
import { readSettings } from "../../main/settings";
|
||||
import { Worker } from "worker_threads";
|
||||
import fixPath from "fix-path";
|
||||
import { getGitAuthor } from "../utils/git_author";
|
||||
|
||||
// Needed, otherwise electron in MacOS/Linux will not be able
|
||||
// to find "npm".
|
||||
@@ -346,10 +347,7 @@ export function registerAppHandlers() {
|
||||
fs: fs,
|
||||
dir: fullAppPath,
|
||||
message: "Init from react vite template",
|
||||
author: {
|
||||
name: "Dyad",
|
||||
email: "dyad@example.com",
|
||||
},
|
||||
author: await getGitAuthor(),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error in background app initialization:", error);
|
||||
@@ -708,10 +706,7 @@ export function registerAppHandlers() {
|
||||
fs,
|
||||
dir: appPath,
|
||||
message: `Reverted all changes back to version ${previousVersionId}`,
|
||||
author: {
|
||||
name: "Dyad",
|
||||
email: "hi@dyad.sh",
|
||||
},
|
||||
author: await getGitAuthor(),
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
@@ -845,10 +840,7 @@ export function registerAppHandlers() {
|
||||
fs,
|
||||
dir: appPath,
|
||||
message: `Updated ${filePath}`,
|
||||
author: {
|
||||
name: "Dyad",
|
||||
email: "hi@dyad.sh",
|
||||
},
|
||||
author: await getGitAuthor(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { getDyadAppPath } from "../../paths/paths";
|
||||
import { db } from "../../db";
|
||||
import { apps } from "../../db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { GithubUser } from "../../lib/schemas";
|
||||
|
||||
// --- GitHub Device Flow Constants ---
|
||||
// TODO: Fetch this securely, e.g., from environment variables or a config file
|
||||
@@ -38,6 +39,37 @@ let currentFlowState: DeviceFlowState | null = null;
|
||||
|
||||
// --- Helper Functions ---
|
||||
|
||||
/**
|
||||
* Fetches the GitHub username of the currently authenticated user (using the stored access token).
|
||||
* @returns {Promise<string|null>} The GitHub username, or null if not authenticated or on error.
|
||||
*/
|
||||
export async function getGithubUser(): Promise<GithubUser | null> {
|
||||
const settings = readSettings();
|
||||
const email = settings.githubUser?.email;
|
||||
if (email) return { email };
|
||||
try {
|
||||
const accessToken = settings.githubSettings?.secrets?.accessToken;
|
||||
if (!accessToken) return null;
|
||||
const res = await fetch("https://api.github.com/user/emails", {
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const emails = await res.json();
|
||||
const email = emails.find((e: any) => e.primary)?.email;
|
||||
if (!email) return null;
|
||||
|
||||
writeSettings({
|
||||
githubUser: {
|
||||
email,
|
||||
},
|
||||
});
|
||||
return { email };
|
||||
} catch (err) {
|
||||
console.error("[GitHub Handler] Failed to get GitHub username:", err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// function event.sender.send(channel: string, data: any) {
|
||||
// if (currentFlowState?.window && !currentFlowState.window.isDestroyed()) {
|
||||
// currentFlowState.window.webContents.send(channel, data);
|
||||
|
||||
Reference in New Issue
Block a user