Skip to content

Commit

Permalink
fix: prefixed org names and owners to Owners
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderMatt committed Jan 23, 2025
1 parent 3607ed8 commit e201d38
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 129 deletions.
116 changes: 0 additions & 116 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/operator/gitea.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('giteaOperator', () => {
it('should create a valid group mapping string with all the teams', () => {
const mappingString = buildTeamString(teamNames)
expect(mappingString).to.be.equal(
'{"platform-admin":{"otomi":["Owners"]},"team-demo":{"otomi":["otomi-viewer","team-demo"],"demo":["owners"]},"team-demo2":{"otomi":["otomi-viewer","team-demo2"],"demo2":["owners"]},"team-demo3":{"otomi":["otomi-viewer","team-demo3"],"demo3":["owners"]}}',
'{"platform-admin":{"otomi":["Owners"]},"team-demo":{"otomi":["otomi-viewer","team-demo"],"demo":["Owners"]},"team-demo2":{"otomi":["otomi-viewer","team-demo2"],"demo2":["Owners"]},"team-demo3":{"otomi":["otomi-viewer","team-demo3"],"demo3":["Owners"]}}',
)
expect(mappingString).to.not.contain('team-admin')
})
Expand Down
27 changes: 15 additions & 12 deletions src/operator/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,21 @@ async function upsertOrganization(
existingOrganizations: Organization[],
organizationName: string,
): Promise<void> {
const prefixedOrgName = `team-${organizationName}`
const orgOption = {
...new CreateOrgOption(),
username: organizationName,
fullName: organizationName,
username: prefixedOrgName,
fullName: prefixedOrgName,
repoAdminChangeTeamAccess: true,
}
const existingOrg = existingOrganizations.find((organization) => organization.name === organizationName)
const existingOrg = existingOrganizations.find((organization) => organization.name === prefixedOrgName)
if (isEmpty(existingOrg))
return doApiCall(errors, `Creating org "${orgOption.fullName}"`, () => orgApi.orgCreate(orgOption), 422)

return doApiCall(
errors,
`Updating org "${orgOption.fullName}"`,
() => orgApi.orgEdit(organizationName, orgOption),
() => orgApi.orgEdit(prefixedOrgName, orgOption),
422,
)
}
Expand All @@ -277,19 +278,21 @@ async function upsertTeam(
)
if (!isEmpty(getErrors)) console.error('Errors when gettings teams.', getErrors)
const existingTeam = existingTeams?.find((team) => team.name === teamOption.name)
if (isEmpty(existingTeam))
if (existingTeam === undefined) {
return doApiCall(
errors,
`Creating team "${teamOption.name}" in org "${organizationName}"`,
() => orgApi.orgCreateTeam(organizationName, teamOption),
422,
)
return doApiCall(
errors,
`Updating team "${teamOption.name}" in org "${organizationName}"`,
() => orgApi.orgEditTeam(existingTeam!.id!, teamOption),
422,
)
} else {
return doApiCall(
errors,
`Updating team "${teamOption.name}" in org "${organizationName}"`,
() => orgApi.orgEditTeam(existingTeam.id!, teamOption),
422,
)
}
}

async function upsertRepo(
Expand Down Expand Up @@ -478,7 +481,7 @@ export function buildTeamString(teamNames: any[]): string {
const team = `team-${teamName}`
teamObject[team] = {
otomi: [teamNameViewer, team],
[teamName]: ['owners'],
[teamName]: ['Owners'],
}
})
return JSON.stringify(teamObject)
Expand Down

0 comments on commit e201d38

Please sign in to comment.