Skip to content

Commit

Permalink
fix: Respect transportMode for branches.mergeState (#236)
Browse files Browse the repository at this point in the history
* Respect transportMode

Also change parent to parentId

* Include RequestOptions in documentation
  • Loading branch information
anthony-j-castro authored Mar 18, 2020
1 parent 9183441 commit 5805c51
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions docs/abstract-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ A branch merge state is a description of whether a branch can be cleanly merged
| Property | Type | Description |
|------------------------|----------|---------------------------------------------------------------------------------------------------|
| `state` | `string` | The merge state of the branch relative to its parent branch. May be one of `CLEAN`, `NEEDS_UPDATE`, or `NEEDS_REMOTE_UPDATE` |
| `parentId` | `string` | UUID of the parent btanch |
| `parentId` | `string` | UUID of the parent branch |
| `parentCommit` | `string` | SHA that represents the latest commit on the parent branch |
| `branchId` | `string` | UUID identifier of the branch, or the string "master" |
| `branchCommit` | `string` | SHA that represents the latest commit on the branch |
Expand All @@ -271,7 +271,7 @@ A branch merge state is a description of whether a branch can be cleanly merged

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

`branches.mergeState(BranchDescriptor, options?: { parent?: string }): Promise<BranchMergeState>`
`branches.mergeState(BranchDescriptor, { ...RequestOptions, parentId?: string }): Promise<BranchMergeState>`

Load the merge state for a specific branch in a project.

Expand All @@ -282,7 +282,7 @@ abstract.branches.mergeState({
});
```

> Note: The API and CLI [transports](/docs/transports) behave differently for merge state. The CLI transport ignores `options.parent`, and _only_ returns one of the three possible merge states (no other fields are included). The API transport includes a value for each field of `BranchMergeState`, and only returns statuses `CLEAN` or `NEEDS_UPDATE`.
> Note: The API and CLI [transports](/docs/transports) behave differently for merge state. The CLI transport ignores `options.parentId`, and _only_ returns one of the three possible merge states (no other fields are included). The API transport includes a value for each field of `BranchMergeState`, and only returns statuses `CLEAN` or `NEEDS_UPDATE`.
## Changesets

Expand Down
20 changes: 12 additions & 8 deletions src/endpoints/Branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ export default class Branches extends Endpoint {
});
}

mergeState(descriptor: BranchDescriptor, options?: { parent?: string }) {
mergeState(
descriptor: BranchDescriptor,
options?: { ...RequestOptions, parentId?: string } = {}
) {
const { parentId, ...requestOptions } = options;

return this.configureRequest<Promise<BranchMergeState>>({
api: async () => {
let requestUrl = `projects/${descriptor.projectId}/branches/${descriptor.branchId}/merge_state`;
if (options) {
const { parent } = options;
if (parent) {
const query = querystring.stringify({ parentId: parent });
requestUrl = `${requestUrl}?${query}`;
}
if (parentId) {
const query = querystring.stringify({ parentId });
requestUrl = `${requestUrl}?${query}`;
}
const response = await this.apiRequest(requestUrl, { headers });
return wrap(response.data, response);
Expand All @@ -107,7 +109,9 @@ export default class Branches extends Endpoint {
]);

return wrap(response, response);
}
},

requestOptions
});
}
}
2 changes: 1 addition & 1 deletion tests/endpoints/Branches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe("branches", () => {
branchId: "branch-id",
projectId: "project-id"
},
{ parent: "parent-id" }
{ parentId: "parent-id" }
);
expect(response).toEqual({
state: "CLEAN"
Expand Down

0 comments on commit 5805c51

Please sign in to comment.