Skip to content

Commit 682553a

Browse files
committed
Syncing updates
1 parent d5a28ed commit 682553a

46 files changed

Lines changed: 2461 additions & 1518 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@ module.exports = {
4141
},
4242
},
4343
],
44-
ignorePatterns: ['default-assets-package/thirdparty/**/*.js', 'dist/**/*.js', '**/vendor/**'],
44+
ignorePatterns: [
45+
'default-assets-package/thirdparty/**/*.js',
46+
'dist/**/*.js',
47+
'dist/**/*.d.ts',
48+
'**/vendor/**',
49+
],
4550
};

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"singleQuote": true,
3+
"trailingComma": "es5",
34
"printWidth": 110
45
}

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
"console": "integratedTerminal",
4848
"env": {
4949
"NODE_ENV": "development",
50-
"DEBUG": "startup,g:server,context,github:tokens",
51-
"MORE_DEBUG": "appinsights,cache,restapi,pg,querycache,user,redis-cross-org,health"
50+
"DEBUG": "startup,g:server,context",
51+
"MORE_DEBUG": "appinsights,cache,restapi,pg,querycache,user,redis-cross-org,health,github:tokens"
5252
}
5353
},
5454
{

api/client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ router.get('/', (req: ReposAppRequest, res) => {
8787
appService: config?.webServer?.appService?.name
8888
? {
8989
name: config?.webServer?.appService?.name,
90-
slot: config?.webServer?.appService?.slot,
90+
slot: config?.webServer?.appService?.advanced?.slotType || config?.webServer?.appService?.slot,
9191
region: config?.webServer?.appService?.region,
9292
}
9393
: undefined,

api/client/organization/repo.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import asyncHandler from 'express-async-handler';
88

99
import { jsonError } from '../../../middleware';
1010
import { ErrorHelper, getProviders } from '../../../transitional';
11-
import { Repository } from '../../../business';
1211
import { IndividualContext } from '../../../business/user';
1312
import NewRepositoryLockdownSystem from '../../../features/newRepositories/newRepositoryLockdown';
1413
import {
@@ -19,16 +18,8 @@ import { renameRepositoryDefaultBranchEndToEnd } from '../../../routes/org/repos
1918
import getCompanySpecificDeployment from '../../../middleware/companySpecificDeployment';
2019

2120
import RouteRepoPermissions from './repoPermissions';
22-
import {
23-
ReposAppRequest,
24-
LocalApiRepoAction,
25-
getRepositoryMetadataProvider,
26-
NoCacheNoBackground,
27-
} from '../../../interfaces';
28-
29-
type RequestWithRepo = ReposAppRequest & {
30-
repository: Repository;
31-
};
21+
import { LocalApiRepoAction, getRepositoryMetadataProvider, NoCacheNoBackground } from '../../../interfaces';
22+
import { RequestWithRepo } from '../../../middleware/business/repository';
3223

3324
enum ArchivalAction {
3425
Archive,

api/client/organization/repos.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import { NextFunction, Response, Router } from 'express';
77
import asyncHandler from 'express-async-handler';
88

99
import { jsonError } from '../../../middleware';
10-
import { getProviders } from '../../../transitional';
10+
import { CreateError, getProviders } from '../../../transitional';
1111
import { Repository } from '../../../business';
1212

13-
import RouteRepo from './repo';
1413
import JsonPager from '../jsonPager';
1514
import { ReposAppRequest, IProviders } from '../../../interfaces';
1615
import { sortRepositoriesByNameCaseInsensitive } from '../../../utils';
16+
import { apiMiddlewareRepositoriesToRepository } from '../../../middleware/business/repository';
17+
18+
import routeRepo from './repo';
1719

1820
const router: Router = Router();
1921

@@ -236,21 +238,10 @@ export async function searchRepos(
236238

237239
// --- End of search reimplementation ---
238240

239-
router.use(
240-
'/:repoName',
241-
asyncHandler(async (req: ReposAppRequest, res: Response, next: NextFunction) => {
242-
const { organization } = req;
243-
const { repoName } = req.params;
244-
// does not confirm the name
245-
(req as any).repository = organization.repository(repoName);
246-
return next();
247-
})
248-
);
249-
250-
router.use('/:repoName', RouteRepo);
241+
router.use('/:repoName', asyncHandler(apiMiddlewareRepositoriesToRepository), routeRepo);
251242

252243
router.use('*', (req, res: Response, next: NextFunction) => {
253-
return next(jsonError('no API or function available within this repos endpoint', 404));
244+
return next(CreateError.NotFound('no API or function available within org/repos endpoint'));
254245
});
255246

256247
export default router;

api/client/organizations.ts

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,18 @@ import { NextFunction, Response, Router } from 'express';
77
import asyncHandler from 'express-async-handler';
88

99
import { jsonError } from '../../middleware';
10-
import { CreateError, ErrorHelper, getProviders } from '../../transitional';
10+
import { CreateError, getProviders } from '../../transitional';
1111
import { ReposAppRequest } from '../../interfaces';
1212

1313
import RouteOrganization from './organization';
14-
import {
15-
IReposAppRequestWithOrganizationManagementType,
16-
OrganizationManagementType,
17-
} from '../../middleware/business/organization';
18-
14+
import { apiMiddlewareOrganizationsToOrganization } from '../../middleware/business/organization';
1915
import type { GitHubOrganizationResponseSanitized } from '../../business';
2016
import {
2117
OrganizationAnnotation,
2218
OrganizationAnnotationProperty,
2319
scrubOrganizationAnnotation,
2420
} from '../../entities/organizationAnnotation';
25-
import {
26-
getOrganizationProfileViaMemoryCache,
27-
setOrganizationProfileForRequest,
28-
} from '../../middleware/github/ensureOrganizationProfile';
21+
import { getOrganizationProfileViaMemoryCache } from '../../middleware/github/ensureOrganizationProfile';
2922

3023
const router: Router = Router();
3124

@@ -128,46 +121,10 @@ router.get(
128121
})
129122
);
130123

131-
router.use(
132-
'/:orgName',
133-
asyncHandler(
134-
async (req: IReposAppRequestWithOrganizationManagementType, res: Response, next: NextFunction) => {
135-
const { operations } = getProviders(req);
136-
const { orgName } = req.params;
137-
req.organizationName = orgName;
138-
try {
139-
const org = operations.getOrganization(orgName);
140-
if (org) {
141-
req.organizationManagementType = OrganizationManagementType.Managed;
142-
req.organization = org;
143-
return next();
144-
}
145-
} catch (orgNotFoundError) {
146-
if (!ErrorHelper.IsNotFound(orgNotFoundError)) {
147-
return next(orgNotFoundError);
148-
}
149-
}
150-
try {
151-
const org = operations.getUncontrolledOrganization(orgName);
152-
req.organizationManagementType = OrganizationManagementType.Unmanaged;
153-
req.organization = org;
154-
await setOrganizationProfileForRequest(req);
155-
} catch (orgProfileError) {
156-
if (ErrorHelper.IsNotFound(orgProfileError)) {
157-
return next(CreateError.NotFound(`The organization ${orgName} does not exist`));
158-
} else {
159-
return next(orgProfileError);
160-
}
161-
}
162-
return next();
163-
}
164-
)
165-
);
166-
167-
router.use('/:orgName', RouteOrganization);
124+
router.use('/:orgName', asyncHandler(apiMiddlewareOrganizationsToOrganization), RouteOrganization);
168125

169126
router.use('*', (req: ReposAppRequest, res: Response, next: NextFunction) => {
170-
return next(jsonError('orgs API not found', 404));
127+
return next(CreateError.NotFound('orgs API not found'));
171128
});
172129

173130
export default router;

business/collaborator.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55

66
import { GitHubRepositoryPermission, IGitHubCollaboratorPermissions } from '../interfaces';
7+
import { projectCollaboratorPermissionsObjectToGitHubRepositoryPermission } from '../transitional';
78
import * as common from './common';
89

910
// prettier-ignore
@@ -14,6 +15,19 @@ const memberPrimaryProperties = [
1415
'avatar_url',
1516
];
1617

18+
export type CollaboratorJson = {
19+
avatar_url: string;
20+
id: number;
21+
login: string;
22+
permissions: IGitHubCollaboratorPermissions;
23+
};
24+
25+
export type CollaboratorAccount = Collaborator | { id: number; login: string };
26+
27+
export function compareCollaborators(a: Collaborator, b: Collaborator) {
28+
return a?.login.localeCompare(b?.login, 'en', { sensitivity: 'base' });
29+
}
30+
1731
export class Collaborator {
1832
public static PrimaryProperties = memberPrimaryProperties;
1933

@@ -28,7 +42,7 @@ export class Collaborator {
2842
}
2943
}
3044

31-
asJson() {
45+
asJson(): CollaboratorJson {
3246
return {
3347
avatar_url: this.avatar_url,
3448
id: this._id,
@@ -45,15 +59,7 @@ export class Collaborator {
4559
if (!this._permissions) {
4660
return GitHubRepositoryPermission.None;
4761
}
48-
const permissions = this._permissions;
49-
if (permissions.admin) {
50-
return GitHubRepositoryPermission.Admin;
51-
} else if (permissions.push) {
52-
return GitHubRepositoryPermission.Push;
53-
} else if (permissions.pull) {
54-
return GitHubRepositoryPermission.Pull;
55-
}
56-
throw new Error(`Unsupported permission type by getHighestPermission`);
62+
return projectCollaboratorPermissionsObjectToGitHubRepositoryPermission(this._permissions);
5763
}
5864

5965
get id(): number {

business/enterprise.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ export type EnterpriseSamlExternalIdentityNode = {
2222
};
2323

2424
export default class GitHubEnterprise {
25-
constructor(private providers: IProviders, public slug: string, private administrativeToken: string) {}
25+
constructor(
26+
private providers: IProviders,
27+
public slug: string,
28+
private administrativeToken: string
29+
) {}
2630

2731
async getGitHubLoginForUserPrincipalName(userPrincipalName: string): Promise<string> {
2832
const node = await this.getSamlNodeFromUserPrincipalName(userPrincipalName);

business/githubApps/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ export abstract class CustomAppPurpose implements ICustomAppPurpose {
3333
get isCustomAppPurpose() {
3434
return true;
3535
}
36-
constructor(public id: string, public name: string) {}
36+
constructor(
37+
public id: string,
38+
public name: string
39+
) {}
3740
}
3841

3942
export class CustomAppPurposeOrganizationVariance extends CustomAppPurpose {
4043
fallbackIfNotConfiguredOrganizationName = false;
41-
constructor(public id: string, public name: string, private configurations: IGitHubAppConfiguration[]) {
44+
constructor(
45+
public id: string,
46+
public name: string,
47+
private configurations: IGitHubAppConfiguration[]
48+
) {
4249
super(id, name);
4350
}
4451
getForOrganizationName(organizationName: string) {
@@ -53,7 +60,11 @@ export class CustomAppPurposeOrganizationVariance extends CustomAppPurpose {
5360
}
5461

5562
export class CustomAppPurposeSingleConfiguration extends CustomAppPurpose {
56-
constructor(public id: string, public name: string, private configuration: IGitHubAppConfiguration) {
63+
constructor(
64+
public id: string,
65+
public name: string,
66+
private configuration: IGitHubAppConfiguration
67+
) {
5768
super(id, name);
5869
}
5970

0 commit comments

Comments
 (0)