diff --git a/CHANGELOG.md b/CHANGELOG.md index e5df26cd8..e147cee0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,10 @@ x - +- Take commit hash from CircleCI environment variable [@valscion] +- Fix project path with /- in GitLab MR URL [@pgoudreau] +- When creating a new PR with `createOrUpdatePR`, add the description (as done when editing) - [@sogame] + # 10.1.0 diff --git a/source/ci_source/providers/Circle.ts b/source/ci_source/providers/Circle.ts index ab7b0a072..e85520e7c 100644 --- a/source/ci_source/providers/Circle.ts +++ b/source/ci_source/providers/Circle.ts @@ -96,4 +96,8 @@ export class Circle implements CISource { get ciRunURL() { return this.env["CIRCLE_BUILD_URL"] } + + get commitHash(): string { + return this.env.CIRCLE_SHA1 + } } diff --git a/source/ci_source/providers/_tests/_circle.test.ts b/source/ci_source/providers/_tests/_circle.test.ts index cb8342e5a..34b252eed 100644 --- a/source/ci_source/providers/_tests/_circle.test.ts +++ b/source/ci_source/providers/_tests/_circle.test.ts @@ -97,3 +97,19 @@ describe(".repoSlug", () => { expect(circle.repoSlug).toEqual("artsy/eigen") }) }) + +describe("commit hash", () => { + it("returns correct commit hash when present", () => { + const env = { + ...correctEnv, + CIRCLE_SHA1: "1234abc", + } + const circle = new Circle(env) + expect(circle.commitHash).toEqual("1234abc") + }) + + it("returns no commit hash when not present", () => { + const circle = new Circle(correctEnv) + expect(circle.commitHash).toBeUndefined() + }) +}) diff --git a/source/platforms/_tests/_pull_request_parser.test.ts b/source/platforms/_tests/_pull_request_parser.test.ts index 627a56748..72b3afd0a 100644 --- a/source/platforms/_tests/_pull_request_parser.test.ts +++ b/source/platforms/_tests/_pull_request_parser.test.ts @@ -108,6 +108,60 @@ describe("parsing urls", () => { }) }) }) + + describe("with /-", () => { + describe(".com", () => { + it("handles PRs-", () => { + expect(pullRequestParser("https://gitlab.com/GROUP/PROJ/-/merge_requests/123")).toEqual({ + pullRequestNumber: "123", + repo: "GROUP/PROJ", + platform: "GitLab", + }) + }) + + it("handles PRs sub-pages-", () => { + expect(pullRequestParser("https://gitlab.com/GROUP/PROJ/-/merge_requests/123/commits")).toEqual({ + pullRequestNumber: "123", + repo: "GROUP/PROJ", + platform: "GitLab", + }) + }) + + it("handles sub-groups", () => { + expect(pullRequestParser("https://gitlab.com/GROUP/SUBGROUP/PROJ/-/merge_requests/123")).toEqual({ + pullRequestNumber: "123", + repo: "GROUP/SUBGROUP/PROJ", + platform: "GitLab", + }) + }) + }) + + describe("CE/EE", () => { + it("handles PRs", () => { + expect(pullRequestParser("https://localdomain/GROUP/PROJ/-/merge_requests/123")).toEqual({ + pullRequestNumber: "123", + repo: "GROUP/PROJ", + platform: "GitLab", + }) + }) + + it("handles PRs sub-pages", () => { + expect(pullRequestParser("https://localdomain/GROUP/PROJ/-/merge_requests/123/commits")).toEqual({ + pullRequestNumber: "123", + repo: "GROUP/PROJ", + platform: "GitLab", + }) + }) + + it("handles sub-groups", () => { + expect(pullRequestParser("https://localdomain/GROUP/SUBGROUP/PROJ/-/merge_requests/123")).toEqual({ + pullRequestNumber: "123", + repo: "GROUP/SUBGROUP/PROJ", + platform: "GitLab", + }) + }) + }) + }) }) describe("Bitbucket Cloud", () => { diff --git a/source/platforms/github/GitHubUtils.ts b/source/platforms/github/GitHubUtils.ts index 2701080fd..aecf2a3ba 100644 --- a/source/platforms/github/GitHubUtils.ts +++ b/source/platforms/github/GitHubUtils.ts @@ -176,6 +176,7 @@ export const createOrUpdatePR = (pr: GitHubPRDSL | undefined, api: GitHub) => as owner, repo, title: config.title, + body: config.body, }) } } diff --git a/source/platforms/pullRequestParser.ts b/source/platforms/pullRequestParser.ts index ea4933cc4..c17f5a9ba 100644 --- a/source/platforms/pullRequestParser.ts +++ b/source/platforms/pullRequestParser.ts @@ -50,7 +50,7 @@ export function pullRequestParser(address: string): PullRequestParts | null { if (parts) { return { platform: GitLab.name, - repo: parts[1], + repo: parts[1].replace(/\/-$/, ""), pullRequestNumber: parts[2], } }