Skip to content

Commit

Permalink
fix(branch): use micromatch for list
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Oct 1, 2018
1 parent 3285e95 commit f60d2db
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 33 deletions.
52 changes: 31 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,32 @@ repository provider for bitbucket
- [repositoryClass](#repositoryclass)
- [branchClass](#branchclass)
- [repositoryGroupClass](#repositorygroupclass)
- [repository](#repository)
- [Parameters](#parameters-1)
- [defaultOptions](#defaultoptions)
- [analyseURL](#analyseurl)
- [Parameters](#parameters-1)
- [repository](#repository)
- [Parameters](#parameters-2)
- [optionsFromEnvironment](#optionsfromenvironment)
- [project](#project)
- [Parameters](#parameters-3)
- [defaultOptions](#defaultoptions)
- [optionsFromEnvironment](#optionsfromenvironment)
- [Parameters](#parameters-4)
- [BitbucketBranch](#bitbucketbranch)
- [content](#content)
- [Parameters](#parameters-4)
- [createPullRequest](#createpullrequest)
- [Parameters](#parameters-5)
- [createPullRequest](#createpullrequest)
- [Parameters](#parameters-6)
- [defaultOptions](#defaultoptions-1)
- [hash](#hash)
- [BitbucketRepository](#bitbucketrepository)
- [Parameters](#parameters-6)
- [Parameters](#parameters-7)
- [Properties](#properties)
- [urls](#urls)
- [homePageURL](#homepageurl)
- [issuesURL](#issuesurl)
- [createBranch](#createbranch)
- [Parameters](#parameters-7)
- [deleteBranch](#deletebranch)
- [Parameters](#parameters-8)
- [deleteBranch](#deletebranch)
- [Parameters](#parameters-9)
- [BitbucketProject](#bitbucketproject)
- [defaultOptions](#defaultoptions-2)
- [api](#api-1)
Expand Down Expand Up @@ -100,6 +102,18 @@ Returns **Class** BitbucketBranch

Returns **Class** BitbucketProject

### analyseURL

decode URL for a given repo url
provide version 1.0 for stash hosts names and 2.0 for all other

#### Parameters

- `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** bitbucket (repo)
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** api version (optional, default `{version:"2.0"}`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** bitbucket api urls by version

### repository

Supported name schemes are
Expand All @@ -112,26 +126,22 @@ Supported name schemes are
#### Parameters

- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `options`

Returns **Repository**

### defaultOptions

Default configuration

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
### project

### analyseURL
#### Parameters

api URL for a given repo url
provide version 1.0 for stash hosts names and 2.0 for all other
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

#### Parameters
### defaultOptions

- `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** bitbucket (repo)
- `version` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** api version (optional, default `"2.0"`)
Default configuration as given for the cloud privider

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** bitbucket api urls by version
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

### optionsFromEnvironment

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"travis-deploy-once": "travis-deploy-once"
},
"dependencies": {
"micromatch": "^3.1.10",
"repository-provider": "^5.2.2",
"request": "^2.88.0",
"request-promise": "^4.2.2"
Expand Down
14 changes: 13 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,17 @@ export default {
commonjs(),
cleanup()
],
external: ["repository-provider", "stream", "http", "https", "zlib"]
external: [
"repository-provider",
"stream",
"http",
"https",
"zlib",
"util",
"path",
"fs",
"net",
"url",
"tty"
]
};
23 changes: 14 additions & 9 deletions src/bitbucket-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
PullRequest
} from "repository-provider";

import micromatch from "micromatch";

/**
* Branch of a bitbucket repository
*/
Expand Down Expand Up @@ -49,21 +51,24 @@ export class BitbucketBranch extends Branch {
return new Content(path, res);
}

async tree(path) {
async *tree(path, patterns) {
const res = await this.get(
`repositories/${this.repository.fullName}/src/${this.hash}${path}`
);

console.log(res);
return res.values.map(e => {
return { path: e.path };
});
for(const entry of res.values) {
if (patterns === undefined) {
yield new Content(entry.path);
} else {
if (micromatch([entry.path], patterns).length === 1) {
yield new Content(entry.path);
}
}
}
}

async *list(pattern = ["**/*", "**/.*"]) {
for (entry of this.tree("/")) {
yield entry;
}
async *list(patterns) {
return yield *this.tree("/", patterns);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion tests/branch-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import test from "ava";
import {
Content,
} from "repository-provider";

import { BitbucketProvider } from "../src/bitbucket-provider";
import { BitbucketProject } from "../src/bitbucket-project";

Expand Down Expand Up @@ -47,7 +51,9 @@ test.only("list", async t => {
entries.push(entry);
}

t.deepEqual(entries, [{ path: "README.md" }]);
t.true(entries[0].equals(new Content('README.md')));

//t.deepEqual(entries, [{ path: "README.md" }]);
});

test("content", async t => {
Expand Down
15 changes: 14 additions & 1 deletion tests/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ export default {
sourcemap: true,
interop: false
},
external: ["ava", "repository-provider", "stream", "http", "https", "zlib"],
external: [
"ava",
"repository-provider",
"stream",
"http",
"https",
"zlib",
"util",
"path",
"fs",
"net",
"url",
"tty"
],
plugins: [
multiEntry(),
babel({
Expand Down

0 comments on commit f60d2db

Please sign in to comment.