From e201d38254d360381dff5c78b2e4f3438f2edbc2 Mon Sep 17 00:00:00 2001 From: ElderMatt <18527012+ElderMatt@users.noreply.github.com> Date: Thu, 23 Jan 2025 13:42:53 +0100 Subject: [PATCH] fix: prefixed org names and owners to Owners --- package-lock.json | 116 ------------------------------------- src/operator/gitea.test.ts | 2 +- src/operator/gitea.ts | 27 +++++---- 3 files changed, 16 insertions(+), 129 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7da9fbf..4f5dfcf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2526,24 +2526,6 @@ "typescript": ">=4.8.4" } }, - "node_modules/@typescript-eslint/scope-manager": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.18.0.tgz", - "integrity": "sha512-PNGcHop0jkK2WVYGotk/hxj+UFLhXtGPiGtiaWgVBVP1jhMoMCHlTyJA+hEj4rszoSdLTK3fN4oOatrL0Cp+Xw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.18.0", - "@typescript-eslint/visitor-keys": "8.18.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/type-utils": { "version": "8.19.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.19.1.tgz", @@ -2659,73 +2641,6 @@ "typescript": ">=4.8.4" } }, - "node_modules/@typescript-eslint/types": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.18.0.tgz", - "integrity": "sha512-FNYxgyTCAnFwTrzpBGq+zrnoTO4x0c1CKYY5MuUTzpScqmY5fmsh2o3+57lqdI3NZucBDCzDgdEbIaNfAjAHQA==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.18.0.tgz", - "integrity": "sha512-rqQgFRu6yPkauz+ms3nQpohwejS8bvgbPyIDq13cgEDbkXt4LH4OkDMT0/fN1RUtzG8e8AKJyDBoocuQh8qNeg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.18.0", - "@typescript-eslint/visitor-keys": "8.18.0", - "debug": "^4.3.4", - "fast-glob": "^3.3.2", - "is-glob": "^4.0.3", - "minimatch": "^9.0.4", - "semver": "^7.6.0", - "ts-api-utils": "^1.3.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "typescript": ">=4.8.4 <5.8.0" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@typescript-eslint/utils": { "version": "8.19.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.19.1.tgz", @@ -2858,24 +2773,6 @@ "typescript": ">=4.8.4" } }, - "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.18.0.tgz", - "integrity": "sha512-pCh/qEA8Lb1wVIqNvBke8UaRjJ6wrAWkJO5yyIbs8Yx6TNGYyfNjOo61tLv+WwLvoLPp4BQ8B7AHKijl8NGUfw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.18.0", - "eslint-visitor-keys": "^4.2.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", @@ -13336,19 +13233,6 @@ "node": ">=6" } }, - "node_modules/ts-api-utils": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.3.tgz", - "integrity": "sha512-i3eMG77UTMD0hZhgRS562pv83RC6ukSAC2GMNWc+9dieh/+jDM5u5YG+NHX6VNDRHQcHwmsTHctP9LhbC3WxVw==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=16" - }, - "peerDependencies": { - "typescript": ">=4.2.0" - } - }, "node_modules/ts-custom-error": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/ts-custom-error/-/ts-custom-error-3.3.1.tgz", diff --git a/src/operator/gitea.test.ts b/src/operator/gitea.test.ts index d10a172..042812a 100644 --- a/src/operator/gitea.test.ts +++ b/src/operator/gitea.test.ts @@ -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') }) diff --git a/src/operator/gitea.ts b/src/operator/gitea.ts index 8221e86..7f42613 100644 --- a/src/operator/gitea.ts +++ b/src/operator/gitea.ts @@ -247,20 +247,21 @@ async function upsertOrganization( existingOrganizations: Organization[], organizationName: string, ): Promise { + 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, ) } @@ -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( @@ -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)