return interface instead of boolean
Signed-off-by: secustor <sebastian@poxhofer.at>
This commit is contained in:
@@ -333,7 +333,7 @@ export class GithubUrlReader implements UrlReader {
|
||||
// GitHub returns a 403 response with a couple of headers indicating rate
|
||||
// limit status. See more in the GitHub docs:
|
||||
// https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
|
||||
if (this.integration.isRateLimited(response)) {
|
||||
if (this.integration.parseRateLimitInfo(response).isRateLimited) {
|
||||
message += ' (rate limit exceeded)';
|
||||
}
|
||||
|
||||
|
||||
@@ -568,7 +568,7 @@ export class GithubIntegration implements ScmIntegration {
|
||||
// (undocumented)
|
||||
static factory: ScmIntegrationsFactory<GithubIntegration>;
|
||||
// (undocumented)
|
||||
isRateLimited(response: ConsumedResponse): boolean;
|
||||
parseRateLimitInfo(response: ConsumedResponse): RateLimitInfo;
|
||||
// (undocumented)
|
||||
resolveEditUrl(url: string): string;
|
||||
// (undocumented)
|
||||
@@ -697,6 +697,12 @@ export type PersonalAccessTokenCredential = AzureCredentialBase & {
|
||||
personalAccessToken: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export interface RateLimitInfo {
|
||||
// (undocumented)
|
||||
isRateLimited: boolean;
|
||||
}
|
||||
|
||||
// @public
|
||||
export function readAwsS3IntegrationConfig(
|
||||
config: Config,
|
||||
|
||||
@@ -95,11 +95,13 @@ describe('GithubIntegration', () => {
|
||||
const headers = new Headers({
|
||||
'x-ratelimit-remaining': ratelimitRemaining,
|
||||
});
|
||||
const result = integration.isRateLimited({
|
||||
const result = integration.parseRateLimitInfo({
|
||||
status,
|
||||
headers,
|
||||
} as Response);
|
||||
expect(expected).toBe(result);
|
||||
expect(result).toMatchObject({
|
||||
isRateLimited: expected,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
|
||||
import { basicIntegrations, defaultScmResolveUrl } from '../helpers';
|
||||
import { ScmIntegration, ScmIntegrationsFactory } from '../types';
|
||||
import {
|
||||
RateLimitInfo,
|
||||
ScmIntegration,
|
||||
ScmIntegrationsFactory,
|
||||
} from '../types';
|
||||
import {
|
||||
GithubIntegrationConfig,
|
||||
readGithubIntegrationConfigs,
|
||||
@@ -67,12 +71,13 @@ export class GithubIntegration implements ScmIntegration {
|
||||
return replaceGithubUrlType(url, 'edit');
|
||||
}
|
||||
|
||||
isRateLimited(response: ConsumedResponse): boolean {
|
||||
return (
|
||||
response.status === 429 ||
|
||||
(response.status === 403 &&
|
||||
response.headers.get('x-ratelimit-remaining') === '0')
|
||||
);
|
||||
parseRateLimitInfo(response: ConsumedResponse): RateLimitInfo {
|
||||
return {
|
||||
isRateLimited:
|
||||
response.status === 429 ||
|
||||
(response.status === 403 &&
|
||||
response.headers.get('x-ratelimit-remaining') === '0'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,5 +37,6 @@ export type {
|
||||
ScmIntegration,
|
||||
ScmIntegrationsFactory,
|
||||
ScmIntegrationsGroup,
|
||||
RateLimitInfo,
|
||||
} from './types';
|
||||
export type { ScmIntegrationRegistry } from './registry';
|
||||
|
||||
@@ -108,3 +108,12 @@ export interface ScmIntegrationsGroup<T extends ScmIntegration> {
|
||||
export type ScmIntegrationsFactory<T extends ScmIntegration> = (options: {
|
||||
config: Config;
|
||||
}) => ScmIntegrationsGroup<T>;
|
||||
|
||||
/**
|
||||
* Encapsulates information about the RateLimit state
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface RateLimitInfo {
|
||||
isRateLimited: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user