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

chore: added explicit json response parsing to catch an error #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ This Source is capable of syncing the following Streams:
* [Organization](https://github.com/linear/linear/blob/master/packages/sdk/src/schema.graphql#L7098)
* [Teams](https://github.com/linear/linear/blob/master/packages/sdk/src/schema.graphql#L10249)
* [User](https://github.com/linear/linear/blob/master/packages/sdk/src/schema.graphql#L11949)
* [Milestone](https://github.com/linear/linear/blob/master/packages/sdk/src/schema.graphql#L4205)
* [Project](https://github.com/linear/linear/blob/master/packages/sdk/src/schema.graphql#L7667)
* [Integration Resource](https://github.com/linear/linear/blob/master/packages/sdk/src/schema.graphql#L2297)
* [Attachment](https://github.com/linear/linear/blob/master/packages/sdk/src/schema.graphql#L144)
Expand Down
26 changes: 0 additions & 26 deletions resources/schemas/milestone.json

This file was deleted.

3 changes: 0 additions & 3 deletions resources/schemas/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
"organizationId": {
"type": "string"
},
"milestoneId": {
"type": ["null", "string"]
},
"lastProjectUpdatePromptAt": {
"type": ["null", "string"]
},
Expand Down
27 changes: 17 additions & 10 deletions src/client/LinearClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios";
import { AirbyteLogger } from "faros-airbyte-cdk/lib";
import {
Attachment,
AuditEntry,
Expand All @@ -8,7 +9,6 @@ import {
IssueHistory,
IssueLabel,
IssueRelation,
Milestone,
Organization,
Project,
ProjectLink,
Expand Down Expand Up @@ -40,7 +40,6 @@ export type EntityType =
| "teamkey"
| "teammembership"
| "user"
| "milestone"
| "project"
| "projectupdate"
| "projectlink"
Expand All @@ -57,7 +56,10 @@ export type EntityType =
* Thin client on top of the rest export api to fetch different resources.
*/
export class LinearClient {
public constructor(private readonly config: Config) {}
public constructor(
private readonly config: Config,
private readonly logger: AirbyteLogger
) {}

/**
* @returns List of all issues in organization.
Expand Down Expand Up @@ -94,13 +96,6 @@ export class LinearClient {
return await this.fetchEntities<TeamMembership>("teammembership");
}

/**
* @returns List of all milestones in organization.
*/
public async milestones(): Promise<Milestone[]> {
return await this.fetchEntities<Milestone>("milestone");
}

/**
* @returns List of all projects in organization.
*/
Expand Down Expand Up @@ -209,6 +204,18 @@ export class LinearClient {
method: "GET",
baseURL: LINEAR_API_BASE_URL,
url: entityType,
transformResponse: (data) => {
try {
return JSON.parse(data);
} catch (error) {
this.logger.error(
`Failed to parse data as JSON.
Data:${data},
Error: ${JSON.stringify(error, null, 2)}`
);
throw error;
}
},
headers: {
Authorization: this.config.apiKey,
},
Expand Down
11 changes: 0 additions & 11 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@ export interface IssueLabel {
creatorId?: null | string;
}

export interface Milestone {
id?: string;
createdAt?: string;
updatedAt?: string;
archivedAt?: null | string;
name?: string;
organizationId?: string;
sortOrder?: number;
}

export interface Project {
id?: string;
createdAt?: string;
Expand All @@ -186,7 +176,6 @@ export interface Project {
leadId?: null | string;
memberIds?: string[];
organizationId?: string;
milestoneId?: string;
lastProjectUpdatePromptAt?: null | string;
startDate?: string;
targetDate?: string;
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Document } from "./streams/document";
import { IssueHistory } from "./streams/issueHistory";
import { IssueLabel } from "./streams/issueLabel";
import { IssueRelation } from "./streams/issueRelation";
import { Milestone } from "./streams/milestone";
import { Organization } from "./streams/organization";
import { Project } from "./streams/project";
import { ProjectLink } from "./streams/projectLink";
Expand Down Expand Up @@ -49,7 +48,7 @@ class LinearSource extends AirbyteSourceBase {
public async checkConnection(
config: AirbyteConfig
): Promise<[boolean, VError]> {
const client = new LinearClient({ apiKey: config.apiKey });
const client = new LinearClient({ apiKey: config.apiKey }, this.logger);
try {
await client.checkConnection();
return [true, null];
Expand All @@ -59,15 +58,14 @@ class LinearSource extends AirbyteSourceBase {
}

public streams(config: AirbyteConfig): AirbyteStreamBase[] {
const client = new LinearClient({ apiKey: config.apiKey });
const client = new LinearClient({ apiKey: config.apiKey }, this.logger);
return [
new Issue(this.logger, client),
new Organization(this.logger, client),
new Team(this.logger, client),
new TeamKey(this.logger, client),
new TeamMembership(this.logger, client),
new User(this.logger, client),
new Milestone(this.logger, client),
new Project(this.logger, client),
new ProjectUpdate(this.logger, client),
new ProjectLink(this.logger, client),
Expand Down
30 changes: 0 additions & 30 deletions src/streams/milestone.ts

This file was deleted.

17 changes: 0 additions & 17 deletions test_files/full_configured_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,6 @@
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "milestone",
"json_schema": {},
"supported_sync_modes": [
"full_refresh"
],
"source_defined_cursor": true,
"source_defined_primary_key": [
[
"id"
]
]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "project",
Expand Down