Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
INT-10098 - ingest project labels (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
RonaldEAM authored Dec 6, 2023
1 parent 294d514 commit 82f8874
Show file tree
Hide file tree
Showing 9 changed files with 2,487 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/jupiterone.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The following entities are created:
| Commit | `gitlab_commit` | `CodeCommit` |
| Finding | `gitlab_finding` | `Finding` |
| Group | `gitlab_group` | `Group` |
| Label | `gitlab_label` | `Record` |
| Merge Request | `gitlab_merge_request` | `CodeReview`, `PR` |
| Project | `gitlab_project` | `CodeRepo`, `Project` |
| User | `gitlab_user` | `User` |
Expand All @@ -103,6 +104,7 @@ The following relationships are created:
| `gitlab_group` | **HAS** | `gitlab_user` |
| `gitlab_merge_request` | **HAS** | `gitlab_commit` |
| `gitlab_project` | **HAS** | `gitlab_finding` |
| `gitlab_project` | **HAS** | `gitlab_label` |
| `gitlab_project` | **HAS** | `gitlab_merge_request` |
| `gitlab_project` | **HAS** | `gitlab_user` |
| `gitlab_user` | **APPROVED** | `gitlab_merge_request` |
Expand Down
12 changes: 12 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const Steps = {
BUILD_PROJECT_HAS_PR: 'build-project-merge-request-relationships',
BUILD_USER_OPENED_PR: 'build-user-opened-merge-request-relationships',
BUILD_USER_APPROVED_PR: 'build-user-approved-merge-request-relationships',
PROJECT_LABELS: 'fetch-project-labels',
};

export const Entities = {
Expand Down Expand Up @@ -57,6 +58,11 @@ export const Entities = {
_type: 'gitlab_project',
_class: ['CodeRepo', 'Project'],
},
LABEL: {
resourceName: 'Label',
_type: 'gitlab_label',
_class: ['Record'],
},
};

export const Relationships = {
Expand Down Expand Up @@ -126,4 +132,10 @@ export const Relationships = {
_class: RelationshipClass.HAS,
targetType: Entities.COMMIT._type,
},
PROJECT_HAS_LABEL: {
_type: 'gitlab_project_has_label',
sourceType: Entities.PROJECT._type,
_class: RelationshipClass.HAS,
targetType: Entities.LABEL._type,
},
};
33 changes: 33 additions & 0 deletions src/converters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GitLabProject,
GitLabUser,
GitLabFinding,
GitlabLabel,
} from '../provider/types';
import { getCommitWebLinkFromMergeRequest } from '../util/mergeRequest';

Expand Down Expand Up @@ -295,3 +296,35 @@ export function getNumericSeverity(severity: string | undefined) {
return undefined;
}
}

export function createLabelEntity(label: GitlabLabel): Entity {
const key = createLabelEntityIdentifier(label.id);

return createIntegrationEntity({
entityData: {
source: label,
assign: {
_key: key,
_type: Entities.LABEL._type,
_class: Entities.LABEL._class,
id: label.id.toString(),
displayName: label.name,
name: label.name,
description: label.description ?? undefined,
color: label.color,
textColor: label.text_color,
openIssuesCount: label.open_issues_count,
closedIssuesCount: label.closed_issues_count,
openMergeRequestsCount: label.open_merge_requests_count,
subscribed: label.subscribed,
priority: label.priority,
},
},
});
}

const LABEL_ID_PREFIX = 'gitlab-label';

export function createLabelEntityIdentifier(id: number): string {
return `${LABEL_ID_PREFIX}:${id}`;
}
12 changes: 12 additions & 0 deletions src/provider/GitlabClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
GitLabProject,
GitLabUser,
GitLabUserRef,
GitlabLabel,
} from './types';

/**
Expand Down Expand Up @@ -145,6 +146,17 @@ export class GitlabClient {
);
}

async iterateProjectLabels(
projectId: number,
iteratee: ResourceIteratee<GitlabLabel>,
) {
return this.iterateResources(`/projects/${projectId}/labels`, iteratee, {
params: {
with_counts: 'true',
},
});
}

/**
* https://docs.gitlab.com/ee/api/merge_request_approvals.html#get-configuration-1
*/
Expand Down
15 changes: 15 additions & 0 deletions src/provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,18 @@ export type GitLabMergeRequestApproval = Opaque<
any,
'GitLabMergeRequestApproval'
>;

export interface GitlabLabel {
id: number;
color: string;
text_color: string;
name: string;
description?: string | null;
description_html?: string | null;
open_issues_count: number;
closed_issues_count: number;
open_merge_requests_count: number;
subscribed: boolean;
priority?: number;
is_project_label?: boolean | null;
}
Loading

0 comments on commit 82f8874

Please sign in to comment.