Skip to content

Commit

Permalink
feat(integration): add github label import logic
Browse files Browse the repository at this point in the history
- adjust GithubIssue models to include a label array -
  moves the label element from GithubIssue to GithubIssueReduced (indirectly in GithubIssue still through extension) (`github-issue.model.ts`)
- get them from the graphQL API (`gihub-issue-map.util.ts`)
- add labels with a private helper function as tags (with import of name and color)
  using TagService utilities (`gihub-common-interfaces.service.ts`)

part of the implementation regarding johannesjo#2866
  • Loading branch information
MiragonMx committed Aug 14, 2024
1 parent 5d67655 commit 89f0733
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import { GithubApiService } from './github-api.service';
import { ProjectService } from '../../../project/project.service';
import { SearchResultItem } from '../../issue.model';
import { GithubCfg } from './github.model';
import { GithubIssue, GithubIssueReduced } from './github-issue/github-issue.model';
import {
GithubIssue,
GithubIssueReduced,
GithubLabel,
} from './github-issue/github-issue.model';
import { truncate } from '../../../../util/truncate';
import { getTimestamp } from '../../../../util/get-timestamp';
import { isGithubEnabled } from './is-github-enabled.util';
import { GITHUB_INITIAL_POLL_DELAY, GITHUB_POLL_INTERVAL } from './github.const';
import { TagService } from '../../../tag/tag.service';

@Injectable({
providedIn: 'root',
Expand All @@ -20,6 +25,7 @@ export class GithubCommonInterfacesService implements IssueServiceInterface {
constructor(
private readonly _githubApiService: GithubApiService,
private readonly _projectService: ProjectService,
private _tagService: TagService,
) {}

pollTimer$: Observable<number> = timer(GITHUB_INITIAL_POLL_DELAY, GITHUB_POLL_INTERVAL);
Expand Down Expand Up @@ -156,6 +162,7 @@ export class GithubCommonInterfacesService implements IssueServiceInterface {
// NOTE: we use Date.now() instead to because updated does not account for comments
issueLastUpdated: new Date(issue.updated_at).getTime(),
isDone: this._isIssueDone(issue),
tagIds: this._getGithubLabelsAsTags(issue.labels),
};
}

Expand All @@ -174,4 +181,12 @@ export class GithubCommonInterfacesService implements IssueServiceInterface {
private _isIssueDone(issue: GithubIssueReduced): boolean {
return issue.state === 'closed';
}

private _getGithubLabelsAsTags(labels: GithubLabel[]): string[] {
const getTagIds: string[] = [];
labels.forEach((label: GithubLabel) => {
getTagIds.push(this._tagService.addTag({ title: label.name, color: label.color }));
}, this);
return getTagIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const mapGithubReducedIssueFromGraphQL = ({ node }: any): GithubIssueRedu
title: node.title,
state: node.state,
updated_at: node.updatedAt,
labels: node.labels,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export type GithubIssueReduced = Readonly<{
id: number;
number: number;

// to include labels as tags
labels: GithubLabel[];

// removed
// node_id: string;
// assignees: GithubOriginalUser[];
Expand All @@ -40,7 +43,7 @@ export type GithubIssue = GithubIssueReduced &
events_url: string;
html_url: string;
body: string;
labels: GithubLabel[];
// labels: GithubLabel[];
milestone: GithubMileStone;
locked: boolean;
active_lock_reason: string;
Expand Down

0 comments on commit 89f0733

Please sign in to comment.