Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft issue-1301: update gitbreaker version #1324

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -16,7 +16,7 @@

<!-- Your comment below this -->
- Append random string to danger-results.json and danger-dsl.json files to better support concurrent processes #1311

- GitLab: Upgrade `@gitbreaker/node` from `^21.3.0` to `^^35.7.0` [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk]
- Gitlab package moved to a new home "@gitbreaker/*" [#1301](https://github.com/danger/danger-js/issues/1301) [@ivankatliarchuk]
- GitLab: Improve support for MRs from forks [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk]
- GitLab: Added provider tests [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -148,7 +148,7 @@
"debug": "^4.1.1",
"fast-json-patch": "^3.0.0-1",
"get-stdin": "^6.0.0",
"@gitbeaker/node": "^21.3.0",
"@gitbeaker/node": "^35.7.0",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"hyperlinker": "^1.0.0",
Expand Down
252 changes: 38 additions & 214 deletions source/dsl/GitLabDSL.ts
Expand Up @@ -2,6 +2,13 @@
// TODO: extract out from BitBucket specifically, or create our own type
import { Gitlab } from "@gitbeaker/node"
import { RepoMetaData } from "./BitBucketServerDSL"
import { UserExtendedSchema } from "@gitbeaker/core/dist/types/resources/Users"
import { MergeRequestSchema, UpdateMergeRequestOptions } from "@gitbeaker/core/dist/types/resources/MergeRequests"
import { MergeRequestLevelMergeRequestApprovalSchema } from "@gitbeaker/core/dist/types/resources/MergeRequestApprovals"
import { MergeRequestNoteSchema } from "@gitbeaker/core/dist/types/resources/MergeRequestNotes"
import { BaseRequestOptions } from "@gitbeaker/core/dist/types/infrastructure/RequestHelper"
import { CommitDiffSchema, CommitSchema } from "@gitbeaker/core/dist/types/resources/Commits"
import { RepositoryCompareSchema } from "@gitbeaker/core/dist/types/resources/Repositories"

// getPlatformReviewDSLRepresentation
export interface GitLabJSONDSL {
Expand All @@ -27,133 +34,23 @@ export interface GitLabDSL extends GitLabJSONDSL {
// ---
// JSON responses from API

export interface GitLabUser {
id: number
name: string
username: string
state: "active" | "blocked"
avatar_url: string | null
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 {
/** The MR's id */
id: number

/** The unique ID for this MR */
iid: number

/** The project ID for this MR */
project_id: number

/** The given name of the MR */
title: string

/** The body text describing the MR */
description: string
// can be removed
export interface GitLabUserProfile extends UserExtendedSchema {}
export interface GitlabUpdateMr extends UpdateMergeRequestOptions, BaseRequestOptions {}
export interface GitLabApproval extends MergeRequestLevelMergeRequestApprovalSchema {}
export interface GitLabMRChange extends CommitDiffSchema {}
export interface GitLabRepositoryCompare extends RepositoryCompareSchema {}
export interface GitLabMRCommit extends CommitSchema {}
// ^ can be removed

/** The MR's current availability */
state: "closed" | "open" | "locked" | "merged"

/** When was the MR made */
created_at: string

/** When was the MR updated */
updated_at: string

/** What branch is this MR being merged into */
target_branch: string
/** What branch is this MR come from */
source_branch: string

/** How many folks have given it an upvote */
upvotes: number
/** How many folks have given it an downvote */
downvotes: number

/** Who made it */
author: GitLabUser
/** Access rights for the user who created the MR */
user: {
/** Does the author have access to merge? */
can_merge: boolean
}
/** Who was assigned as the person to review */
assignee?: GitLabUser
assignees: GitLabUser[]
/** Users who were added as reviewers to the MR */
reviewers: GitLabUser[]
source_project_id: number
target_project_id: number
labels: string[]
work_in_progress: boolean
milestone: {
id: number
iid: number
project_id: number
title: string
description: string
state: "closed" | "active"
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" // XXX: other statuses?
merge_error: null | null
sha: string
merge_commit_sha: string | null
user_notes_count: number
discussion_locked: null | null
should_remove_source_branch: boolean
force_remove_source_branch: boolean
allow_collaboration: boolean
allow_maintainer_to_push: boolean
web_url: string
time_stats: {
time_estimate: number
total_time_spent: number
human_time_estimate: number | null
human_total_time_spent: number | null
}
export interface GitLabInlineNote extends MergeRequestNoteSchema {
type: "DiffNote" | "DiscussionNote" | null // XXX: other types? null means "normal comment"
}

/** TODO: These need more comments from someone who uses GitLab, see GitLabDSL.ts in the danger-js repo */
export interface GitLabMR extends GitLabMRBase {
squash: boolean
export interface GitLabMR extends MergeRequestSchema {
subscribed: boolean
changes_count: string
merged_by: GitLabUser
merged_at: string
closed_by: GitLabUser | null
closed_at: string | null
latest_build_started_at: string
latest_build_finished_at: string
first_deployed_to_production_at: string | null
Expand All @@ -171,37 +68,31 @@ export interface GitLabMR extends GitLabMRBase {
}
diverged_commits_count: number
rebase_in_progress: boolean
approvals_before_merge: null | null
}

export interface GitLabMRChange {
old_path: string
new_path: string
a_mode: string
b_mode: string
diff: string
new_file: boolean
renamed_file: boolean
deleted_file: boolean
approvals_before_merge: null
//
/** Access rights for the user who created the MR */
user: {
/** Does the author have access to merge? */
can_merge: boolean
}
merge_error: null
allow_collaboration: boolean
allow_maintainer_to_push: boolean
}

export interface GitLabMRChanges extends GitLabMRBase {
changes: GitLabMRChange[]
export interface GitLabMRChanges extends MergeRequestSchema {
/** Access rights for the user who created the MR */
user: {
/** Does the author have access to merge? */
can_merge: boolean
}
merge_error: null
allow_collaboration: boolean
allow_maintainer_to_push: boolean
}

export interface GitLabNote {
id: number
export interface GitLabNote extends MergeRequestNoteSchema {
type: "DiffNote" | "DiscussionNote" | 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 GitLabDiscussionTextPosition {
Expand All @@ -214,70 +105,3 @@ export interface GitLabDiscussionTextPosition {
old_path: string
old_line: number | null
}

export interface GitLabInlineNote extends GitLabNote {
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 GitLabMRCommit {
id: string
short_id: string
created_at: string
parent_ids: string[]
title: string
message: string
author_name: string
author_email: string
authored_date: string
committer_name: string
committer_email: string
committed_date: string
}

export interface GitLabCommit {
id: string
short_id: string
title: string
author_name: string
author_email: string
created_at: string
}

export interface GitLabRepositoryCompare {
commit: GitLabCommit
commits: GitLabCommit[]
diffs: GitLabMRChange[]
compare_timeout: boolean
compare_same_ref: boolean
}

export interface GitLabApproval {
id: number
iid: number
project_id: number
title: string
description: string
state: "closed" | "open" | "locked" | "merged"
created_at: string
updated_at: string
merge_status: "can_be_merged"
approvals_required: number
approvals_left: number
approved_by?:
| {
user: GitLabUser
}[]
| GitLabUser[]
}
28 changes: 14 additions & 14 deletions source/platforms/GitLab.ts
Expand Up @@ -3,7 +3,6 @@ import { Platform, Comment } from "./platform"
import { GitDSL, GitJSONDSL } from "../dsl/GitDSL"
import { GitCommit } from "../dsl/Commit"
import { GitLabDSL, GitLabJSONDSL, GitLabNote } from "../dsl/GitLabDSL"

import { debug } from "../debug"
import { dangerIDToString } from "../runner/templates/githubIssueTemplate"
const d = debug("GitLab")
Expand All @@ -19,6 +18,7 @@ class GitLab implements Platform {
return this.api.getMergeRequestInfo()
}

// TODO: test it
// returns the `danger.gitlab` object
getPlatformReviewDSLRepresentation = async (): Promise<GitLabJSONDSL> => {
const mr = await this.getReviewInfo()
Expand All @@ -36,32 +36,32 @@ class GitLab implements Platform {
const changes = await this.api.getMergeRequestChanges()
const commits = await this.api.getMergeRequestCommits()

const mappedCommits: GitCommit[] = commits.map(commit => {
const mappedCommits: GitCommit[] = commits.map((commit) => {
return {
sha: commit.id,
author: {
name: commit.author_name,
email: commit.author_email,
date: commit.authored_date,
email: commit.author_email as string,
date: (commit.authored_date as Date).toString(),
},
committer: {
name: commit.committer_name,
email: commit.committer_email,
date: commit.committed_date,
name: commit.committer_name as string,
email: commit.committer_email as string,
date: (commit.committed_date as Date).toString(),
},
message: commit.message,
parents: commit.parent_ids,
parents: commit.parent_ids as string[],
url: `${this.api.projectURL}/commit/${commit.id}`,
tree: null,
}
})

// XXX: does "renamed_file"/move count is "delete/create", or "modified"?
const modified_files: string[] = changes
.filter(change => !change.new_file && !change.deleted_file)
.map(change => change.new_path)
const created_files: string[] = changes.filter(change => change.new_file).map(change => change.new_path)
const deleted_files: string[] = changes.filter(change => change.deleted_file).map(change => change.new_path)
.filter((change) => !change.new_file && !change.deleted_file)
.map((change) => change.new_path)
const created_files: string[] = changes.filter((change) => change.new_file).map((change) => change.new_path)
const deleted_files: string[] = changes.filter((change) => change.deleted_file).map((change) => change.new_path)

return {
modified_files,
Expand All @@ -74,7 +74,7 @@ class GitLab implements Platform {
getInlineComments = async (dangerID: string): Promise<Comment[]> => {
const dangerUserID = (await this.api.getUser()).id

return (await this.api.getMergeRequestInlineNotes()).map(note => {
return (await this.api.getMergeRequestInlineNotes()).map((note) => {
return {
id: `${note.id}`,
body: note.body,
Expand Down Expand Up @@ -164,7 +164,7 @@ class GitLab implements Platform {

return notes.length > 0
}

// Todo: test it
getDangerNotes = async (dangerID: string): Promise<GitLabNote[]> => {
const { id: dangerUserId } = await this.api.getUser()
const notes: GitLabNote[] = await this.api.getMergeRequestNotes()
Expand Down