generated from ipdxco/github-as-code
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from multiformats/master-upgrade
upgrade@7919415966
- Loading branch information
Showing
17 changed files
with
311 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1409,7 +1409,7 @@ | |
"svn_url": "https://github.com/pl-strflt/github-mgmt", | ||
"template": [ | ||
{ | ||
"owner": "protocol", | ||
"owner": "pl-strflt", | ||
"repository": "github-mgmt-template" | ||
} | ||
], | ||
|
@@ -1794,7 +1794,7 @@ | |
"commit_email": "[email protected]", | ||
"commit_message": "Update README", | ||
"commit_sha": "ff32de62d3dd9bc01a2dabd8439d413e8a250dfe", | ||
"content": "# GitHub Management via Terraform: pl-strflt\n\nThis repository is responsible for managing GitHub configuration of `pl-strflt` organisation as code with Terraform. It was created from [github-mgmt-template](https://github.com/protocol/github-mgmt-template) and it will receive updates from that repository.\n\n**IMPORTANT**: Having write access to GitHub Management repository can be as powerful as having admin access to the organizations managed by that repository.\n\n*NOTE*: Because we don't have merge queue functionality enabled for the repository yet, after a merge, wait for the `Apply` and `Update` workflows to complete before merging any other PRs.\n\nTo learn more, check out:\n- [What is GitHub Management and how does it work?](docs/ABOUT.md)\n- [How to set up GitHub Management?](docs/SETUP.md)\n- [How to work with GitHub Management?](docs/HOWTOS.md)\n", | ||
"content": "# GitHub Management via Terraform: pl-strflt\n\nThis repository is responsible for managing GitHub configuration of `pl-strflt` organisation as code with Terraform. It was created from [github-mgmt-template](https://github.com/pl-strflt/github-mgmt-template) and it will receive updates from that repository.\n\n**IMPORTANT**: Having write access to GitHub Management repository can be as powerful as having admin access to the organizations managed by that repository.\n\n*NOTE*: Because we don't have merge queue functionality enabled for the repository yet, after a merge, wait for the `Apply` and `Update` workflows to complete before merging any other PRs.\n\nTo learn more, check out:\n- [What is GitHub Management and how does it work?](docs/ABOUT.md)\n- [How to set up GitHub Management?](docs/SETUP.md)\n- [How to work with GitHub Management?](docs/HOWTOS.md)\n", | ||
"file": "README.md", | ||
"id": "github-mgmt/README.md", | ||
"overwrite_on_create": false, | ||
|
100 changes: 100 additions & 0 deletions
100
scripts/src/actions/shared/get-access-summary-description.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import {Config} from '../../yaml/config' | ||
import { State } from '../../terraform/state' | ||
import { RepositoryCollaborator } from '../../resources/repository-collaborator' | ||
import { Member } from '../../resources/member' | ||
import { TeamMember } from '../../resources/team-member' | ||
import { RepositoryTeam } from '../../resources/repository-team' | ||
|
||
function getAccessSummaryFrom(source: State | Config): Record<string, any> { | ||
const members = source.getResources(Member) | ||
const teamMembers = source.getResources(TeamMember) | ||
const teamRepositories = source.getResources(RepositoryTeam) | ||
const repositoryCollaborators = source.getResources(RepositoryCollaborator) | ||
|
||
const usernames = new Set<string>([ | ||
...members.map(member => member.username), | ||
...repositoryCollaborators.map(collaborator => collaborator.username), | ||
]) | ||
|
||
const accessSummary: Record<string, any> = {} | ||
|
||
for (const username of usernames) { | ||
const role = members.find(member => member.username === username)?.role | ||
const teams = teamMembers.filter(teamMember => teamMember.username === username).map(teamMember => teamMember.team) | ||
const repositoryCollaborator = repositoryCollaborators.filter(repositoryCollaborator => repositoryCollaborator.username === username) | ||
const teamRepository = teamRepositories.filter(teamRepository => teams.includes(teamRepository.team)) | ||
|
||
const repositories: Record<string, any> = {} | ||
|
||
for (const rc of repositoryCollaborator) { | ||
repositories[rc.repository] = repositories[rc.repository] ?? [] | ||
repositories[rc.repository].push({permission: rc.permission, type: 'collaborator'}) | ||
} | ||
|
||
for (const tr of teamRepository) { | ||
repositories[tr.repository] = repositories[tr.repository] ?? [] | ||
repositories[tr.repository].push({permission: tr.permission, type: 'team', team: tr.team}) | ||
} | ||
|
||
accessSummary[username] = { | ||
role, | ||
teams, | ||
repositories | ||
} | ||
} | ||
|
||
return accessSummary | ||
} | ||
|
||
function describeAccessSummary(accessSummary: Record<string, any>): string { | ||
const lines: string[] = [] | ||
const permissions = ['admin', 'maintain', 'push', 'triage', 'pull'] | ||
|
||
for (const [username, summary] of Object.entries(accessSummary)) { | ||
lines.push(`User @${username}:`) | ||
if (summary.role !== undefined) { | ||
lines.push(` - is a ${summary.role} of the organization`) | ||
} else { | ||
lines.push(` - is not a member of the organization`) | ||
} | ||
if (Object.keys(summary.repositories).length > 0) { | ||
for (const permission of permissions) { | ||
const buffer = [] | ||
const index = permission.indexOf(permission) | ||
for (const [repository, accessList] of Object.entries(summary.repositories) as [string, any][]) { | ||
const access = accessList.find((a: any) => a.permission === permission) | ||
if (access !== undefined) { | ||
const higher = accessList.filter((a: any) => permissions.indexOf(a.permission) < index) | ||
if (higher.length === 0) { | ||
if (access.type === 'collaborator') { | ||
buffer.push(` - ${repository} as a direct collaborator`) | ||
} else { | ||
buffer.push(` - ${repository} through team @${access.team}`) | ||
} | ||
} | ||
} | ||
} | ||
if (buffer.length > 0) { | ||
lines.push(` - has ${permission} access to:`) | ||
lines.push(...buffer) | ||
} else { | ||
lines.push(` - has no ${permission} access to any repository`) | ||
} | ||
} | ||
} else { | ||
lines.push(` - has no access to any repository`) | ||
} | ||
} | ||
|
||
return lines.join('\n') | ||
} | ||
|
||
export async function getAccessSummaryDescription(): Promise<string> { | ||
const config = Config.FromPath() | ||
|
||
const accessSummary = getAccessSummaryFrom(config) | ||
|
||
const description = describeAccessSummary(accessSummary) | ||
|
||
return description | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {Config} from '../../yaml/config' | ||
import {Repository} from '../../resources/repository' | ||
import { State } from '../../terraform/state' | ||
|
||
export async function toggleArchivedRepos(): Promise<void> { | ||
const state = await State.New() | ||
const config = Config.FromPath() | ||
|
||
const resources = state.getAllResources() | ||
const stateRepositories = state.getResources(Repository) | ||
const configRepositories = config.getResources(Repository) | ||
|
||
for (const configRepository of configRepositories) { | ||
if (configRepository.archived) { | ||
config.removeResource(configRepository) | ||
const repository = new Repository(configRepository.name) | ||
repository.archived = true | ||
config.addResource(repository) | ||
} else { | ||
const stateRepository = stateRepositories.find(r => r.name === configRepository.name) | ||
if (stateRepository !== undefined && stateRepository.archived) { | ||
config.addResource(stateRepository) | ||
for (const resource of resources) { | ||
if ('repository' in resource && resource.repository === stateRepository.name) { | ||
config.addResource(resource) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
config.save() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.