-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/filter-repositories' into enhancement/adds-avat…
…ars-to-logins
- Loading branch information
Showing
8 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
__test__/projects/FilteringGitHubRepositoryDataSource.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { FilteringGitHubRepositoryDataSource } from "../../src/features/projects/domain" | ||
|
||
test("It returns all repositories when no hidden repositories are provided", async () => { | ||
const sut = new FilteringGitHubRepositoryDataSource({ | ||
hiddenRepositories: [], | ||
dataSource: { | ||
async getRepositories() { | ||
return [{ | ||
owner: "acme", | ||
name: "foo-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "main" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}, { | ||
owner: "acme", | ||
name: "bar-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "bar" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}] | ||
} | ||
} | ||
}) | ||
const repositories = await sut.getRepositories() | ||
expect(repositories.length).toEqual(2) | ||
}) | ||
|
||
test("It removes hidden repository", async () => { | ||
const sut = new FilteringGitHubRepositoryDataSource({ | ||
hiddenRepositories: ["acme/foo-openapi"], | ||
dataSource: { | ||
async getRepositories() { | ||
return [{ | ||
owner: "acme", | ||
name: "foo-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "main" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}, { | ||
owner: "acme", | ||
name: "bar-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "bar" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}] | ||
} | ||
} | ||
}) | ||
const repositories = await sut.getRepositories() | ||
expect(repositories.length).toEqual(1) | ||
}) | ||
|
||
test("It returns unmodified list when hidden repository was not found", async () => { | ||
const sut = new FilteringGitHubRepositoryDataSource({ | ||
hiddenRepositories: ["acme/baz-openapi"], | ||
dataSource: { | ||
async getRepositories() { | ||
return [{ | ||
owner: "acme", | ||
name: "foo-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "main" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}, { | ||
owner: "acme", | ||
name: "bar-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "bar" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}] | ||
} | ||
} | ||
}) | ||
const repositories = await sut.getRepositories() | ||
expect(repositories.length).toEqual(2) | ||
}) | ||
|
||
test("It removes multiple hidden repositories", async () => { | ||
const sut = new FilteringGitHubRepositoryDataSource({ | ||
hiddenRepositories: ["acme/foo-openapi", "acme/bar-openapi"], | ||
dataSource: { | ||
async getRepositories() { | ||
return [{ | ||
owner: "acme", | ||
name: "foo-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "main" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}, { | ||
owner: "acme", | ||
name: "bar-openapi", | ||
defaultBranchRef: { | ||
id: "12345678", | ||
name: "bar" | ||
}, | ||
branches: [], | ||
tags: [] | ||
}] | ||
} | ||
} | ||
}) | ||
const repositories = await sut.getRepositories() | ||
expect(repositories.length).toEqual(0) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { splitOwnerAndRepository } from "@/common" | ||
|
||
test("It returns undefined when string includes no slash", async () => { | ||
const result = splitOwnerAndRepository("foo") | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test("It returns undefined when repository is empty", async () => { | ||
const result = splitOwnerAndRepository("foo/") | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test("It returns undefined when owner is empty", async () => { | ||
const result = splitOwnerAndRepository("/foo") | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test("It splits owner and repository", async () => { | ||
const result = splitOwnerAndRepository("acme/foo") | ||
expect(result).toEqual({ owner: "acme", repository: "foo" }) | ||
}) | ||
|
||
test("It splits owner and repository for repository name containing a slash", async () => { | ||
const result = splitOwnerAndRepository("acme/foo/bar") | ||
expect(result).toEqual({ owner: "acme", repository: "foo/bar" }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Split full repository names into owner and repository. | ||
// shapehq/foo becomes { owner: "shapehq", "repository": "foo" } | ||
export default (str: string) => { | ||
const index = str.indexOf("/") | ||
if (index === -1) { | ||
return undefined | ||
} | ||
const owner = str.substring(0, index) | ||
const repository = str.substring(index + 1) | ||
if (owner.length == 0 || repository.length == 0) { | ||
return undefined | ||
} | ||
return { owner, repository } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/features/projects/domain/FilteringGitHubRepositoryDataSource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import IGitHubRepositoryDataSource, { | ||
GitHubRepository | ||
} from "./IGitHubRepositoryDataSource" | ||
import { splitOwnerAndRepository } from "@/common" | ||
|
||
export default class FilteringGitHubRepositoryDataSource implements IGitHubRepositoryDataSource { | ||
private readonly dataSource: IGitHubRepositoryDataSource | ||
private readonly hiddenRepositories: string[] | ||
|
||
constructor(config: { | ||
dataSource: IGitHubRepositoryDataSource, | ||
hiddenRepositories: string[] | ||
}) { | ||
this.dataSource = config.dataSource | ||
this.hiddenRepositories = config.hiddenRepositories | ||
} | ||
|
||
async getRepositories(): Promise<GitHubRepository[]> { | ||
const repositories = await this.dataSource.getRepositories() | ||
const hiddenOwnerAndRepoNameList = this.hiddenRepositories | ||
.map(splitOwnerAndRepository) | ||
.filter(e => e !== undefined) | ||
return repositories.filter(repository => { | ||
const hiddenMatch = hiddenOwnerAndRepoNameList.find(e => | ||
e.owner == repository.owner && e.repository == repository.name | ||
) | ||
return hiddenMatch === undefined | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters