Skip to content

Commit 2d6d61c

Browse files
Archetypicallygithub-actions[bot]
authored andcommitted
chore: Package action
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 4dbc9e5 commit 2d6d61c

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

dist/index.js

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -214,40 +214,50 @@ async function main() {
214214
core.debug(`User codeowners: ${(0, util_1.inspect)(userCodeowners)}`);
215215
const githubToken = core.getInput("github-token", { required: true });
216216
const octokit = github.getOctokit(githubToken);
217-
// TEAM-Y OPERATIONS
218-
const allTeamsWithAtLeastWriteAccess = await (0, teams_1.getAllTeamsWithAtLeastWriteAccess)(octokit, github.context.repo.owner, github.context.repo.repo);
219-
core.info(`Found ${allTeamsWithAtLeastWriteAccess.length} teams with at least write access.`);
220-
core.debug(`All teams with at least write access: ${(0, util_1.inspect)(allTeamsWithAtLeastWriteAccess)}`);
221217
const failedTeams = [];
222-
teamCodeowners.forEach(async (team) => {
223-
const [orgName, teamSlug] = team.replaceAll("@", "").split("/");
224-
core.debug(`Found org: '${orgName}' and team: '${teamSlug}' from '${team}'.`);
225-
if (allTeamsWithAtLeastWriteAccess.includes(teamSlug)) {
226-
core.notice(`Team '${teamSlug}' already has at least write access; skipping.`);
227-
}
228-
else {
229-
await (0, teams_1.addTeamToWriteAccess)(octokit, orgName, github.context.repo.repo, teamSlug, isDryRun).catch((error) => {
230-
failedTeams.push(teamSlug);
231-
core.warning(`Failed to give write access to team '${teamSlug}': ${error}`);
232-
});
233-
}
234-
});
235-
// USER-Y OPERATIONS HERE
236-
const allUsersWithAtLeastWriteAccess = await (0, collaborators_1.getAllDirectCollaboratorsWithAtLeastWriteAccess)(octokit, github.context.repo.owner, github.context.repo.repo);
237-
core.info(`Found ${allUsersWithAtLeastWriteAccess.length} users with at least write access.`);
238-
core.debug(`All users with at least write access: ${(0, util_1.inspect)(allUsersWithAtLeastWriteAccess)}`);
239218
const failedUsers = [];
240-
userCodeowners.forEach(async (user) => {
241-
if (allUsersWithAtLeastWriteAccess.includes(user)) {
242-
core.notice(`User '${user}' already has at least write access; skipping.`);
243-
}
244-
else {
245-
await (0, collaborators_1.addUserToWriteAccess)(octokit, github.context.repo.owner, github.context.repo.repo, user, isDryRun).catch((error) => {
246-
failedUsers.push(user);
247-
core.warning(`Failed to give write access to user '${user}': ${error}`);
248-
});
249-
}
250-
});
219+
// TEAM-Y OPERATIONS
220+
if (teamCodeowners.length > 0) {
221+
const allTeamsWithAtLeastWriteAccess = await (0, teams_1.getAllTeamsWithAtLeastWriteAccess)(octokit, github.context.repo.owner, github.context.repo.repo);
222+
core.info(`Found ${allTeamsWithAtLeastWriteAccess.length} teams with at least write access.`);
223+
core.debug(`All teams with at least write access: ${(0, util_1.inspect)(allTeamsWithAtLeastWriteAccess)}`);
224+
teamCodeowners.forEach(async (team) => {
225+
const [orgName, teamSlug] = team.replaceAll("@", "").split("/");
226+
core.debug(`Found org: '${orgName}' and team: '${teamSlug}' from '${team}'.`);
227+
if (allTeamsWithAtLeastWriteAccess.includes(teamSlug)) {
228+
core.notice(`Team '${teamSlug}' already has at least write access; skipping.`);
229+
}
230+
else {
231+
await (0, teams_1.addTeamToWriteAccess)(octokit, orgName, github.context.repo.repo, teamSlug, isDryRun).catch((error) => {
232+
failedTeams.push(teamSlug);
233+
core.warning(`Failed to give write access to team '${teamSlug}': ${error}`);
234+
});
235+
}
236+
});
237+
}
238+
else {
239+
core.notice("No team codeowners found; skipping team operations.");
240+
}
241+
// USER-Y OPERATIONS HERE
242+
if (userCodeowners.length > 0) {
243+
const allUsersWithAtLeastWriteAccess = await (0, collaborators_1.getAllDirectCollaboratorsWithAtLeastWriteAccess)(octokit, github.context.repo.owner, github.context.repo.repo);
244+
core.info(`Found ${allUsersWithAtLeastWriteAccess.length} users with at least write access.`);
245+
core.debug(`All users with at least write access: ${(0, util_1.inspect)(allUsersWithAtLeastWriteAccess)}`);
246+
userCodeowners.forEach(async (user) => {
247+
if (allUsersWithAtLeastWriteAccess.includes(user)) {
248+
core.notice(`User '${user}' already has at least write access; skipping.`);
249+
}
250+
else {
251+
await (0, collaborators_1.addUserToWriteAccess)(octokit, github.context.repo.owner, github.context.repo.repo, user, isDryRun).catch((error) => {
252+
failedUsers.push(user);
253+
core.warning(`Failed to give write access to user '${user}': ${error}`);
254+
});
255+
}
256+
});
257+
}
258+
else {
259+
core.notice("No user codeowners found; skipping user operations.");
260+
}
251261
if (failedTeams.length > 0 || failedUsers.length > 0) {
252262
const errorMsg = `Failed to give write access to teams: ${failedTeams.join(", ")}. ` +
253263
`Failed to give write access to users: ${failedUsers.join(", ")}.`;

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)