Skip to content

Commit 0013196

Browse files
💡 update/add additional logging for config results (#86)
This PR makes a few adjustments so that "client side" issues are easier to detect and thus triage.
1 parent ac5ea5a commit 0013196

3 files changed

Lines changed: 68 additions & 19 deletions

File tree

src/services/gitHub.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,22 @@ class InstalledGitHubClient implements InstalledClient {
649649
.filter(i => i.type == "file")
650650
.filter(i => i.name == "team-sync-options.yml" || i.name == "team-sync-options.yaml");
651651

652-
if (onlyConfigFiles.length != 1) {
652+
if (onlyConfigFiles.length > 1) {
653653
return {
654654
successful: false,
655655
state: "BadConfig",
656656
message: "Multiple configuration files are not supported at this point in time."
657657
}
658658
}
659659

660+
if(onlyConfigFiles.length < 1) {
661+
return {
662+
successful: false,
663+
state: "NoConfig",
664+
message: "No configuration file exists in the configuration repository (typically the .github repository)."
665+
}
666+
}
667+
660668
const onlyFile = onlyConfigFiles[0];
661669

662670
const contentResponse = await this.gitHubClient.rest.repos.getContent({

src/services/githubSync.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const replaceAll = function (original: string, search: string, replacement: stri
1919

2020
type GitHubIdsFailed = {
2121
Succeeded: false
22+
Reason: "unknown" | "team_not_found"
2223
}
2324

2425
type GitHubIdsSucceeded = {
@@ -31,8 +32,16 @@ async function GetGitHubIds(teamName: string, config: AppConfig): Promise<GitHub
3132
const membersFromSourceOfTruth = await SearchAllAsync(teamName);
3233

3334
if (membersFromSourceOfTruth.Succeeded == false) {
35+
if(membersFromSourceOfTruth.Reason == "team_not_found") {
36+
return {
37+
Succeeded: false,
38+
Reason: "team_not_found"
39+
}
40+
}
41+
3442
return {
35-
Succeeded: false
43+
Succeeded: false,
44+
Reason: "unknown"
3645
}
3746
}
3847

@@ -46,23 +55,34 @@ async function GetGitHubIds(teamName: string, config: AppConfig): Promise<GitHub
4655
}
4756
}
4857

49-
type SyncFailed = {
58+
type SyncMembersFailed = {
5059
Succeeded: false
60+
Reason: "unknown" | "team_not_found"
5161
}
5262

53-
type SyncSucceeded = {
63+
type SyncMembersSucceeded = {
5464
Succeeded: true
5565
OrgMembers: string[]
5666
}
5767

58-
async function SynchronizeOrgMembers(installedGitHubClient: InstalledClient, teamName: string, config: AppConfig, sourceTeamMap: Map<string, string>): Promise<SyncFailed | SyncSucceeded> {
68+
type SyncMembersResponse = Promise<SyncMembersFailed | SyncMembersSucceeded>
69+
70+
async function SynchronizeOrgMembers(installedGitHubClient: InstalledClient, teamName: string, config: AppConfig, sourceTeamMap: Map<string, string>): SyncMembersResponse {
5971
const actualTeamName = sourceTeamMap.get(teamName) ?? teamName;
6072

6173
const gitHubIdsResponse = await GetGitHubIds(actualTeamName, config);
6274

6375
if (gitHubIdsResponse.Succeeded == false) {
76+
if(gitHubIdsResponse.Reason == "team_not_found") {
77+
return {
78+
Succeeded: false,
79+
Reason: "team_not_found"
80+
}
81+
}
82+
6483
return {
65-
Succeeded: false
84+
Succeeded: false,
85+
Reason: "unknown"
6686
};
6787
}
6888

@@ -368,6 +388,14 @@ async function syncOrg(installedGitHubClient: InstalledClient, appConfig: AppCon
368388
if (currentMembersResponse.Succeeded == false) {
369389
Log("Failed to sync members");
370390

391+
if(currentMembersResponse.Reason == "team_not_found") {
392+
return {
393+
...response,
394+
message: "Org Membership Group does not appear to exist in source of truth.",
395+
status: "bad_config"
396+
};
397+
}
398+
371399
return {
372400
...response,
373401
message: "Failed to sync org members"

src/services/ldapClient.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Config } from "../config";
2-
import axios from "axios";
2+
import axios, { AxiosError } from "axios";
33
import axiosRetry from "axios-retry";
44
import { Log, LoggerToUse } from "../logging";
55
import { redisClient } from "../app";
@@ -11,12 +11,13 @@ export interface Entry {
1111
}
1212

1313
export type SearchAllFailed = {
14-
Succeeded: false
14+
Succeeded: false,
15+
Reason: "unknown" | "team_not_found"
1516
}
1617

1718
export type SearchAllSucceeded = {
1819
Succeeded: true,
19-
entries: Entry[]
20+
entries: Entry[]
2021
}
2122

2223
export type SearchAllResponse = Promise<SearchAllFailed | SearchAllSucceeded>
@@ -77,16 +78,17 @@ async function ForwardSearch(groupName: string): SearchAllResponse {
7778
Log(`Retrieving group (${groupName}) information from '${requestUrl}'`);
7879
try {
7980
const httpResponse = await httpClient.get(requestUrl);
80-
Log(`Results for ${groupName}: ${JSON.stringify(httpResponse.data)}`);
81+
Log(`Results for ${groupName}: ${JSON.stringify(httpResponse.data)}`);
8182

82-
if(httpResponse.status < 200 || httpResponse.status > 299) {
83+
if (httpResponse.status < 200 || httpResponse.status > 299) {
8384
return {
84-
Succeeded: false
85+
Succeeded: false,
86+
Reason: "unknown"
8587
}
86-
}
88+
}
8789

8890
const response = httpResponse.data as SuccessResponse;
89-
91+
9092
return {
9193
Succeeded: true,
9294
entries: response.users.map(u => {
@@ -99,10 +101,21 @@ async function ForwardSearch(groupName: string): SearchAllResponse {
99101
}
100102
catch (e) {
101103
Log(`Error when retrieving results for ${groupName}: ${e}`);
104+
105+
if (e instanceof (AxiosError)) {
106+
const axiosError = e as AxiosError;
107+
if (axiosError.response?.status == 404) {
108+
return {
109+
Succeeded: false,
110+
Reason: "team_not_found"
111+
}
112+
}
113+
}
102114
}
103115

104116
return {
105-
Succeeded: false
117+
Succeeded: false,
118+
Reason: "unknown"
106119
}
107120
}
108121

@@ -111,12 +124,12 @@ export interface User {
111124
email: string
112125
}
113126

114-
export interface SuccessResponse {
115-
users: User[]
127+
export interface SuccessResponse {
128+
users: User[]
116129
}
117130

118-
export interface FailedResponse {
131+
export interface FailedResponse {
119132
Message: string
120133
}
121134

122-
export type SearchResponse = SuccessResponse | FailedResponse
135+
export type SearchResponse = SuccessResponse | FailedResponse;

0 commit comments

Comments
 (0)