-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced default remote repo provider (#67)
* Replaced default remote repo provider - GitHub API can be choosed using --provider github variable - Default API - Forgejo - GenerateCommand can be modified through custom EventProviderGenerator * remote host URI parser added * fix --------- Co-authored-by: v.barabanov <[email protected]>
- Loading branch information
1 parent
0d33992
commit 46a17d9
Showing
26 changed files
with
378 additions
and
114 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
59 changes: 59 additions & 0 deletions
59
Sources/AnalyticsGen/DependeciesGenerator/DefaultDependeciesGenerator.swift
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,59 @@ | ||
import Foundation | ||
import AnalyticsGenTools | ||
import DictionaryCoder | ||
|
||
final class DefaultDependeciesGenerator: DependenciesGenerator { | ||
let httpService: HTTPService | ||
let yamlFileProvider: FileProvider | ||
let templateContextCoder: TemplateContextCoder | ||
let stencilExtensions: [StencilExtension] | ||
let templateRenderer: TemplateRenderer | ||
|
||
init() { | ||
self.httpService = HTTPService() | ||
self.yamlFileProvider = YAMLFileProvider() | ||
self.templateContextCoder = DefaultTemplateContextCoder() | ||
self.stencilExtensions = [ | ||
StencilStringUppercasePrefixFilter(), | ||
StencilStringUppercaseSuffixFilter(), | ||
StencilStringMultilineFilter(), | ||
StencilStringMultilineAlignmentFilter() | ||
] | ||
self.templateRenderer = DefaultTemplateRenderer( | ||
contextCoder: templateContextCoder, | ||
stencilExtensions: stencilExtensions | ||
) | ||
} | ||
|
||
func createGenerator(for provider: String, remoteHost: String) throws -> EventGenerator { | ||
|
||
guard let baseURL = URL(string: remoteHost) else { | ||
throw DependeciesGeneratorError.invalidRemoteHostURI | ||
} | ||
|
||
let repoProviderType = try RemoteRepoProviderType.from(string: provider) | ||
|
||
var remoteRepoProvider: RemoteRepoProvider? | ||
|
||
switch repoProviderType { | ||
case .forgejo: | ||
remoteRepoProvider = ForgejoRemoteRepoProvider(baseURL: baseURL, httpService: httpService) | ||
case .github: | ||
remoteRepoProvider = GitHubRemoteRepoProvider(baseURL: baseURL, httpService: httpService) | ||
} | ||
|
||
guard let remoteRepoProvider = remoteRepoProvider else { | ||
throw DependeciesGeneratorError.unknownProvider | ||
} | ||
|
||
let remoteRepoReferenceFinder = RemoteRepoReferenceFinder(remoteRepoProvider: remoteRepoProvider) | ||
|
||
return DefaultEventGenerator( | ||
fileProvider: yamlFileProvider, | ||
remoteRepoProvider: remoteRepoProvider, | ||
templateRenderer: templateRenderer, | ||
dictionaryDecoder: DictionaryDecoder(), | ||
remoteRepoReferenceFinder: remoteRepoReferenceFinder | ||
) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Sources/AnalyticsGen/DependeciesGenerator/DependeciesGeneratorError.swift
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,15 @@ | ||
import Foundation | ||
|
||
enum DependeciesGeneratorError: Error { | ||
case unknownProvider | ||
case invalidRemoteHostURI | ||
|
||
var errorDescription: String { | ||
switch self { | ||
case .unknownProvider: | ||
"The specified remote repository provider is unknown" | ||
case .invalidRemoteHostURI: | ||
"The remote repository URI is not correct" | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Sources/AnalyticsGen/DependeciesGenerator/DependenciesGenerator.swift
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,11 @@ | ||
import AnalyticsGenTools | ||
|
||
protocol DependenciesGenerator { | ||
var httpService: HTTPService { get } | ||
var yamlFileProvider: FileProvider { get } | ||
var templateContextCoder: TemplateContextCoder { get } | ||
var stencilExtensions: [StencilExtension] { get } | ||
var templateRenderer: TemplateRenderer { get } | ||
|
||
func createGenerator(for provider: String, remoteHost: String) throws -> EventGenerator | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.