Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "@/features/projects/data"
import {
CachingProjectDataSource,
ForgivingProjectDataSource,
ProjectRepository,
SessionValidatingProjectDataSource
} from "@/features/projects/domain"
Expand Down Expand Up @@ -175,10 +176,13 @@ export const projectRepository = new ProjectRepository(
export const projectDataSource = new CachingProjectDataSource(
new SessionValidatingProjectDataSource(
sessionValidator,
new GitHubProjectDataSource(
userGitHubClient,
GITHUB_ORGANIZATION_NAME
)
new ForgivingProjectDataSource({
accessTokenReader: accessTokenService,
projectDataSource: new GitHubProjectDataSource(
userGitHubClient,
GITHUB_ORGANIZATION_NAME
)
})
),
projectRepository
)
Expand Down
33 changes: 33 additions & 0 deletions src/features/projects/domain/ForgivingProjectDataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Project from "./Project"
import IProjectDataSource from "./IProjectDataSource"

interface IAccessTokenReader {
getAccessToken(): Promise<string>
}

type ForgivingProjectDataSourceConfig = {
readonly accessTokenReader: IAccessTokenReader
readonly projectDataSource: IProjectDataSource
}

export default class ForgivingProjectDataSource implements IProjectDataSource {
private readonly accessTokenReader: IAccessTokenReader
private readonly projectDataSource: IProjectDataSource

constructor(config: ForgivingProjectDataSourceConfig) {
this.accessTokenReader = config.accessTokenReader
this.projectDataSource = config.projectDataSource
}

async getProjects(): Promise<Project[]> {
try {
await this.accessTokenReader.getAccessToken()
} catch {
// If we cannot get an access token, we show an empty list of projects.
// It is common for guest users that we cannot get an access token because they
// have been incorrectly configured to have access to non-existing repositories.
return []
}
return this.projectDataSource.getProjects()
}
}
1 change: 1 addition & 0 deletions src/features/projects/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as CachingProjectDataSource } from "./CachingProjectDataSource"
export { default as ForgivingProjectDataSource } from "./ForgivingProjectDataSource"
export { default as getSelection } from "./getSelection"
export type { default as IProjectConfig } from "./IProjectConfig"
export type { default as IProjectDataSource } from "./IProjectDataSource"
Expand Down