Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9c8ba47
Recognise DANGER_GITLAB_HOST env
notjosh Apr 5, 2019
cc632c2
GitLab implementation & tests for pullRequestParser
notjosh Apr 5, 2019
e6410b8
Added base platform code for GitLab
notjosh Apr 5, 2019
91ef63a
Fetchin' live MR vales from GitLab API
notjosh Apr 5, 2019
c274eb8
Oof, there's a lot going on in there. The runner works in another pro…
notjosh Apr 6, 2019
8ef0581
Generally the pulling/reading works, to the point of commenting
notjosh Apr 6, 2019
abecf38
The nuts & bolts of API commenting are working
notjosh Apr 6, 2019
8ceb1ec
Inline comments seem to sort of work?
notjosh Apr 6, 2019
2367ed3
Minor bugfix to only delete comments that Danger created
notjosh Apr 6, 2019
a22c68b
Support GitLab CI as a CI source
bigkraig Apr 8, 2019
76b7bb1
Fixes inline commenting in GitLab
bigkraig Apr 9, 2019
957412c
Added CHANGELOG entry
bigkraig Apr 9, 2019
d344384
Added GitLab to README
bigkraig Apr 9, 2019
527c62c
Merge branch 'master' into feature/gitlab
bigkraig Apr 9, 2019
b2ec339
Removed unused test file
bigkraig Apr 9, 2019
5168c45
Throwing errors on not yet implemented gitlab functions
bigkraig Apr 9, 2019
7d9b5c9
Using the CI_MERGE_REQUEST_IID var according to https://docs.gitlab.c…
bigkraig Apr 9, 2019
f0d1e81
Removed some accidentally added vscode configuration
bigkraig Apr 9, 2019
6ac429c
Updated the gitlab dependency to include support for Node 8
bigkraig Apr 10, 2019
4acda3b
Bumped the oldest node to something not so old (8.9)
bigkraig Apr 11, 2019
06ea6d9
Merge branch 'master' into feature/gitlab
bigkraig Apr 14, 2019
7d629cc
Changed out the older node 8 tests to test against the current LTS ve…
bigkraig Apr 14, 2019
19a35b7
Merge remote-tracking branch 'upstream/master' into feature/gitlab
May 17, 2019
e3a78d7
Add tests for GitLab
May 17, 2019
2d3c6de
Merge pull request #1 from jamime/feature/gitlab
bigkraig May 20, 2019
ab83665
delete main comment when all issues are resolved
May 21, 2019
a26047e
Merge pull request #2 from bigkraig/feature/delete_comment
jamime May 28, 2019
7b34217
update gitlab dep
May 28, 2019
2ba17eb
use GITLAB_CI to detect CI
May 29, 2019
765d5d6
Revert "update gitlab dep"
May 29, 2019
3a337fb
improve GitLab environment detection
May 29, 2019
157383b
fix: use DANGER_GITLAB_API_TOKEN to detect DSL type
May 29, 2019
657e0a0
Merge branch 'master' into feature/gitlab
f-meloni May 29, 2019
9bf4690
fix: updateOrCreateComment note detection
May 30, 2019
9363aa1
update gitlab dep
Jun 3, 2019
1d75688
docs: update command in readme
Jun 4, 2019
0952bac
chore: tidy code
Jun 4, 2019
67662eb
fix: improve danger-pr
Jun 4, 2019
78af7b2
feat: GitLab fileContents
Jun 5, 2019
8776aa6
fix: change GitHub platform to be a named function instead of an arro…
Jun 5, 2019
083cff7
ci: trigger build
Jun 5, 2019
b386dae
feat: add logging to GitLabAPI
Jun 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
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"
}
]
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

<!-- Your comment below this -->

- Adds GitLab & GitLab CI support.

# 7.1.0

- Adds Chainsmoker, and expands the Danger DSL with the addition of `danger.git.fileMatch`.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"commander": "^2.18.0",
"debug": "^4.1.1",
"get-stdin": "^6.0.0",
"gitlab": "^5.0.0-rc.11",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.1",
"hyperlinker": "^1.0.0",
Expand Down
68 changes: 68 additions & 0 deletions source/ci_source/providers/GitLabCI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Env, CISource } from "../ci_source"
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers"

export class GitLabCI implements CISource {
constructor(private readonly env: Env) {}

get name(): string {
return "GitLab CI"
}

get isCI(): boolean {
return ensureEnvKeysExist(this.env, ["CI_MR_ID"])
}

get isPR(): boolean {
const mustHave = ["CI_MR_ID", "CI_PROJECT_PATH"]
const mustBeInts = ["CI_MR_ID"]
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts)
}

get pullRequestID(): string {
return this.env.CI_MR_ID
}

get repoSlug(): string {
return this.env.CI_PROJECT_PATH
}
}

