Skip to content

Commit

Permalink
feat: add support for branch changesets
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `changesets.info` was ranamed to `changesets.commit`
  • Loading branch information
bitpshr committed Sep 24, 2019
1 parent eea097a commit 9d79909
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 deletions.
23 changes: 19 additions & 4 deletions docs/abstract-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,37 @@ A changeset is a group of changes that together form a single, indivisible modif
| `layerStyleId` | `string` | UUID of the layer style associated with this change |
| `textStyleId` | `string` | UUID of the text style associated with this change |

### Retrieve a changeset
### Retrieve a changeset for a commit

![CLI][cli-icon] ![API][api-icon]

`changesets.info(CommitDescriptor): Promise<Changeset>`
`changesets.commit(CommitDescriptor): Promise<Changeset>`

Load an individual changeset
Load a changeset for a commit

```js
abstract.changesets.info({
abstract.changesets.commit({
branchId: "master",
projectId: "616daa90-1736-11e8-b8b0-8d1fec7aef78",
sha: "e2a0a301c4a530ec16024cbb339dfc135c841b10"
});
```

### Retrieve a changeset for a branch

![CLI][cli-icon] ![API][api-icon]

`changesets.commit(BranchDscriptor): Promise<Changeset>`

Load a changeset for a branch

```js
abstract.changesets.branch({
branchId: "c426d0a6-e039-43d7-b7b3-e685a25e4cfb",
projectId: "616daa90-1736-11e8-b8b0-8d1fec7aef78"
});
```


## Collections

Expand Down
32 changes: 27 additions & 5 deletions src/endpoints/Changesets.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow
import type { Changeset, CommitDescriptor } from "../types";
import type { BranchDescriptor, Changeset, CommitDescriptor } from "../types";
import Endpoint from "./Endpoint";

export default class Changesets extends Endpoint {
async info(descriptor: CommitDescriptor) {
async commit(descriptor: CommitDescriptor) {
const latestDescriptor = await this.client.descriptors.getLatestDescriptor(
descriptor
);
Expand All @@ -15,21 +15,43 @@ export default class Changesets extends Endpoint {
return response.changeset;
},

cli: () => {
return this.cliRequest([
cli: async () => {
const response = await this.cliRequest([
"changeset",
latestDescriptor.projectId,
"--commit",
latestDescriptor.sha,
"--branch",
latestDescriptor.branchId
]);
return response.changeset;
},

cache: {
key: `changeset:${descriptor.sha}`,
key: `changeset-commit:${descriptor.sha}`,
disabled: descriptor.sha === "latest"
}
});
}

async branch(descriptor: BranchDescriptor) {
return this.request<Promise<Changeset>>({
api: async () => {
const response = await this.apiRequest(
`projects/${descriptor.projectId}/branches/${descriptor.branchId}/changeset`
);
return response.changeset;
},

cli: async () => {
const response = await this.cliRequest([
"changeset",
descriptor.projectId,
"--branch",
descriptor.branchId
]);
return response.changeset;
}
});
}
}
38 changes: 34 additions & 4 deletions src/endpoints/Changesets.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow
import { mockAPI, mockCLI, API_CLIENT, CLI_CLIENT } from "../testing";

describe("#info", () => {
describe("#commit", () => {
test("api", async () => {
mockAPI("/projects/project-id/branches/branch-id/commits/sha/changeset", {
changeset: { id: "changeset-id" }
});
const response = await API_CLIENT.changesets.info({
const response = await API_CLIENT.changesets.commit({
branchId: "branch-id",
projectId: "project-id",
sha: "sha"
Expand All @@ -19,10 +19,12 @@ describe("#info", () => {
mockCLI(
["changeset", "project-id", "--commit", "sha", "--branch", "branch-id"],
{
id: "changeset-id"
changeset: {
id: "changeset-id"
}
}
);
const response = await CLI_CLIENT.changesets.info({
const response = await CLI_CLIENT.changesets.commit({
branchId: "branch-id",
projectId: "project-id",
sha: "sha"
Expand All @@ -31,3 +33,31 @@ describe("#info", () => {
expect(response).toEqual({ id: "changeset-id" });
});
});

describe("#branch", () => {
test("api", async () => {
mockAPI("/projects/project-id/branches/branch-id/changeset", {
changeset: { id: "changeset-id" }
});
const response = await API_CLIENT.changesets.branch({
branchId: "branch-id",
projectId: "project-id"
});

expect(response).toEqual({ id: "changeset-id" });
});

test("cli", async () => {
mockCLI(["changeset", "project-id", "--branch", "branch-id"], {
changeset: {
id: "changeset-id"
}
});
const response = await CLI_CLIENT.changesets.branch({
branchId: "branch-id",
projectId: "project-id"
});

expect(response).toEqual({ id: "changeset-id" });
});
});

0 comments on commit 9d79909

Please sign in to comment.