Skip to content

Commit 91cefc9

Browse files
authored
Merge pull request #176 from RobertReaves/feature-lkId
Added support for adding a LK id
2 parents 8265b8b + 0c3ed5a commit 91cefc9

File tree

4 files changed

+139
-19
lines changed

4 files changed

+139
-19
lines changed

specs/workflows/dev.spec.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
const resetWorkflow = require("../../src/workflows/dev");
2-
const run = require("../../src/workflows/steps");
3-
41
describe("dev workflow", () => {
5-
it("should have all of the required steps", () => {
6-
expect(resetWorkflow).toEqual([
7-
run.fetchUpstream,
8-
run.gitCreateBranchOrigin,
9-
run.checkoutBaseBranch,
10-
run.rebaseUpstreamBaseBranch,
11-
run.checkoutWorkingBranch,
12-
run.gitCreateBranchUpstream,
13-
run.githubUpstream,
14-
run.githubOrigin,
15-
run.updatePullRequestTitle,
16-
run.updatePullRequestBody,
17-
run.createGithubPullRequestAganistBranch
18-
]);
2+
let resetWorkflow;
3+
describe("has LK scope", () => {
4+
beforeEach(() => {
5+
jest.resetModules();
6+
jest.doMock("../../src/utils", () => ({
7+
hasLkScope: jest.fn(() => true)
8+
}));
9+
10+
resetWorkflow = require("../../src/workflows/dev");
11+
});
12+
13+
it("should have all of the required steps", () => {
14+
expect(resetWorkflow.length).toEqual(12);
15+
});
16+
});
17+
18+
describe("doesn't have LK scope", () => {
19+
beforeEach(() => {
20+
jest.resetModules();
21+
jest.doMock("../../src/utils", () => ({
22+
hasLkScope: jest.fn(() => false)
23+
}));
24+
25+
resetWorkflow = require("../../src/workflows/dev");
26+
});
27+
28+
it("should have all of the required steps", () => {
29+
expect(resetWorkflow.length).toEqual(11);
30+
});
1931
});
2032
});

specs/workflows/steps/index.spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,23 @@ describe("shared workflow steps", () => {
32043204
});
32053205
});
32063206

3207+
describe("has LK id", () => {
3208+
it("should call update title with LK id", () => {
3209+
state.lkId = "123456789";
3210+
return run
3211+
.createGithubPullRequestAganistBranch(state)
3212+
.then(() => {
3213+
expect(createPullRequest).toHaveBeenCalledWith({
3214+
base: "feature-branch",
3215+
body: "This is my pull request body",
3216+
head: "someone-awesome-origin:feature-branch",
3217+
title:
3218+
"This is my pull request title (LK:123456789)"
3219+
});
3220+
});
3221+
});
3222+
});
3223+
32073224
it("should create a new GitHub client instance given a valid auth token", () => {
32083225
return run.createGithubPullRequestAganistBranch(state).then(() => {
32093226
expect(GitHub).toHaveBeenCalledTimes(1);
@@ -4595,6 +4612,65 @@ feature-last-branch`)
45954612
});
45964613
});
45974614

4615+
describe("addLKId", () => {
4616+
describe("when user has LK id", () => {
4617+
beforeEach(() => {
4618+
util.prompt = jest.fn(() =>
4619+
Promise.resolve({ hasId: true, id: "123456789" })
4620+
);
4621+
});
4622+
4623+
it("should prompt the user if they have a LK id", () => {
4624+
return run.addLKId(state).then(() => {
4625+
expect(util.prompt).toHaveBeenCalledWith([
4626+
{
4627+
type: "confirm",
4628+
name: "hasId",
4629+
message: "Do you have a LK ID?",
4630+
default: false
4631+
}
4632+
]);
4633+
});
4634+
});
4635+
4636+
it("should prompt the user for their LK id", () => {
4637+
return run.addLKId(state).then(() => {
4638+
expect(util.prompt).toHaveBeenCalledWith([
4639+
{
4640+
type: "input",
4641+
name: "id",
4642+
message: "What is your LK ID?"
4643+
}
4644+
]);
4645+
});
4646+
});
4647+
4648+
it("should persist the given LK id to the workflow state", () => {
4649+
return run.addLKId(state).then(() => {
4650+
expect(state).toHaveProperty("lkId");
4651+
expect(state.lkId).toEqual("123456789");
4652+
});
4653+
});
4654+
});
4655+
4656+
describe("when user doesn't have LK id", () => {
4657+
it("should prompt the user for their LK id", () => {
4658+
util.prompt = jest.fn(() => Promise.resolve({ hasId: false }));
4659+
return run.addLKId(state).then(() => {
4660+
expect(util.prompt).toHaveBeenCalledTimes(1);
4661+
expect(util.prompt).toHaveBeenCalledWith([
4662+
{
4663+
type: "confirm",
4664+
name: "hasId",
4665+
message: "Do you have a LK ID?",
4666+
default: false
4667+
}
4668+
]);
4669+
});
4670+
});
4671+
});
4672+
});
4673+
45984674
describe("updatePullRequestBody", () => {
45994675
beforeEach(() => {
46004676
util.prompt = jest.fn(() => Promise.resolve({ body: true }));

src/workflows/dev.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const run = require("./steps/index");
2+
const { hasLkScope } = require("../utils");
23

34
module.exports = [
45
run.fetchUpstream,
@@ -10,6 +11,7 @@ module.exports = [
1011
run.githubUpstream,
1112
run.githubOrigin,
1213
run.updatePullRequestTitle,
14+
hasLkScope() ? run.addLKId : null,
1315
run.updatePullRequestBody,
1416
run.createGithubPullRequestAganistBranch
15-
];
17+
].filter(x => x);

src/workflows/steps/index.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ ${chalk.green(log)}`);
11381138
},
11391139
origin: { owner: repositoryOriginOwner }
11401140
},
1141+
lkId,
11411142
token,
11421143
branch,
11431144
devBranch,
@@ -1152,7 +1153,7 @@ ${chalk.green(log)}`);
11521153
);
11531154

11541155
const options = {
1155-
title,
1156+
title: `${title}${lkId ? ` (LK:${lkId})` : ""}`,
11561157
body,
11571158
head: `${repositoryOriginOwner}:${branch}`,
11581159
base: devBranch ? `${devBranch}` : `${branch}`
@@ -1600,6 +1601,35 @@ ${chalk.green(log)}`);
16001601
});
16011602
});
16021603
},
1604+
addLKId(state) {
1605+
state.step = "addLKId";
1606+
return util
1607+
.prompt([
1608+
{
1609+
type: "confirm",
1610+
name: "hasId",
1611+
message: "Do you have a LK ID?",
1612+
default: false
1613+
}
1614+
])
1615+
.then(answers => {
1616+
if (answers.hasId) {
1617+
return util
1618+
.prompt([
1619+
{
1620+
type: "input",
1621+
name: "id",
1622+
message: "What is your LK ID?"
1623+
}
1624+
])
1625+
.then(response => {
1626+
state.lkId = response.id.trim();
1627+
return Promise.resolve();
1628+
});
1629+
}
1630+
return Promise.resolve();
1631+
});
1632+
},
16031633
updatePullRequestBody(state) {
16041634
state.step = "updatePullRequestBody";
16051635
const { filePaths: { pullRequestTemplatePath } } = state;

0 commit comments

Comments
 (0)