-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replaced default remote repo provider #67
Conversation
BarabanovVVl
commented
Jan 13, 2025
- GitHub API can be choosed using --provider github variable
- Default API - Forgejo
- GenerateCommand can be modified through custom EventProviderGenerator
- GitHub API can be choosed using --provider github variable - Default API - Forgejo - GenerateCommand can be modified through custom EventProviderGenerator
enum RemoteRepoProviderType: String { | ||
case forgejo = "forgejo" | ||
case github = "github" | ||
case unknown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
кажется, unknown
быть не должно, мы с ним работать не можем
case github = "github" | ||
case unknown | ||
|
||
static func from(string: String) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот здесь лучше кидать ошибку, если невалидный string
, то есть метод будет throws
case unknown | ||
|
||
static func from(string: String) -> Self { | ||
switch string.lowercased() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А можно же просто?
RemoteRepoProviderType(rawValue: string.lowercased())
case forgejo = "forgejo" | ||
case github = "github" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как будто бы можно оставить просто:
case forgejo
case github
let repoProviderType = RemoteRepoProviderType.from(string: provider) | ||
|
||
var remoteRepoProvider: RemoteRepoProvider? | ||
|
||
switch repoProviderType { | ||
case .forgejo: | ||
remoteRepoProvider = ForgejoRemoteRepoProvider(httpService: httpService) | ||
case .github: | ||
remoteRepoProvider = GitHubRemoteRepoProvider(httpService: httpService) | ||
case .unknown: | ||
throw DependeciesGeneratorError.unknownProvider | ||
} | ||
|
||
guard let remoteRepoProvider = remoteRepoProvider else { | ||
throw DependeciesGeneratorError.unknownProvider | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
С учетом предыдущих комментов здесь будет примерно так:
let repoProviderType = try RemoteReportProviderType.from(string: provider)
let remoteReporProvider = switch repoProviderType {
case .forgejo:
ForgejoRemoteRepoProvider(httpService: httpService)
case .github:
GitHubRemoteRepoProvider(httpService: httpService)
}
|
||
// MARK: - Initializers | ||
|
||
init(from decoder: Decoder) throws { | ||
if let container = try? decoder.container(keyedBy: CodingKeys.self) { | ||
self = .gitHub(configuration: try container.decode(forKey: .gitHub)) | ||
//TODO: - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Осталось
// | ||
// RemoteRepoCommit.swift | ||
// AnalyticsGen | ||
// | ||
// Created by v.barabanov on 10.01.2025. | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хидеры в файлах не нужны, обычно удаляем
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В других новых файлах тоже стоит убрать
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
автоматом создалось и не удалил) почищу
// Created by v.barabanov on 13.01.2025. | ||
// | ||
|
||
struct QueryCount: Encodable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не стоит ли добавить префикс Forgejo
, если это относится только к нему? Или вынести из папки Forgejo
struct ForgejoRemoteRepoProvider: RemoteRepoProvider { | ||
|
||
// MARK: - Instance Properties | ||
private let baseURL = URL(string: "https://forgejo.pyn.ru/api/v1")! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сложно ли будет forgejo.pyn.ru
передавать через настройки/параметры? Если да, давай оставим TODO, хотелось бы сделать универсальным
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не упремся снова в то, что от разработчиков потребуется передавать доп переменную окружения?
Можно как вариант перенести в yaml настройки эту функцию.
Отдельный вопрос: в чем тут выгода? если для каждого провайдера свои методы скорее всего (единствкенный плюс переключения на src.pyn а нужен ли?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, я в yaml и предложил
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если для каждого провайдера свои методы скорее всего
Нет, у Forgejo единый API же, может отличаться только от версии сервера
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот тут и вопрос, вроде как обсудили что src.pyn не нужен будет.
Энивэй, давай сделаю)
|
||
// MARK: - Instance Properties | ||
private let baseURL = URL(string: "https://forgejo.pyn.ru/api/v1")! | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пустая строка, надо бы SwiftLint подключить
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай запущу
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Его скорее всего настроить нужно
func createGenerator(for provider: String, remoteHost: String) throws -> EventGenerator { | ||
|
||
guard let baseURL = URL(string: remoteHost) else { | ||
throw DependeciesGeneratorError.missingRemoteHostURI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Скорее не missing
, а не валидный URL?
case .unknownProvider: | ||
"The specified remote repository provider is unknown" | ||
case .missingRemoteHostURI: | ||
"The remote repository URI is not specified or incorrect" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is not specified
По идее он должен быть дефолтный, если его не указали