Skip to content

Commit

Permalink
Merge pull request #154 from Microsoft/clear-deployment
Browse files Browse the repository at this point in the history
Clear updates associated with a deployment
  • Loading branch information
lostintangent committed Mar 8, 2016
2 parents aff8bab + 5abc4b5 commit c20c08a
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ code-push deployment add <appName> <deploymentName>
Just like with apps, you can remove and rename deployments as well, using the following commands respectively:

```
code-push deployment rename <appName> <deploymentName> <newDeploymentName>
code-push deployment rm <appName> <deploymentName>
code-push deployment rename <appName> <deploymentName> <newDeploymentName>
```

If at any time you'd like to view the list of deployments that a specific app includes, you can simply run the following command:
Expand Down Expand Up @@ -425,3 +425,13 @@ Additionally, the history displays the install metrics for each release. You can
By default, the history doesn't display the author of each release, but if you are collaborating on an app with other developers, and want to view who released each update, you can pass the additional `--displayAuthor` (or `-a`) flag to the history command.

*NOTE: The history command can also be run using the "h" alias*

## Clearing release history

You can clear the release history associated with a deployment using the following command:

```
code-push deployment clear <appName> <deploymentName>
```

After running this command, client devices configured to receive updates from this deployment using its associated deployment key will no longer receive those updates that have been cleared. This command is irreversible, and therefore should not be used in a production deployment.
6 changes: 6 additions & 0 deletions cli/definitions/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
collaboratorRemove,
deploymentAdd,
deploymentHistory,
deploymentHistoryClear,
deploymentList,
deploymentMetrics,
deploymentRemove,
Expand Down Expand Up @@ -83,6 +84,11 @@ export interface IDeploymentAddCommand extends ICommand {
deploymentName: string;
}

export interface IDeploymentHistoryClearCommand extends ICommand {
appName: string;
deploymentName: string;
}

export interface IDeploymentHistoryCommand extends ICommand {
appName: string;
deploymentName: string;
Expand Down
17 changes: 17 additions & 0 deletions cli/script/command-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ function deploymentAdd(command: cli.IDeploymentAddCommand): Promise<void> {
});
}

function deploymentHistoryClear(command: cli.IDeploymentHistoryClearCommand): Promise<void> {
return confirm()
.then((wasConfirmed: boolean): Promise<void> => {
if (wasConfirmed) {
return sdk.clearDeploymentHistory(command.appName, command.deploymentName)
.then((): void => {
log("Successfully cleared the release history associated with the \"" + command.deploymentName + "\" deployment from the \"" + command.appName + "\" app.");
})
}

log("Clear deployment cancelled.");
});
}

export var deploymentList = (command: cli.IDeploymentListCommand, showPackage: boolean = true): Promise<void> => {
throwForInvalidOutputFormat(command.format);
var deployments: Deployment[];
Expand Down Expand Up @@ -435,6 +449,9 @@ export function execute(command: cli.ICommand): Promise<void> {
case cli.CommandType.deploymentAdd:
return deploymentAdd(<cli.IDeploymentAddCommand>command);

case cli.CommandType.deploymentHistoryClear:
return deploymentHistoryClear(<cli.IDeploymentHistoryClearCommand>command);

case cli.CommandType.deploymentHistory:
return deploymentHistory(<cli.IDeploymentHistoryCommand>command);

Expand Down
21 changes: 21 additions & 0 deletions cli/script/command-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ function removeCollaborator(commandName: string, yargs: yargs.Argv): void {
addCommonConfiguration(yargs);
}

function deploymentHistoryClear(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment " + commandName + " <appName> <deploymentName>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("deployment " + commandName + " MyApp MyDeployment", "Clears the release history associated with deployment \"MyDeployment\" from app \"MyApp\"");

addCommonConfiguration(yargs);
}

function deploymentList(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment " + commandName + " <appName> [--format <format>] [--displayKeys]")
Expand Down Expand Up @@ -227,6 +236,7 @@ var argv = yargs.usage(USAGE_PREFIX + " <command>")

addCommonConfiguration(yargs);
})
.command("clear", "Clears the release history associated with a deployment", (yargs: yargs.Argv) => deploymentHistoryClear("clear", yargs))
.command("remove", "Remove a deployment from an app", (yargs: yargs.Argv) => deploymentRemove("remove", yargs))
.command("rm", "Remove a deployment from an app", (yargs: yargs.Argv) => deploymentRemove("rm", yargs))
.command("rename", "Rename an existing deployment", (yargs: yargs.Argv) => {
Expand Down Expand Up @@ -461,6 +471,17 @@ function createCommand(): cli.ICommand {
}
break;

case "clear":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.deploymentHistoryClear };

var deploymentHistoryClearCommand = <cli.IDeploymentHistoryClearCommand>cmd;

deploymentHistoryClearCommand.appName = arg2;
deploymentHistoryClearCommand.deploymentName = arg3;
}
break;

case "list":
case "ls":
if (arg2) {
Expand Down
45 changes: 45 additions & 0 deletions cli/test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export class SdkStub {
});
}

public clearDeploymentHistory(appId: string, deployment: string): Promise<void> {
return Q(<void>null);
}

public getAccessKeys(): Promise<codePush.AccessKey[]> {
return Q([<codePush.AccessKey>{
name: "8",
Expand Down Expand Up @@ -516,6 +520,47 @@ describe("CLI", () => {
});
});

it("deploymentHistoryClear clears deployment", (done: MochaDone): void => {
var command: cli.IDeploymentHistoryClearCommand = {
type: cli.CommandType.deploymentHistoryClear,
appName: "a",
deploymentName: "Staging"
};

var clearDeployment: Sinon.SinonSpy = sandbox.spy(cmdexec.sdk, "clearDeploymentHistory");

cmdexec.execute(command)
.done((): void => {
sinon.assert.calledOnce(clearDeployment);
sinon.assert.calledWithExactly(clearDeployment, "a", "Staging");
sinon.assert.calledOnce(log);
sinon.assert.calledWithExactly(log, "Successfully cleared the release history associated with the \"Staging\" deployment from the \"a\" app.");

done();
});
});

it("deploymentHistoryClear does not clear deployment if cancelled", (done: MochaDone): void => {
var command: cli.IDeploymentHistoryClearCommand = {
type: cli.CommandType.deploymentHistoryClear,
appName: "a",
deploymentName: "Staging"
};

var clearDeployment: Sinon.SinonSpy = sandbox.spy(cmdexec.sdk, "clearDeploymentHistory");

wasConfirmed = false;

cmdexec.execute(command)
.done((): void => {
sinon.assert.notCalled(clearDeployment);
sinon.assert.calledOnce(log);
sinon.assert.calledWithExactly(log, "Clear deployment cancelled.");

done();
});
});

it("deploymentList lists deployment names, deployment keys, and package information", (done: MochaDone): void => {
var command: cli.IDeploymentListCommand = {
type: cli.CommandType.deploymentList,
Expand Down
5 changes: 5 additions & 0 deletions sdk/script/management-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ class AccountManager {
return this.post(urlEncode `/apps/${appName}/deployments/`, JSON.stringify(deployment), /*expectResponseBody=*/ true)
.then((res: JsonResponse) => res.body.deployment);
}

public clearDeploymentHistory(appName: string, deploymentName: string): Promise<void> {
return this.del(urlEncode `/apps/${appName}/deployments/${deploymentName}/history`)
.then(() => null);
}

public getDeployments(appName: string): Promise<Deployment[]> {
return this.get(urlEncode `/apps/${appName}/deployments/`)
Expand Down

0 comments on commit c20c08a

Please sign in to comment.