return interface instead of boolean

Signed-off-by: secustor <sebastian@poxhofer.at>
This commit is contained in:
secustor
2024-01-25 19:32:54 +01:00
parent bb00ed407b
commit 75b51a87b6
6 changed files with 34 additions and 11 deletions
@@ -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)';
}
+7 -1
View File
@@ -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'),
};
}
}
+1
View File
@@ -37,5 +37,6 @@ export type {
ScmIntegration,
ScmIntegrationsFactory,
ScmIntegrationsGroup,
RateLimitInfo,
} from './types';
export type { ScmIntegrationRegistry } from './registry';
+9
View File
@@ -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;
}