Skip to content

Commit

Permalink
chore: validate org login
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-ae committed Sep 7, 2024
1 parent ba92dd7 commit 14f3ceb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/handlers/shared/get-user-task-limit-and-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ export async function getUserRoleAndTaskLimit(context: Context, user: string): P
);

try {
// Validate the organization login
if (typeof orgLogin !== 'string' || orgLogin.trim() === '') {
throw new Error('Invalid organization name');
}

const response = await context.octokit.orgs.getMembershipForUser({
org: orgLogin as string,
org: orgLogin,
username: user,
});

const role = response.data.role.toLowerCase()
const role = response.data.role.toLowerCase();
const limit = maxConcurrentTasks[role];

return limit ? { role, limit } : smallestTask;
return limit ? { role, limit } : smallestTask;

} catch (err) {
logger.error("Could not get user role", { err });
return smallestTask;
Expand Down
4 changes: 1 addition & 3 deletions src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ async function handleTaskLimitChecks(username: string, context: Context, logger:
limit,
});

if (log.logMessage?.diff) {
await addCommentToIssue(context, log.logMessage.diff as string);
}
await addCommentToIssue(context, log.logMessage.diff);
}

return false;
Expand Down

0 comments on commit 14f3ceb

Please sign in to comment.