Skip to content
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

Merged
merged 3 commits into from
Jan 14, 2025
Merged

Replaced default remote repo provider #67

merged 3 commits into from
Jan 14, 2025

Conversation

BarabanovVVl
Copy link
Contributor

  • 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
@BarabanovVVl BarabanovVVl requested a review from timbaev January 13, 2025 20:43
enum RemoteRepoProviderType: String {
case forgejo = "forgejo"
case github = "github"
case unknown
Copy link
Collaborator

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 {
Copy link
Collaborator

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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А можно же просто?

RemoteRepoProviderType(rawValue: string.lowercased())

Comment on lines 2 to 3
case forgejo = "forgejo"
case github = "github"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как будто бы можно оставить просто:

    case forgejo
    case github

Comment on lines 29 to 44
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
}
Copy link
Collaborator

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: -
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Осталось

Comment on lines 1 to 6
//
// RemoteRepoCommit.swift
// AnalyticsGen
//
// Created by v.barabanov on 10.01.2025.
//
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хидеры в файлах не нужны, обычно удаляем

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В других новых файлах тоже стоит убрать

Copy link
Contributor Author

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 {
Copy link
Collaborator

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")!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сложно ли будет forgejo.pyn.ru передавать через настройки/параметры? Если да, давай оставим TODO, хотелось бы сделать универсальным

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не упремся снова в то, что от разработчиков потребуется передавать доп переменную окружения?
Можно как вариант перенести в yaml настройки эту функцию.
Отдельный вопрос: в чем тут выгода? если для каждого провайдера свои методы скорее всего (единствкенный плюс переключения на src.pyn а нужен ли?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, я в yaml и предложил

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если для каждого провайдера свои методы скорее всего

Нет, у Forgejo единый API же, может отличаться только от версии сервера

Copy link
Contributor Author

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")!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пустая строка, надо бы SwiftLint подключить

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай запущу

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Его скорее всего настроить нужно

@BarabanovVVl BarabanovVVl requested a review from timbaev January 14, 2025 14:51
func createGenerator(for provider: String, remoteHost: String) throws -> EventGenerator {

guard let baseURL = URL(string: remoteHost) else {
throw DependeciesGeneratorError.missingRemoteHostURI
Copy link
Collaborator

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not specified

По идее он должен быть дефолтный, если его не указали

@BarabanovVVl BarabanovVVl requested a review from timbaev January 14, 2025 15:12
@BarabanovVVl BarabanovVVl merged commit 46a17d9 into master Jan 14, 2025
1 check passed
@BarabanovVVl BarabanovVVl deleted the MOB-45054 branch January 14, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants