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

Popuplate GitHub pull request labels #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export abstract class AzurePipelineConverter extends Converter {

return {
name: toLower(parts[1]),
uid: toLower(parts[1]),
organization: {
uid: toLower(parts[0]),
source: repo.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {DestinationModel, DestinationRecord} from '../converter';
import {GitHubConverter} from './common';

export class IssueLabels extends GitHubConverter {
readonly destinationModels: ReadonlyArray<DestinationModel> = ['tms_Label'];
readonly destinationModels: ReadonlyArray<DestinationModel> = [
'tms_Label',
'vsc_Label',
];

async convert(
record: AirbyteRecord
Expand All @@ -15,6 +18,10 @@ export class IssueLabels extends GitHubConverter {
model: 'tms_Label',
record: {name: label.name},
},
{
model: 'vcs_Label',
record: {name: label.name},
},
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Issues extends GitHubConverter {
'tms_TaskBoardRelationship',
'tms_TaskTag',
'tms_User',
'vcs_PullRequestLabel',
];

private readonly issueLabelsStream = new StreamName('github', 'issue_labels');
Expand All @@ -25,7 +26,7 @@ export class Issues extends GitHubConverter {
return [this.issueLabelsStream];
}

async convert(
private async convertIssue(
record: AirbyteRecord,
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
Expand All @@ -34,13 +35,6 @@ export class Issues extends GitHubConverter {
const res: DestinationRecord[] = [];
const uid = `${issue.id}`;

// GitHub's REST API v3 considers every pull request an issue,
// but not every issue is a pull request. Will skip pull requests
// since we pull them separately
if (issue.pull_request) {
return res;
}

const user = GitHubCommon.tms_User(issue?.user, source);
if (user) res.push(user);

Expand All @@ -58,16 +52,7 @@ export class Issues extends GitHubConverter {
}
});

const issueLabelsStream = this.issueLabelsStream.asString;
for (const labelNode of issue.labels) {
const label = ctx.get(issueLabelsStream, String(labelNode.id));
const name = label?.record?.data?.name;
if (!name) continue;
res.push({
model: 'tms_TaskTag',
record: {task: {uid, source}, label: {name}},
});
}
this.convertLabels(record, ctx, res);

// Github issues only have state either open or closed
const category = issue.state === 'open' ? 'Todo' : 'Done';
Expand Down Expand Up @@ -105,4 +90,49 @@ export class Issues extends GitHubConverter {

return res;
}

private async convertPullRequest(
record: AirbyteRecord,
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const res: DestinationRecord[] = [];

this.convertLabels(record, ctx, res);

return res;
}

private convertLabels(
record: AirbyteRecord,
ctx: StreamContext,
result: DestinationRecord[]
): void {
const issue = record.record.data;
const uid = `${issue.id}`;
const source = this.streamName.source;
const issueLabelsStream = this.issueLabelsStream.asString;

for (const labelNode of issue.labels) {
const label = ctx.get(issueLabelsStream, String(labelNode.id));
const name = label?.record?.data?.name;
if (!name) continue;
result.push({
model: issue.pull_request ? 'vcs_PullRequestLabel' : 'tms_TaskTag',
record: {pullRequest: {uid, source}, label: {name}},
});
}
}

async convert(
record: AirbyteRecord,
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const issue = record.record.data;

if (issue.pull_reuqest) {
return this.convertPullRequest(record, ctx);
} else {
return this.convertIssue(record, ctx);
}
}
}
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.