MCPcopy
hub / github.com/danger/danger-js / GitLab

Class GitLab

source/platforms/GitLab.ts:19–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17 process.env.DANGER_GITLAB_USE_THREADS === "1" || process.env.DANGER_GITLAB_USE_THREADS === "true"
18
19class GitLab implements Platform {
20 public readonly name: string
21
22 constructor(public readonly api: GitLabAPI) {
23 this.name = "GitLab"
24 }
25
26 getReviewInfo = async (): Promise<any> => {
27 return this.api.getMergeRequestInfo()
28 }
29
30 // returns the `danger.gitlab` object
31 getPlatformReviewDSLRepresentation = async (): Promise<GitLabJSONDSL> => {
32 const mr = await this.getReviewInfo()
33 const commits = await this.api.getMergeRequestCommits()
34 const approvals = await this.api.getMergeRequestApprovals()
35 return {
36 metadata: this.api.repoMetadata,
37 mr,
38 commits,
39 approvals,
40 }
41 }
42 // TODO: test
43 getPlatformGitRepresentation = async (): Promise<GitJSONDSL> => {
44 const diffs = await this.api.getMergeRequestDiffs()
45 const commits = await this.api.getMergeRequestCommits()
46
47 const mappedCommits: GitCommit[] = commits.map((commit) => {
48 return {
49 sha: commit.id,
50 author: {
51 name: commit.author_name,
52 email: commit.author_email as string,
53 date: commit.authored_date as string,
54 },
55 committer: {
56 name: commit.committer_name as string,
57 email: commit.committer_email as string,
58 date: commit.committed_date as string,
59 },
60 message: commit.message,
61 parents: commit.parent_ids as string[],
62 url: `${this.api.projectURL}/commit/${commit.id}`,
63 tree: null,
64 }
65 })
66
67 // XXX: does "renamed_file"/move count is "delete/create", or "modified"?
68 const modified_files: string[] = diffs
69 .filter((diff) => !diff.new_file && !diff.deleted_file)
70 .map((diff) => diff.new_path)
71 const created_files: string[] = diffs.filter((diff) => diff.new_file).map((diff) => diff.new_path)
72 const deleted_files: string[] = diffs.filter((diff) => diff.deleted_file).map((diff) => diff.new_path)
73
74 return {
75 modified_files,
76 created_files,

Callers

nothing calls this directly

Calls 5

inlinePositionParserFunction · 0.90
dangerIDToStringFunction · 0.90
useThreadsFunction · 0.85
structuredDiffForFileMethod · 0.65
getReviewInfoMethod · 0.45

Tested by

no test coverage detected