Skip to content

Commit bda76b6

Browse files
add explicit tag flag to update-pipeline. fixes #57 (#58)
1 parent dc3602d commit bda76b6

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/commands/cloudmanager/update-pipeline.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ class UpdatePipelineCommand extends Command {
3030

3131
const programId = await getProgramId(flags)
3232

33+
if (flags.tag && flags.branch) {
34+
throw new Error("Both branch and tag cannot be specified.")
35+
}
36+
37+
if (flags.tag && flags.tag.startsWith("refs/tags/")) {
38+
throw new Error(`tag flag should not be specified with "refs/tags/" prefix. Value provided was ${flags.tag}`)
39+
}
40+
41+
if (flags.tag) {
42+
flags.branch = `refs/tags/${flags.tag}`
43+
}
44+
3345
let result
3446

3547
cli.action.start("updating pipeline")
@@ -56,6 +68,7 @@ UpdatePipelineCommand.flags = {
5668
...commonFlags.global,
5769
...commonFlags.programId,
5870
branch: flags.string({ description: "the new branch"}),
71+
tag: flags.string({ description: "the new tag"}),
5972
repositoryId: flags.string({ description: "the new repositoryId"})
6073
}
6174

test/commands/update-pipeline.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,63 @@ test('update-pipeline - repository and branch success', async () => {
103103
await expect(cli.action.stop.mock.calls[0][0]).toBe("updated pipeline ID 5")
104104
})
105105

106+
test('update-pipeline - both tag and branch', async () => {
107+
setStore({
108+
'jwt-auth': JSON.stringify({
109+
client_id: '1234',
110+
jwt_payload: {
111+
iss: "good"
112+
}
113+
}),
114+
})
115+
116+
expect.assertions(2)
117+
118+
let runResult = UpdatePipelineCommand.run(["--programId", "5", "5", "--branch", "develop", "--tag", "foo"])
119+
await expect(runResult instanceof Promise).toBeTruthy()
120+
await expect(runResult).rejects.toSatisfy(err => err.message.indexOf("Both branch and tag cannot be specified") === 0)
121+
})
122+
123+
test('update-pipeline - malformed tag', async () => {
124+
setStore({
125+
'jwt-auth': JSON.stringify({
126+
client_id: '1234',
127+
jwt_payload: {
128+
iss: "good"
129+
}
130+
}),
131+
})
132+
133+
expect.assertions(2)
134+
135+
let runResult = UpdatePipelineCommand.run(["--programId", "5", "5", "--tag", "refs/tags/foo"])
136+
await expect(runResult instanceof Promise).toBeTruthy()
137+
await expect(runResult).rejects.toSatisfy(err => err.message.indexOf("tag flag should not be specified with \"refs/tags/\" prefix. Value provided was refs/tags/foo") === 0)
138+
})
139+
140+
141+
test('update-pipeline - correct tag', async () => {
142+
setStore({
143+
'jwt-auth': JSON.stringify({
144+
client_id: '1234',
145+
jwt_payload: {
146+
iss: "good"
147+
}
148+
}),
149+
})
150+
151+
expect.assertions(3)
152+
153+
let runResult = UpdatePipelineCommand.run(["--programId", "5", "5", "--tag", "foo"])
154+
await expect(runResult instanceof Promise).toBeTruthy()
155+
await expect(runResult).resolves.toMatchObject({
156+
phases: expect.arrayContaining([{
157+
name: 'BUILD_1',
158+
branch: 'refs/tags/foo',
159+
type: 'BUILD',
160+
repositoryId: '1'
161+
}])
162+
})
163+
await expect(cli.action.stop.mock.calls[0][0]).toBe("updated pipeline ID 5")
164+
})
106165

0 commit comments

Comments
 (0)