fix(github): label Copilot profiles by account identity (#2498)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -56,6 +56,17 @@ function upsert(db, c) {
|
||||
);
|
||||
}
|
||||
|
||||
function deriveConnectionName(data, fallbackName) {
|
||||
if (data.provider === "github") {
|
||||
return data.providerSpecificData?.githubLogin
|
||||
|| data.providerSpecificData?.githubEmail
|
||||
|| data.email
|
||||
|| data.providerSpecificData?.githubName
|
||||
|| fallbackName;
|
||||
}
|
||||
return fallbackName;
|
||||
}
|
||||
|
||||
export async function getProviderConnections(filter = {}) {
|
||||
const db = await getAdapter();
|
||||
const where = [];
|
||||
@@ -133,7 +144,7 @@ export async function createProviderConnection(data) {
|
||||
|
||||
let connectionName = data.name || null;
|
||||
if (!connectionName && (data.authType === "oauth" || data.authType === "access_token")) {
|
||||
connectionName = data.email || `Account ${all.length + 1}`;
|
||||
connectionName = deriveConnectionName(data, data.email || `Account ${all.length + 1}`);
|
||||
}
|
||||
let connectionPriority = data.priority;
|
||||
if (!connectionPriority) {
|
||||
|
||||
@@ -777,6 +777,9 @@ const PROVIDERS = {
|
||||
accessToken: tokens.access_token,
|
||||
refreshToken: tokens.refresh_token,
|
||||
expiresIn: tokens.expires_in,
|
||||
name: extra?.userInfo?.login || extra?.userInfo?.name,
|
||||
displayName: extra?.userInfo?.name || extra?.userInfo?.login,
|
||||
email: extra?.userInfo?.email || null,
|
||||
providerSpecificData: {
|
||||
copilotToken: extra?.copilotToken?.token,
|
||||
copilotTokenExpiresAt: extra?.copilotToken?.expires_at,
|
||||
|
||||
@@ -101,6 +101,19 @@ describe("DB SQLite layer — public API parity", () => {
|
||||
expect(back.providerSpecificData).toEqual({ foo: "bar" });
|
||||
});
|
||||
|
||||
it("providerConnections: GitHub OAuth uses account identity as fallback name", async () => {
|
||||
const c = await sqliteDb.createProviderConnection({
|
||||
provider: "github",
|
||||
authType: "oauth",
|
||||
accessToken: "tok",
|
||||
providerSpecificData: { githubLogin: "octocat" },
|
||||
});
|
||||
|
||||
expect(c.name).toBe("octocat");
|
||||
const back = await sqliteDb.getProviderConnectionById(c.id);
|
||||
expect(back.name).toBe("octocat");
|
||||
});
|
||||
|
||||
it("providerNodes: CRUD", async () => {
|
||||
const n = await sqliteDb.createProviderNode({ type: "openai", name: "Test", baseUrl: "https://api.test", apiType: "openai" });
|
||||
expect(n.id).toBeDefined();
|
||||
|
||||
Reference in New Issue
Block a user