Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/config/repoAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export interface RepositoryAccess {
* name-already-exists error. Adopt it with `pulumi import` first. The
* `repository` key of a managed entry is also the Pulumi resource name, so
* renaming it in place archives the old repository and creates a new one.
* To rename, do three things in order: rename the repository on GitHub,
* rename the resources in state with `pulumi state rename`
* (`repository-<old>` to `repository-<new>`, and `repo-<old>` to
* `repo-<new>`), then change the key.
* To rename an access-only entry after its repository was renamed on GitHub,
* deploy `retainOnDelete: true` on its collaborators resource, then change the
* key, then drop the option. Otherwise deleting the old resource follows
* GitHub's redirect and removes the repository's access. These steps
* don't cover managed entries.
*/
settings?: RepositorySettings;
teams?: Array<{
Expand Down
48 changes: 17 additions & 31 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ ORG_ROLE_ASSIGNMENTS.forEach((assignment) => {
// @pulumi/github release that includes that fix.
const orgRoleTeamNames = [...new Set(ORG_ROLE_ASSIGNMENTS.map((a) => a.team))];

// Access-only entries that are being renamed, under their old and new names. GitHub redirects
// the old name, so deleting the old resource would remove everyone's access to the repository.
// Pulumi forgets it instead. Deploy this before the rename, and remove the names after it.
const RENAMED_REPOSITORIES = [
'experimental-ext-grouping',
'experimental-ext-triggers-events',
'ext-events',
'progressive-disclosure-wg',
];

// Repositories. An entry with `settings` is created and owned by Pulumi; the
// collaborators resource then depends on it through the name output, so a new
// repository and its access land in the same apply. Entries without `settings`
Expand Down Expand Up @@ -142,27 +132,23 @@ REPOSITORY_ACCESS.forEach((repo) => {
}

const grantedTeams = new Set(repo.teams?.map((t) => t.team));
new github.RepositoryCollaborators(
`repo-${repo.repository}`,
{
repository: repositoryName,
// Ignore org-role teams, except where repoAccess.ts grants them directly on
// this repository (e.g. lead-maintainers on maintainer-docs) — those grants
// must stay managed by Pulumi.
ignoreTeams: orgRoleTeamNames
.filter((team) => !grantedTeams.has(team))
.map((team) => ({ teamId: teams[team].slug })),
teams: repo.teams?.map((t) => ({
teamId: teams[t.team]?.id,
permission: t.permission,
})),
users: repo.users?.map((u) => ({
username: u.username,
permission: u.permission,
})),
},
{ retainOnDelete: RENAMED_REPOSITORIES.includes(repo.repository) }
);
new github.RepositoryCollaborators(`repo-${repo.repository}`, {
repository: repositoryName,
// Ignore org-role teams, except where repoAccess.ts grants them directly on
// this repository (e.g. lead-maintainers on maintainer-docs) — those grants
// must stay managed by Pulumi.
ignoreTeams: orgRoleTeamNames
.filter((team) => !grantedTeams.has(team))
.map((team) => ({ teamId: teams[team].slug })),
teams: repo.teams?.map((t) => ({
teamId: teams[t.team]?.id,
permission: t.permission,
})),
users: repo.users?.map((u) => ({
username: u.username,
permission: u.permission,
})),
});
});

export { teams as githubTeams, repositories as githubRepositories };
Loading