// See https://docs.gitlab.com/ee/ci/variables/
//
// export CI_JOB_ID="50"
// export CI_COMMIT_SHA="1ecfd275763eff1d6b4844ea3168962458c9f27a"
// export CI_COMMIT_SHORT_SHA="1ecfd275"
// export CI_COMMIT_REF_NAME="master"
// export CI_REPOSITORY_URL="https://gitlab-ci-token:[email protected]/gitlab-org/gitlab-ce.git"
// export CI_COMMIT_TAG="1.0.0"
// export CI_JOB_NAME="spec:other"
// export CI_JOB_STAGE="test"
// export CI_JOB_MANUAL="true"
// export CI_JOB_TRIGGERED="true"
// export CI_JOB_TOKEN="abcde-1234ABCD5678ef"
// export CI_PIPELINE_ID="1000"
// export CI_PIPELINE_IID="10"
// export CI_PAGES_DOMAIN="gitlab.io"
// export CI_PAGES_URL="https://gitlab-org.gitlab.io/gitlab-ce"
// export CI_PROJECT_ID="34"
// export CI_PROJECT_DIR="/builds/gitlab-org/gitlab-ce"
// export CI_PROJECT_NAME="gitlab-ce"
// export CI_PROJECT_NAMESPACE="gitlab-org"
// export CI_PROJECT_PATH="gitlab-org/gitlab-ce"
// export CI_PROJECT_URL="https://example.com/gitlab-org/gitlab-ce"
// export CI_REGISTRY="registry.example.com"
// export CI_REGISTRY_IMAGE="registry.example.com/gitlab-org/gitlab-ce"
// export CI_RUNNER_ID="10"
// export CI_RUNNER_DESCRIPTION="my runner"
// export CI_RUNNER_TAGS="docker, linux"
// export CI_SERVER="yes"
// export CI_SERVER_NAME="GitLab"
// export CI_SERVER_REVISION="70606bf"
// export CI_SERVER_VERSION="8.9.0"
// export CI_SERVER_VERSION_MAJOR="8"
// export CI_SERVER_VERSION_MINOR="9"
// export CI_SERVER_VERSION_PATCH="0"
// export GITLAB_USER_ID="42"
// export GITLAB_USER_EMAIL="[email protected]"
// export CI_REGISTRY_USER="gitlab-ci-token"
// export CI_REGISTRY_PASSWORD="longalfanumstring"
3 changes: 3 additions & 0 deletions source/ci_source/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DockerCloud } from "./DockerCloud"
import { Drone } from "./Drone"
import { FakeCI } from "./Fake"
import { GitHubActions } from "./GitHubActions"
import { GitLabCI } from "./GitLabCI"
import { Jenkins } from "./Jenkins"
import { Netlify } from "./Netlify"
import { Nevercode } from "./Nevercode"
Expand All @@ -22,6 +23,7 @@ import { VSTS } from "./VSTS"
const providers = [
FakeCI,
GitHubActions,
GitLabCI,
Travis,
Circle,
Semaphore,
Expand All @@ -45,6 +47,7 @@ const providers = [
// Mainly used for Dangerfile linting
const realProviders = [
GitHubActions,
GitLabCI,
Travis,
Circle,
Semaphore,
Expand Down
1 change: 1 addition & 0 deletions source/commands/ci/runner.ts
Original file line number Diff line number Diff line change
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
14 changes: 11 additions & 3 deletions source/commands/danger-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ program
.on("--help", () => {
log("\n")
log(" Docs:")
if (!process.env["DANGER_GITHUB_API_TOKEN"] && !process.env["DANGER_BITBUCKETSERVER_HOST"]) {
if (
!process.env["DANGER_GITHUB_API_TOKEN"] &&
!process.env["DANGER_BITBUCKETSERVER_HOST"] &&
!process.env["DANGER_GITLAB_HOST"]
) {
log("")
log(" You don't have a DANGER_GITHUB_API_TOKEN set up, this is optional, but TBH, you want to do this.")
log(" Check out: http://danger.systems/js/guides/the_dangerfile.html#working-on-your-dangerfile")
Expand All @@ -60,13 +64,17 @@ if (program.args.length === 0) {
console.error("Please include a PR URL to run against")
process.exitCode = 1
} else {
const customHost = process.env["DANGER_GITHUB_HOST"] || process.env["DANGER_BITBUCKETSERVER_HOST"] || "github"
const customHost =
process.env["DANGER_GITHUB_HOST"] ||
process.env["DANGER_BITBUCKETSERVER_HOST"] ||
process.env["DANGER_GITLAB_HOST"] ||
"github"

// Allow an ambiguous amount of args to find the PR reference
const findPR = program.args.find(a => a.includes(customHost))

if (!findPR) {
console.error(`Could not find an arg which mentioned GitHub or BitBucket Server.`)
console.error(`Could not find an arg which mentioned GitHub, BitBucket, or GitLab Server.`)
process.exitCode = 1
} else {
const pr = pullRequestParser(findPR)
Expand Down
21 changes: 19 additions & 2 deletions source/dsl/DangerDSL.ts
Original file line number Diff line number Diff line change
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
}
}
}
Loading