-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsyncSpecificTeamHandler.ts
More file actions
61 lines (46 loc) · 1.95 KB
/
syncSpecificTeamHandler.ts
File metadata and controls
61 lines (46 loc) · 1.95 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Context } from "openapi-backend";
import type { Request, Response } from "express";
import { GetClient } from "../services/gitHub.ts";
import { SyncTeam } from "../services/githubSync.ts";
import axios from 'axios';
import { Log } from "../logging.ts";
import { GetInvitationsClient } from "../services/githubInvitations.ts";
async function forwardToProxy(installationId: number) {
Log(`Forwarding request to '${process.env.GITHUB_PROXY}'`);
const requestUrl = `${process.env.GITHUB_PROXY}/api/sync/SynchronizeOrg?installationId=${installationId}`
const result = await axios.post(requestUrl);
if(result.status >= 200 && result.status < 300) {
return result.data;
}
return {
status: "failed",
installationId: installationId
}
}
export async function syncSpecificTeamHandler(
c: Context,
_req: Request,
res: Response
) {
const orgId = c.request.query.orgId! as unknown as number;
const teamName = c.request.query.teamName! as unknown as string;
const dryRun = c.request.query.dryRun as unknown as boolean ?? true;
const client = GetClient();
const orgClient = await client.GetOrgClient(orgId);
const appConfig = await client.GetAppConfig();
const invitationsClient = GetInvitationsClient(orgClient);
const invitesResponse = await invitationsClient.ListInvites();
if(!invitesResponse.successful) {
return res.status(500).json("Unable to list existing invites");
}
const invites = invitesResponse.data;
const orgConfig = await orgClient.GetConfigurationForInstallation();
if(!orgConfig.successful) {
return res.status(500).json({
Message: "Unable to fetch organization configuration."
})
}
const sourceTeamMap = orgConfig.data.DisplayNameToSourceMap;
const response = await SyncTeam(teamName, orgClient, appConfig, invites, sourceTeamMap, dryRun);
return res.status(200).json(response);
}