-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e55f5ca
commit 676d7b5
Showing
2 changed files
with
112 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright (c) Microsoft. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
import { NextFunction, Response, Router } from 'express'; | ||
import asyncHandler from 'express-async-handler'; | ||
|
||
import { ReposAppRequest, AccountJsonFormat } from '../../interfaces'; | ||
import { CreateError, getProviders } from '../../transitional'; | ||
|
||
const router: Router = Router(); | ||
|
||
router.get( | ||
'/:login', | ||
asyncHandler(async (req: ReposAppRequest, res: Response, next: NextFunction) => { | ||
const { operations } = getProviders(req); | ||
const login = req.params.login as string; | ||
try { | ||
if (!login) { | ||
throw CreateError.ParameterRequired('login'); | ||
} | ||
const accountInfo = await operations.getAccountByUsername(login); | ||
return res.json(accountInfo.asJson(AccountJsonFormat.GitHubExtended)) as any as void; | ||
} catch (error) { | ||
return next(error); | ||
} | ||
}) | ||
); | ||
|
||
router.use('*', (req, res: Response, next: NextFunction) => { | ||
return next(CreateError.NotFound('/users: no API found')); | ||
}); | ||
|
||
export default router; |
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,77 @@ | ||
// | ||
// Copyright (c) Microsoft. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
import { GitHubRepositoryPermission, GitHubSimpleAccount } from '../interfaces'; | ||
import * as common from './common'; | ||
import { Repository } from './repository'; | ||
|
||
const primaryProperties = ['inviter', 'invitee', 'permissions', 'created_at', 'html_url', 'node_id']; | ||
|
||
export type RepositoryInvitationClientJson = { | ||
inviter: { | ||
id: number; | ||
login: string; | ||
}; | ||
invitee: { | ||
id: number; | ||
login: string; | ||
}; | ||
permissions: GitHubRepositoryPermission; | ||
created_at: string; | ||
html_url: string; | ||
// node_id: string; | ||
}; | ||
|
||
export class RepositoryInvitation { | ||
public static PrimaryProperties = primaryProperties; | ||
|
||
private _inviter: GitHubSimpleAccount; | ||
private _invitee: GitHubSimpleAccount; | ||
private _permissions: GitHubRepositoryPermission; | ||
private _html_url: string; | ||
private _created_at: string; | ||
|
||
constructor( | ||
private repository: Repository, | ||
entity: unknown | ||
) { | ||
if (entity) { | ||
common.assignKnownFieldsPrefixed(this, entity, 'invitation', primaryProperties); | ||
} | ||
} | ||
|
||
asJson(): RepositoryInvitationClientJson { | ||
return { | ||
invitee: this.invitee, | ||
inviter: this.inviter, | ||
permissions: this.permission, | ||
html_url: this.invitationUrl, | ||
created_at: this._created_at, | ||
}; | ||
} | ||
|
||
get permission(): GitHubRepositoryPermission { | ||
return this._permissions; | ||
} | ||
|
||
// getHighestPermission() { | ||
// if (!this._permissions) { | ||
// return GitHubRepositoryPermission.None; | ||
// } | ||
// return projectCollaboratorPermissionsObjectToGitHubRepositoryPermission(this._permissions); | ||
// } | ||
|
||
get inviter(): GitHubSimpleAccount { | ||
return this._inviter; | ||
} | ||
|
||
get invitee(): GitHubSimpleAccount { | ||
return this._invitee; | ||
} | ||
|
||
get invitationUrl(): string { | ||
return this._html_url; | ||
} | ||
} |