-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathservice.ts
More file actions
31 lines (27 loc) · 1.01 KB
/
service.ts
File metadata and controls
31 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { getCloudUrlFromRegion } from "@shared/utils/urls";
import { shell } from "electron";
import { injectable } from "inversify";
import { logger } from "../../utils/logger";
import type { CloudRegion, StartGitHubFlowOutput } from "./schemas";
const log = logger.scope("github-integration-service");
@injectable()
export class GitHubIntegrationService {
public async startFlow(
region: CloudRegion,
projectId: number,
): Promise<StartGitHubFlowOutput> {
try {
const cloudUrl = getCloudUrlFromRegion(region);
const next = `${cloudUrl}/projects/${projectId}`;
const authorizeUrl = `${cloudUrl}/api/environments/${projectId}/integrations/authorize/?kind=github&next=${encodeURIComponent(next)}`;
log.info("Opening GitHub authorization URL in browser");
await shell.openExternal(authorizeUrl);
return { success: true };
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : "Unknown error",
};
}
}
}