Skip to content

Commit

Permalink
Oof, there's a lot going on in there. The runner works in another pro…
Browse files Browse the repository at this point in the history
…cess now
  • Loading branch information
notjosh authored and bigkraig committed Apr 9, 2019
1 parent 91ef63a commit c274eb8
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Expand Up @@ -10,7 +10,8 @@
"protocol": "inspector",
"console": "internalConsole",
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/distribution"]
"outFiles": ["${workspaceRoot}/distribution"],
"runtimeExecutable": "/Users/joshua/.nvm/versions/node/v10.12.0/bin/node"
}
]
}
1 change: 1 addition & 0 deletions source/commands/ci/runner.ts
Expand Up @@ -58,6 +58,7 @@ export const runRunner = async (app: SharedCLI, config?: Partial<RunnerConfig>)

if (platform) {
const dangerJSONDSL = await jsonDSLGenerator(platform, source, app)
d({ dangerJSONDSL })
const execConfig: ExecutorOptions = {
stdoutOnly: !platform.supportsCommenting() || app.textOnly,
verbose: app.verbose,
Expand Down
21 changes: 19 additions & 2 deletions source/dsl/DangerDSL.ts
Expand Up @@ -5,6 +5,7 @@ import { GitHubDSL } from "../dsl/GitHubDSL"
import { BitBucketServerDSL, BitBucketServerJSONDSL } from "../dsl/BitBucketServerDSL"
import { DangerUtilsDSL } from "./DangerUtilsDSL"
import { CliArgs } from "../dsl/cli-args"
import { GitLabDSL } from "./GitLabDSL"

/**
* The shape of the JSON passed between Danger and a subprocess. It's built
Expand Down Expand Up @@ -57,6 +58,8 @@ export interface DangerDSLJSONType {
github?: GitHubDSL
/** The data only version of BitBucket Server DSL */
bitbucket_server?: BitBucketServerJSONDSL
/** The data only version of GitLab DSL */
gitlab?: GitLabDSL
/**
* Used in the Danger JSON DSL to pass metadata between
* processes. It will be undefined when used inside the Danger DSL
Expand Down Expand Up @@ -119,12 +122,23 @@ export interface DangerDSLType {
* comments and reviews on the PR, related issues, commits, comments
* and activities.
*
* Strictly speaking, `bitbucket_server` is a nullable type, if you are using
* GitHub then it will be undefined. For the DSL convenience sake though, it
* Strictly speaking, `bitbucket_server` is a nullable type, if you are not using
* BitBucket Server then it will be undefined. For the DSL convenience sake though, it
* is classed as non-nullable
*/
readonly bitbucket_server: BitBucketServerDSL

/**
* The GitLab metadata. This covers things like PR info,
* comments and reviews on the MR, commits, comments
* and activities.
*
* Strictly speaking, `gitlab` is a nullable type, if you are not using
* GitLab then it will be undefined. For the DSL convenience sake though, it
* is classed as non-nullable
*/
readonly gitlab: GitLabDSL

/**
* Functions which are globally useful in most Dangerfiles. Right
* now, these functions are around making sentences of arrays, or
Expand All @@ -138,6 +152,7 @@ export interface DangerDSLType {
export class DangerDSL {
public readonly github?: GitHubDSL
public readonly bitbucket_server?: BitBucketServerDSL
public readonly gitlab?: GitLabDSL

constructor(platformDSL: any, public readonly git: GitJSONDSL, public readonly utils: DangerUtilsDSL, name: string) {
switch (name) {
Expand All @@ -146,6 +161,8 @@ export class DangerDSL {
this.github = platformDSL
case "BitBucketServer":
this.bitbucket_server = platformDSL
case "GitLab":
this.gitlab = platformDSL
}
}
}
67 changes: 57 additions & 10 deletions source/dsl/GitLabDSL.ts
@@ -1,13 +1,29 @@
// TODO: extract out from BitBucket specifically, or create our own type
import { RepoMetaData } from "./BitBucketServerDSL"

// danger.gitlab

export interface GitLabDSL {
metadata: RepoMetaData
// issues: any[]
mr: GitLabMR
// commits: GitLabMRCommit[]
// comments: any[]
}

// ---
// JSON responses from API

export interface GitLabUser {
id: number
name: string
username: string
state: "active"
state: "active" // XXX: other states?
avatar_url: string | null
web_url: string
}

export interface GitLabMRDSLBase {
export interface GitLabMRBase {
/** */
id: number

Expand Down Expand Up @@ -52,15 +68,15 @@ export interface GitLabMRDSLBase {
project_id: number
title: string
description: string
state: "closed"
state: "closed" // XXX: other states?
created_at: string
updated_at: string
due_date: string
start_date: string
web_url: string
}
merge_when_pipeline_succeeds: boolean
merge_status: "can_be_merged"
merge_status: "can_be_merged" // XXX: other statuses?
merge_error: null | null
sha: string
merge_commit_sha: string | null
Expand All @@ -79,7 +95,7 @@ export interface GitLabMRDSLBase {
}
}

export interface GitLabMRDSL extends GitLabMRDSLBase {
export interface GitLabMR extends GitLabMRBase {
squash: boolean
subscribed: boolean
changes_count: string
Expand All @@ -94,7 +110,7 @@ export interface GitLabMRDSL extends GitLabMRDSLBase {
id: number
sha: string
ref: string
status: "success"
status: "success" // XXX: other statuses?
web_url: string
}
diff_refs: {
Expand All @@ -107,7 +123,7 @@ export interface GitLabMRDSL extends GitLabMRDSLBase {
approvals_before_merge: null | null
}

export interface GitLabMRChangeDSL {
export interface GitLabMRChange {
old_path: string
new_path: string
a_mode: string
Expand All @@ -118,11 +134,42 @@ export interface GitLabMRChangeDSL {
deleted_file: boolean
}

export interface GitLabMRChangesDSL extends GitLabMRDSLBase {
changes: GitLabMRChangeDSL[]
export interface GitLabMRChanges extends GitLabMRBase {
changes: GitLabMRChange[]
}

export interface GitLabComment {
id: number
type: "DiffNote" | null // XXX: other types? null means "normal comment"
body: string
attachment: null // XXX: what can an attachment be?
author: GitLabUser
created_at: string
updated_at: string
system: boolean
noteable_id: number
noteable_type: "MergeRequest" // XXX: other types...?
resolvable: boolean
noteable_iid: number
}

export interface GitLabInlineComment extends GitLabComment {
position: {
base_sha: string
start_sha: string
head_sha: string
old_path: string
new_path: string
position_type: "text" // XXX: other types?
old_line: number | null
new_line: number
}
resolvable: boolean
resolved: boolean
resolved_by: GitLabUser | null
}

export interface GitLabMRCommitDSL {
export interface GitLabMRCommit {
id: string
short_id: string
created_at: string
Expand Down
52 changes: 37 additions & 15 deletions source/platforms/GitLab.ts
Expand Up @@ -3,6 +3,7 @@ import { Platform, Comment } from "./platform"
import { readFileSync } from "fs"
import { GitDSL, GitJSONDSL } from "../dsl/GitDSL"
import { GitCommit } from "../dsl/Commit"
import { GitLabDSL } from "../dsl/GitLabDSL"

class GitLab implements Platform {
public readonly name: string
Expand All @@ -11,15 +12,28 @@ class GitLab implements Platform {
this.name = "GitLab"
}

async getReviewInfo(): Promise<any> {
return this.api.getPullRequestInfo()
getReviewInfo = async (): Promise<any> => {
return this.api.getMergeRequestInfo()
}

async getPlatformReviewDSLRepresentation(): Promise<any> {
return {}
// returns the `danger.gitlab` object
getPlatformReviewDSLRepresentation = async (): Promise<GitLabDSL> => {
const mr = await this.getReviewInfo()
// const commits = await this.api.getMergeRequestCommits()
// const comments: any[] = [] //await this.api.getMergeRequestComments()
// const activities = {} //await this.api.getPullRequestActivities()
// const issues: any[] = [] //await this.api.getIssues()

return {
metadata: this.api.repoMetadata,
// issues,
mr,
// commits,
// comments,
}
}

async getPlatformGitRepresentation(): Promise<GitJSONDSL> {
getPlatformGitRepresentation = async (): Promise<GitJSONDSL> => {
const changes = await this.api.getMergeRequestChanges()
const commits = await this.api.getMergeRequestCommits()

Expand Down Expand Up @@ -57,17 +71,25 @@ class GitLab implements Platform {
modified_files,
created_files,
deleted_files,
commits: mappedCommits,
// diffForFile: async () => ({ before: "", after: "", diff: "", added: "", removed: "" }),
// structuredDiffForFile: async () => ({ chunks: [] }),
// JSONDiffForFile: async () => ({} as any),
// JSONPatchForFile: async () => ({} as any),
commits: mappedCommits,
// linesOfCode: async () => 0,
}
}

async getInlineComments(_: string): Promise<Comment[]> {
return []
getInlineComments = async (_: string): Promise<Comment[]> => {
const comments = (await this.api.getMergeRequestInlineComments()).map(comment => {
return {
id: `${comment.id}`,
body: comment.body,
ownedByDanger: comment.author.id === 1,
}
})

return comments
}

supportsCommenting() {
Expand All @@ -78,31 +100,31 @@ class GitLab implements Platform {
return true
}

async updateOrCreateComment(_dangerID: string, _newComment: string): Promise<string> {
updateOrCreateComment = async (_dangerID: string, _newComment: string): Promise<string> => {
return "https://gitlab.com/group/project/merge_requests/154#note_132143425"
}

async createComment(_comment: string): Promise<any> {
createComment = async (_comment: string): Promise<any> => {
return true
}

async createInlineComment(_git: GitDSL, _comment: string, _path: string, _line: number): Promise<any> {
createInlineComment = async (_git: GitDSL, _comment: string, _path: string, _line: number): Promise<any> => {
return true
}

async updateInlineComment(_comment: string, _commentId: string): Promise<any> {
updateInlineComment = async (_comment: string, _commentId: string): Promise<any> => {
return true
}

async deleteInlineComment(_id: string): Promise<boolean> {
deleteInlineComment = async (_id: string): Promise<boolean> => {
return true
}

async deleteMainComment(): Promise<boolean> {
deleteMainComment = async (): Promise<boolean> => {
return true
}

async updateStatus(): Promise<boolean> {
updateStatus = async (): Promise<boolean> => {
return true
}

Expand Down
Empty file.

0 comments on commit c274eb8

Please sign in to comment.