-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organization: get Copilot seat assignments
Retrieves the list of Copilot basics when the organization has Copilot for Business attachments. Do note that this API only works to page, slowly, at scale to a point - after 400 pages I am not able to get results due to a hard cap of sorts here, so need to rely on other methods to get the info.
- Loading branch information
1 parent
d8195d4
commit 4471969
Showing
6 changed files
with
264 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// Copyright (c) Microsoft. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
import { | ||
IGetAuthorizationHeader, | ||
IOperationsInstance, | ||
IPagedCacheOptions, | ||
IPurposefulGetAuthorizationHeader, | ||
throwIfNotGitHubCapable, | ||
} from '../interfaces'; | ||
import type { CollectionCopilotSeatsOptions } from '../lib/github/collections'; | ||
import { AppPurpose, AppPurposeTypes } from './githubApps'; | ||
import { CacheDefault, getMaxAgeSeconds, getPageSize } from './operations/core'; | ||
import { Organization } from './organization'; | ||
|
||
export type CopilotSeatData = { | ||
assignee: { | ||
avatar_url: string; | ||
id: number; | ||
login: string; | ||
}; | ||
created_at: string; | ||
updated_at: string; | ||
last_activity_at: string; | ||
last_activity_editor: string; | ||
}; | ||
|
||
export class OrganizationCopilot { | ||
constructor( | ||
private organization: Organization, | ||
private getSpecificAuthorizationHeader: IPurposefulGetAuthorizationHeader, | ||
private operations: IOperationsInstance | ||
) {} | ||
|
||
async getSeatActivity( | ||
options?: IPagedCacheOptions, | ||
appPurpose: AppPurposeTypes = AppPurpose.Data | ||
): Promise<CopilotSeatData[]> { | ||
options = options || {}; | ||
const operations = throwIfNotGitHubCapable(this.operations); | ||
const getAuthorizationHeader = this.getSpecificAuthorizationHeader.bind( | ||
this, | ||
appPurpose | ||
) as IGetAuthorizationHeader; | ||
const github = operations.github; | ||
const parameters: CollectionCopilotSeatsOptions = { | ||
org: this.organization.name, | ||
per_page: getPageSize(operations), | ||
}; | ||
const caching = { | ||
maxAgeSeconds: getMaxAgeSeconds(operations, CacheDefault.orgMembersStaleSeconds, options), | ||
backgroundRefresh: true, | ||
pageRequestDelay: options.pageRequestDelay, | ||
}; | ||
if (options && options.backgroundRefresh === false) { | ||
caching.backgroundRefresh = false; | ||
} | ||
(caching as any).pageLimit = 10; | ||
const seats = (await github.collections.getOrganizationCopilotSeats( | ||
getAuthorizationHeader, | ||
parameters, | ||
caching | ||
)) as CopilotSeatData[]; | ||
return seats; | ||
} | ||
} |
Oops, something went wrong.