Skip to content

Commit

Permalink
Move get members for each org outside of deployed users loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjozwiak committed Jan 17, 2024
1 parent 3d45f96 commit f576d95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
11 changes: 7 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22347,11 +22347,16 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
});
core.info(`Found ${usersToDeploy.length} users to deploy.`);
core.debug(JSON.stringify(usersToDeploy, null, 2));
const uniqueOrganizations = new Set(usersToDeploy.map(user => user.organization));
for (const organization of uniqueOrganizations) {
const members = yield getOrgMembers(organization, octokit);
core.info(`Found ${members.length} members in ${organization}.`);
}
usersToDeploy.forEach((user) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c;
core.info(`Deploying user: ${JSON.stringify(user)}`);
core.info(`Processing user for deployment: ${JSON.stringify(user)}`);
if (!orgData.get(user.organization)) {
core.debug(`Organization Data not found for ${user.organization}. Fetching...`);
core.info(`Organization Data not found for ${user.organization}. Fetching...`);
const seats = yield getOrgData(user.organization, octokit);
getInactiveSeats(user.organization, seats, input.inactiveDays);
if (!orgData.get(user.organization)) {
Expand All @@ -22362,8 +22367,6 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
else {
core.debug(`Organization Data found for ${user.organization}`);
}
const members = yield getOrgMembers(user.organization, octokit);
core.info(`Found ${members.length} members in ${user.organization}.`);
if (user.login != ((_b = (_a = orgData.get(user.organization)) === null || _a === void 0 ? void 0 : _a.members.find(member => member.login === user.login)) === null || _b === void 0 ? void 0 : _b.login)) {
core.error(`User ${user.login} is not a member of ${user.organization}`);
return;
Expand Down
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,20 @@ const run = async (): Promise<void> => {
core.info(`Found ${usersToDeploy.length} users to deploy.`);
core.debug(JSON.stringify(usersToDeploy, null, 2));

// Get members from each organization
const uniqueOrganizations = new Set(usersToDeploy.map(user => user.organization));
for (const organization of uniqueOrganizations) {
const members = await getOrgMembers(organization, octokit);
core.info(`Found ${members.length} members in ${organization}.`);
}

usersToDeploy.forEach(async user => {
core.info(`Deploying user: ${JSON.stringify(user)}`);
core.info(`Processing user for deployment: ${JSON.stringify(user)}`);

// Check if the organization already exists in orgData
if (!orgData.get(user.organization)) {
// Organization not found in orgData. Add it.
core.debug(`Organization Data not found for ${user.organization}. Fetching...`);
core.info(`Organization Data not found for ${user.organization}. Fetching...`);
const seats = await getOrgData(user.organization, octokit);
getInactiveSeats(user.organization, seats, input.inactiveDays);

Expand All @@ -365,8 +372,8 @@ const run = async (): Promise<void> => {
}

// Save organization member info with https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#list-organization-members
const members = await getOrgMembers(user.organization, octokit);
core.info(`Found ${members.length} members in ${user.organization}.`);
//const members = await getOrgMembers(user.organization, octokit);
//core.info(`Found ${members.length} members in ${user.organization}.`);

// Then Check if the user exists in the organization
if (user.login != orgData.get(user.organization)?.members.find(member => member.login === user.login)?.login) {
Expand Down

0 comments on commit f576d95

Please sign in to comment.