Skip to content

Commit 4583a1d

Browse files
authored
Add commit and share experiment command to the palette (#2259)
1 parent 452490a commit 4583a1d

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

extension/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@
363363
"category": "DVC",
364364
"icon": "$(repo-push)"
365365
},
366+
{
367+
"title": "%command.shareExperimentAsCommit%",
368+
"command": "dvc.shareExperimentAsCommit",
369+
"category": "DVC",
370+
"icon": "$(repo-push)"
371+
},
366372
{
367373
"title": "%command.showCommands",
368374
"command": "dvc.showCommands",
@@ -757,6 +763,10 @@
757763
"command": "dvc.shareExperimentAsBranch",
758764
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
759765
},
766+
{
767+
"command": "dvc.shareExperimentAsCommit",
768+
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
769+
},
760770
{
761771
"command": "dvc.showExperiments",
762772
"when": "dvc.commands.available && dvc.project.available"

extension/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"command.selectForCompare": "Select for Compare",
5050
"command.setupWorkspace": "Setup The Workspace",
5151
"command.shareExperimentAsBranch": "Share Experiment as Branch",
52+
"command.shareExperimentAsCommit": "Commit and Share Experiment",
5253
"command.showCommands": "Show Commands",
5354
"command.showExperiments": "Show Experiments",
5455
"command.showOutput": "Show DVC Output",

extension/src/commands/external.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export enum RegisteredCliCommands {
1010
EXPERIMENT_RUN_QUEUED = 'dvc.startExperimentsQueue',
1111
EXPERIMENT_RESET_AND_RUN = 'dvc.resetAndRunCheckpointExperiment',
1212
EXPERIMENT_SHARE_AS_BRANCH = 'dvc.shareExperimentAsBranch',
13+
EXPERIMENT_SHARE_AS_COMMIT = 'dvc.shareExperimentAsCommit',
1314
QUEUE_EXPERIMENT = 'dvc.queueExperiment',
1415

1516
EXPERIMENT_VIEW_APPLY = 'dvc.views.experiments.applyExperiment',

extension/src/experiments/commands/register.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ const registerExperimentInputCommands = (
194194
)
195195
)
196196

197+
internalCommands.registerExternalCliCommand(
198+
RegisteredCliCommands.EXPERIMENT_SHARE_AS_COMMIT,
199+
() =>
200+
experiments.getCwdExpNameAndInputThenRun(
201+
getShareExperimentAsCommitCommand(internalCommands),
202+
Title.ENTER_COMMIT_MESSAGE
203+
)
204+
)
205+
197206
internalCommands.registerExternalCliCommand(
198207
RegisteredCliCommands.EXPERIMENT_VIEW_SHARE_AS_COMMIT,
199208
({ dvcRoot, id }: ExperimentDetails) =>

extension/src/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export interface IEventNamePropertyMapping {
127127
[EventName.EXPERIMENT_RESET_AND_RUN]: undefined
128128
[EventName.EXPERIMENT_SELECT]: undefined
129129
[EventName.EXPERIMENT_SHARE_AS_BRANCH]: undefined
130+
[EventName.EXPERIMENT_SHARE_AS_COMMIT]: undefined
130131
[EventName.EXPERIMENT_SHOW]: undefined
131132
[EventName.EXPERIMENT_SORT_ADD]: undefined
132133
[EventName.EXPERIMENT_SORT_ADD_STARRED]: undefined

extension/src/test/suite/experiments/workspace.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,61 @@ suite('Workspace Experiments Test Suite', () => {
606606
})
607607
})
608608

609+
describe('dvc.shareExperimentAsCommit', () => {
610+
it('should be able to share an experiment as a commit', async () => {
611+
const { experiments } = buildExperiments(disposable)
612+
await experiments.isReady()
613+
614+
const testExperiment = 'exp-83425'
615+
const mockCommit = 'this is the best experiment ever!'
616+
const inputEvent = getInputBoxEvent(mockCommit)
617+
618+
stub(window, 'showQuickPick').resolves({
619+
value: { id: testExperiment, name: testExperiment }
620+
} as QuickPickItemWithValue<{ id: string; name: string }>)
621+
622+
const mockExperimentApply = stub(
623+
DvcExecutor.prototype,
624+
'experimentApply'
625+
).resolves(
626+
`Changes for experiment '${testExperiment}' have been applied to your current workspace.`
627+
)
628+
const mockPush = stub(DvcExecutor.prototype, 'push').resolves(
629+
'191232423 files updated.'
630+
)
631+
const mockStageAndCommit = stub(
632+
GitExecutor.prototype,
633+
'stageAndCommit'
634+
).resolves('')
635+
const mockGitPush = stub(GitExecutor.prototype, 'pushBranch')
636+
const branchPushedToRemote = new Promise(resolve =>
637+
mockGitPush.callsFake(() => {
638+
resolve(undefined)
639+
return Promise.resolve(`${mockCommit} pushed to remote`)
640+
})
641+
)
642+
643+
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)
644+
645+
await commands.executeCommand(
646+
RegisteredCliCommands.EXPERIMENT_SHARE_AS_COMMIT
647+
)
648+
649+
await inputEvent
650+
await branchPushedToRemote
651+
expect(mockExperimentApply).to.be.calledWithExactly(
652+
dvcDemoPath,
653+
testExperiment
654+
)
655+
expect(mockStageAndCommit).to.be.calledWithExactly(
656+
dvcDemoPath,
657+
mockCommit
658+
)
659+
expect(mockPush).to.be.calledWithExactly(dvcDemoPath)
660+
expect(mockGitPush).to.be.calledWithExactly(dvcDemoPath)
661+
})
662+
})
663+
609664
describe('dvc.removeExperiment', () => {
610665
it('should ask the user to pick an experiment and then remove that experiment from the workspace', async () => {
611666
const mockExperiment = 'exp-to-remove'

0 commit comments

Comments
 (0)