Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove node-fetch dependency #212

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"graphql": "^16.6.0",
"js-yaml": "^4.1.0",
"nestjs-pino": "^3.1.1",
"node-fetch": "2",
"pino": "^8.4.2",
"pino-http": "^7.0.0",
"pino-pretty": "^9.1.0",
Expand Down
1 change: 0 additions & 1 deletion services/bots/src/cla-sign/cla-sign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { createAppAuth } from '@octokit/auth-app';
import { DynamoDB } from 'aws-sdk';
import fetch from 'node-fetch';
import { GithubClient } from '../github-webhook/github-webhook.model';

export class ServiceRequestError extends ServiceError {}
Expand Down
3 changes: 0 additions & 3 deletions services/bots/src/discord/commands/home-assistant/versions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import fetch from 'node-fetch';

import { getVersionInfo } from '@lib/common';
import { EmbedBuilder } from 'discord.js';
import { CommandHandler, DiscordCommandClass } from '../../discord.decorator';
import {
Expand Down
1 change: 0 additions & 1 deletion services/bots/src/discord/services/common/message-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import yaml from 'js-yaml';

import { Injectable } from '@nestjs/common';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { Injectable } from '@nestjs/common';

export interface ComponentData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { Injectable } from '@nestjs/common';

export interface IntegrationData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { Injectable } from '@nestjs/common';

interface Redirect {
Expand Down
2 changes: 0 additions & 2 deletions services/bots/src/github-webhook/handlers/month_of_wth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

import { PullRequest, PullRequestOpenedEvent } from '@octokit/webhooks-types';
import { EventType, Organization } from '../github-webhook.const';
import { WebhookContext } from '../github-webhook.model';
Expand Down
2 changes: 0 additions & 2 deletions services/bots/src/github-webhook/utils/integration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

export enum QualityScale {
NO_SCORE = 'no score',
SILVER = 'silver',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import fetch from 'node-fetch';

import { WebhookContext } from '../../../../../services/bots/src/github-webhook/github-webhook.model';
import { mockWebhookContext } from '../../../../utils/test_context';
import { loadJsonFixture } from '../../../../utils/fixture';
import { IssueCommentCommands } from '../../../../../services/bots/src/github-webhook/handlers/issue_comment_commands/handler';
import { IssueCommentCreatedEvent } from '@octokit/webhooks-types';
import { EventType } from '../../../../../services/bots/src/github-webhook/github-webhook.const';

// Globally mock fetch
jest.mock('node-fetch', () => jest.fn());
fetch.mockImplementation(() =>
Promise.resolve({ json: () => Promise.resolve({ codeowners: ['@test'] }) }),
);

describe('IssueCommentCommands', () => {
let handler: IssueCommentCommands;
let mockContext: WebhookContext<IssueCommentCreatedEvent>;
let mockedFetch: ReturnType<typeof jest.fn>;

beforeEach(function () {
mockedFetch = jest.fn(global.fetch);
mockedFetch.mockImplementation(() =>
Promise.resolve({
json: () => Promise.resolve({ codeowners: ['@test'] }),
} as unknown as Response),
);
(global.fetch as unknown) = mockedFetch;
handler = new IssueCommentCommands();
mockContext = mockWebhookContext<IssueCommentCreatedEvent>({
eventType: EventType.ISSUE_COMMENT_CREATED,
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('IssueCommentCommands', () => {
);
});
it('not by codeowner', async () => {
fetch.mockImplementation(() =>
mockedFetch.mockImplementation(() =>
Promise.resolve({ json: () => Promise.resolve({ codeowners: ['@test'] }) }),
);
mockContext.payload.comment.user.login = 'other';
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7093,7 +7093,7 @@ __metadata:
languageName: node
linkType: hard

"node-fetch@npm:2, node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7":
"node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7":
version: 2.6.7
resolution: "node-fetch@npm:2.6.7"
dependencies:
Expand Down Expand Up @@ -8223,7 +8223,6 @@ __metadata:
jest: ^29.2.1
js-yaml: ^4.1.0
nestjs-pino: ^3.1.1
node-fetch: 2
pino: ^8.4.2
pino-http: ^7.0.0
pino-pretty: ^9.1.0
Expand Down