Improve messaging

This commit is contained in:
Carlos Monastyrski
2025-08-28 09:49:38 -03:00
parent e8ef0191d6
commit 7894bd8ae1
5 changed files with 13 additions and 28 deletions
@@ -141,7 +141,6 @@ export const registerGithubOrgSyncRouter = async (server: FastifyZodProvider) =>
response: { response: {
200: z.object({ 200: z.object({
syncedUsersCount: z.number(), syncedUsersCount: z.number(),
skippedUsersCount: z.number(),
totalUsers: z.number(), totalUsers: z.number(),
errors: z.array(z.string()), errors: z.array(z.string()),
createdTeams: z.array(z.string()), createdTeams: z.array(z.string()),
@@ -159,7 +158,6 @@ export const registerGithubOrgSyncRouter = async (server: FastifyZodProvider) =>
return { return {
syncedUsersCount: result.syncedUsersCount, syncedUsersCount: result.syncedUsersCount,
skippedUsersCount: result.skippedUsersCount,
totalUsers: result.totalUsers, totalUsers: result.totalUsers,
errors: result.errors, errors: result.errors,
createdTeams: result.createdTeams, createdTeams: result.createdTeams,
@@ -417,7 +417,9 @@ export const githubOrgSyncServiceFactory = ({
} }
}); });
await octokitGraphQL.graphql(`query { organization(login: $org) { id name } }`, { org: config.githubOrgName }); await octokitGraphQL.graphql(`query($org: String!) { organization(login: $org) { id name } }`, {
org: config.githubOrgName
});
return { return {
valid: true, valid: true,
@@ -550,7 +552,6 @@ export const githubOrgSyncServiceFactory = ({
const startTime = Date.now(); const startTime = Date.now();
let syncedUsersCount = 0; let syncedUsersCount = 0;
let skippedUsersCount = 0;
const syncErrors: string[] = []; const syncErrors: string[] = [];
const createdTeams = new Set<string>(); const createdTeams = new Set<string>();
const updatedTeams = new Set<string>(); const updatedTeams = new Set<string>();
@@ -765,8 +766,6 @@ export const githubOrgSyncServiceFactory = ({
for (const member of activeMembers) { for (const member of activeMembers) {
try { try {
if (!member.userId) { if (!member.userId) {
skippedUsersCount += 1;
syncErrors.push("Member without userId found, skipping");
// eslint-disable-next-line no-continue // eslint-disable-next-line no-continue
continue; continue;
} }
@@ -774,8 +773,6 @@ export const githubOrgSyncServiceFactory = ({
const githubUsername = githubUsernameMap.get(member.userId); const githubUsername = githubUsernameMap.get(member.userId);
if (!githubUsername) { if (!githubUsername) {
skippedUsersCount += 1;
syncErrors.push(`User ${member.userId}: No GitHub username found. User needs to log in at least once.`);
// eslint-disable-next-line no-continue // eslint-disable-next-line no-continue
continue; continue;
} }
@@ -811,7 +808,6 @@ export const githubOrgSyncServiceFactory = ({
{ {
orgId: orgPermission.orgId, orgId: orgPermission.orgId,
syncedUsersCount, syncedUsersCount,
skippedUsersCount,
totalUsers: activeMembers.length, totalUsers: activeMembers.length,
createdTeams: createdTeams.size, createdTeams: createdTeams.size,
updatedTeams: updatedTeams.size, updatedTeams: updatedTeams.size,
@@ -824,7 +820,6 @@ export const githubOrgSyncServiceFactory = ({
return { return {
syncedUsersCount, syncedUsersCount,
skippedUsersCount,
totalUsers: activeMembers.length, totalUsers: activeMembers.length,
errors: syncErrors, errors: syncErrors,
createdTeams: Array.from(createdTeams), createdTeams: Array.from(createdTeams),
@@ -29,7 +29,6 @@ export interface TSyncAllTeamsDTO {
export interface TSyncResult { export interface TSyncResult {
syncedUsersCount: number; syncedUsersCount: number;
skippedUsersCount: number;
totalUsers: number; totalUsers: number;
errors: string[]; errors: string[];
createdTeams: string[]; createdTeams: string[];
@@ -49,7 +49,6 @@ export const useSyncAllGithubTeams = () => {
githubOrgAccessToken?: string; githubOrgAccessToken?: string;
} = {}): Promise<{ } = {}): Promise<{
syncedUsersCount: number; syncedUsersCount: number;
skippedUsersCount: number;
totalUsers: number; totalUsers: number;
errors: string[]; errors: string[];
createdTeams: string[]; createdTeams: string[];
@@ -65,20 +65,23 @@ export const OrgGithubSyncSection = () => {
const result = await syncAllTeamsMutation.mutateAsync({ const result = await syncAllTeamsMutation.mutateAsync({
githubOrgAccessToken: token githubOrgAccessToken: token
}); });
let message = `Successfully synced teams for ${result.syncedUsersCount} out of ${result.totalUsers} users`; let message = `Successfully synced teams for ${result.syncedUsersCount} user${result.syncedUsersCount === 1 ? "" : "s"}`;
const details = []; const details = [];
if (result.createdTeams.length > 0) { if (result.createdTeams.length > 0) {
details.push(`${result.createdTeams.length} new teams created`); details.push(
`${result.createdTeams.length} new team${result.createdTeams.length === 1 ? "" : "s"} created`
);
} }
if (result.updatedTeams.length > 0) { if (result.updatedTeams.length > 0) {
details.push(`${result.updatedTeams.length} teams updated`); details.push(
`${result.updatedTeams.length} team${result.updatedTeams.length === 1 ? "" : "s"} updated`
);
} }
if (result.removedMemberships > 0) { if (result.removedMemberships > 0) {
details.push(`${result.removedMemberships} memberships removed`); details.push(
} `${result.removedMemberships} membership${result.removedMemberships === 1 ? "" : "s"} removed`
if (result.skippedUsersCount > 0) { );
details.push(`${result.skippedUsersCount} users skipped`);
} }
if (details.length > 0) { if (details.length > 0) {
@@ -326,15 +329,6 @@ export const OrgGithubSyncSection = () => {
{tokenValidationResult.valid && tokenValidationResult.organizationInfo ? ( {tokenValidationResult.valid && tokenValidationResult.organizationInfo ? (
<div> <div>
<div className="font-medium">✓ Token Valid</div> <div className="font-medium">✓ Token Valid</div>
<div>
Organization: {tokenValidationResult.organizationInfo.name} (
{tokenValidationResult.organizationInfo.login})
</div>
{tokenValidationResult.organizationInfo.publicRepos !== undefined && (
<div>
Public repos: {tokenValidationResult.organizationInfo.publicRepos}
</div>
)}
</div> </div>
) : ( ) : (
<div className="font-medium">✗ Token Invalid</div> <div className="font-medium">✗ Token Invalid</div>