Skip to content

Commit

Permalink
Generally the pulling/reading works, to the point of commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
notjosh authored and bigkraig committed Apr 9, 2019
1 parent c274eb8 commit 8ef0581
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 13 deletions.
28 changes: 27 additions & 1 deletion source/dsl/GitLabDSL.ts
Expand Up @@ -7,8 +7,9 @@ export interface GitLabDSL {
metadata: RepoMetaData
// issues: any[]
mr: GitLabMR
// commits: GitLabMRCommit[]
commits: GitLabMRCommit[]
// comments: any[]
utils: {}
}

// ---
Expand All @@ -23,6 +24,31 @@ export interface GitLabUser {
web_url: string
}

export interface GitLabUserProfile extends GitLabUser {
created_at: string
bio: string | null
location: string | null
public_email: string
skype: string
linkedin: string
twitter: string
website_url: string
organization: string
last_sign_in_at: string
confirmed_at: string
theme_id: number
last_activity_on: string
color_scheme_id: number
projects_limit: number
current_sign_in_at: string
identities: [{ provider: string; extern_uid: string }]
can_create_group: boolean
can_create_project: boolean
two_factor_enabled: boolean
external: boolean
private_profile: boolean
}

export interface GitLabMRBase {
/** */
id: number
Expand Down
23 changes: 19 additions & 4 deletions source/platforms/GitLab.ts
Expand Up @@ -5,6 +5,9 @@ import { GitDSL, GitJSONDSL } from "../dsl/GitDSL"
import { GitCommit } from "../dsl/Commit"
import { GitLabDSL } from "../dsl/GitLabDSL"

import { debug } from "../debug"
const d = debug("GitLab")

class GitLab implements Platform {
public readonly name: string

Expand All @@ -19,7 +22,7 @@ class GitLab implements Platform {
// returns the `danger.gitlab` object
getPlatformReviewDSLRepresentation = async (): Promise<GitLabDSL> => {
const mr = await this.getReviewInfo()
// const commits = await this.api.getMergeRequestCommits()
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()
Expand All @@ -28,8 +31,9 @@ class GitLab implements Platform {
metadata: this.api.repoMetadata,
// issues,
mr,
// commits,
commits,
// comments,
utils: {},
}
}

Expand Down Expand Up @@ -80,15 +84,19 @@ class GitLab implements Platform {
}
}

getInlineComments = async (_: string): Promise<Comment[]> => {
getInlineComments = async (dangerID: string): Promise<Comment[]> => {
const dangerUserID = (await this.api.getUser()).id

const comments = (await this.api.getMergeRequestInlineComments()).map(comment => {
return {
id: `${comment.id}`,
body: comment.body,
ownedByDanger: comment.author.id === 1,
ownedByDanger: comment.author.id === dangerUserID && comment.body.includes(dangerID),
}
})

console.log({ comments })

return comments
}

Expand All @@ -101,30 +109,37 @@ class GitLab implements Platform {
}

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

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

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

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

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

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

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

Expand Down
26 changes: 21 additions & 5 deletions source/platforms/gitlab/GitLabAPI.ts
Expand Up @@ -7,6 +7,7 @@ import {
GitLabMRCommit,
GitLabInlineComment,
GitLabComment,
GitLabUserProfile,
} from "../../dsl/GitLabDSL"

import { Gitlab } from "gitlab"
Expand All @@ -18,6 +19,7 @@ class GitLabAPI {
fetch: typeof fetch

// private mr: GitLabMR | undefined
// private user: GitLabUserProfile | undefined

// https://github.com/jdalrymple/node-gitlab/issues/257
private api: any //typeof Gitlab
Expand Down Expand Up @@ -52,6 +54,18 @@ class GitLabAPI {
return `${this.projectURL}/merge_requests/${this.repoMetadata.pullRequestID}`
}

getUser = async (): Promise<GitLabUserProfile> => {
// if (this.user) {
// return this.user
// }

const user = (await this.api.Users.current()) as GitLabUserProfile

// this.user = user

return user
}

getMergeRequestInfo = async (): Promise<GitLabMR> => {
// if (this.mr) {
// return this.mr
Expand Down Expand Up @@ -93,15 +107,17 @@ class GitLabAPI {
}

getMergeRequestComments = async (): Promise<GitLabComment[]> => {
const api = this.api.MergeRequestNotes()
const api = this.api.MergeRequestNotes
return (await api.all(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID)) as GitLabComment[]
}

getMergeRequestInlineComments = async (): Promise<GitLabInlineComment[]> => {
const api = this.api.MergeRequestNotes()
return (await api
.all(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID)
.filter((comment: GitLabComment) => comment.type == "DiffNote")) as GitLabInlineComment[]
const api = this.api.MergeRequestNotes
const res = await api.all(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID)

const returns = res.filter((comment: GitLabComment) => comment.type == "DiffNote") as GitLabInlineComment[]

return Promise.resolve(returns)
}
}

Expand Down
3 changes: 0 additions & 3 deletions source/runner/jsonToDSL.ts
Expand Up @@ -64,9 +64,6 @@ const apiForDSL = (dsl: DangerDSLJSONType): OctoKit | BitBucketServerAPI | GitLa
}

const gitlab = dsl.gitlab
console.log("??????")
d("???????????")
d({ dsl })
if (gitlab != null && process.env["DANGER_GITLAB_API_TOKEN"] != null) {
// d({ gitlab })
return new GitLabAPI(gitlab.metadata, process.env["DANGER_GITLAB_API_TOKEN"]!)
Expand Down

0 comments on commit 8ef0581

Please sign in to comment.