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

GitLab: Improve GitLab CI support for MRs from forks #1319

Merged
merged 5 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

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

- 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]
<!-- Your comment above this -->

## 11.1.2
Expand All @@ -28,7 +29,7 @@

- Bug fix for over-deleting inline comments #1287

## 11.1.0
## 11.1.0

- Adds support for the new [GitHub Job summaries](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/) API via:
- `danger.github.setSummaryMarkdown("[markdown]")` for the JavaScript DSL
Expand Down Expand Up @@ -57,7 +58,7 @@
# 11.0.0 -> 11.0.2

- *Breaking:* Upgrade @octokit/rest from ^16.43.1 to ^18.12.0 - [#1204](https://github.com/danger/danger-js/pull/1204) [@fbartho]

This is only likely to hit you if you use `danger.github.api` pretty extensively in your Dangerfiles, but better to keep an eye out.

# 10.8.1
Expand Down Expand Up @@ -1947,6 +1948,7 @@ Not usable for others, only stubs of classes etc. - [@orta]
[@hmschreiner]: https://github.com/hmschreiner
[@hongrich]: https://github.com/hongrich
[@igorbek]: https://github.com/igorbek
[@ivankatliarchuk]: https://github.com/ivankatliarchuk
[@iljadaderko]: https://github.com/IljaDaderko
[@imorente]: https://github.com/imorente
[@jamiebuilds]: https://github.com/jamiebuilds
Expand Down
2 changes: 1 addition & 1 deletion source/ci_source/providers/GitLabCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class GitLabCI implements CISource {
}

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

get commitHash(): string {
Expand Down
47 changes: 47 additions & 0 deletions source/ci_source/providers/_tests/_gitlab.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { GitLabCI } from "../GitLabCI"
import { getCISourceForEnv } from "../../get_ci_source"

const correctEnv = {
GITLAB_CI: "true",
CI_MERGE_REQUEST_IID: "27117",
CI_PROJECT_PATH: "gitlab-org/gitlab-foss",
}

describe("being found when looking for CI", () => {
it("finds GitLab with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(GitLabCI)
})
})

describe(".isCI", () => {
it("validates when all GitLab environment vars are set", async () => {
const result = new GitLabCI(correctEnv)
expect(result.isCI).toBeTruthy()
})

it("does not validate without env", async () => {
const result = new GitLabCI({})
expect(result.isCI).toBeFalsy()
})
})

describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const result = new GitLabCI(correctEnv)
expect(result.pullRequestID).toEqual("27117")
})
})

describe(".repoSlug", () => {
it("derives it from 'CI_PROJECT_PATH' env var", () => {
const result = new GitLabCI(correctEnv)
expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss")
})

it("derives it form 'CI_MERGE_REQUEST_PROJECT_PATH' env var if set", () => {
correctEnv["CI_MERGE_REQUEST_PROJECT_PATH"] = "gitlab-org/release-tools"
const result = new GitLabCI(correctEnv)
expect(result.repoSlug).toEqual("gitlab-org/release-tools")
})
})