Skip to content

Commit

Permalink
Disconnect FundingLink type from GH specific internal representation
Browse files Browse the repository at this point in the history
  • Loading branch information
finestructure committed Nov 15, 2023
1 parent 15de8ce commit b7bd083
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sources/App/Commands/Ingest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func updateRepository(on database: Database,

repository.defaultBranch = repoMetadata.defaultBranch
repository.forks = repoMetadata.forkCount
repository.fundingLinks = repoMetadata.fundingLinks ?? []
repository.fundingLinks = repoMetadata.fundingLinks?.map(FundingLink.init(from:)) ?? []
repository.homepageUrl = repoMetadata.homepageUrl?.trimmed
repository.isArchived = repoMetadata.isArchived
repository.isInOrganization = repoMetadata.isInOrganization
Expand Down
21 changes: 20 additions & 1 deletion Sources/App/Core/Github.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ extension Github {
var defaultBranchRef: DefaultBranchRef?
var description: String?
var forkCount: Int
var fundingLinks: [FundingLink]?
var fundingLinks: [FundingLinkNode]?
var homepageUrl: String?
var isArchived: Bool
// periphery:ignore
Expand Down Expand Up @@ -370,6 +370,25 @@ extension Github {
}
}

struct FundingLinkNode: Codable, Equatable {
enum Platform: String, Codable {
case communityBridge = "COMMUNITYBRIDGE"
case customUrl = "CUSTOMURL"
case gitHub = "GITHUB"
case issueHunt = "ISSUEHUNT"
case koFi = "KOFI"
case lfxCrowdfunding = "LFXCROWDFUNDING"
case liberaPay = "LIBERAPAY"
case openCollective = "OPENCOLLECTIVE"
case otechie = "OTECHIE"
case patreon = "PATREON"
case tideLift = "TIDELIFT"
}

var platform: Platform
var url: String
}

struct IssueNodes: Decodable, Equatable {
var nodes: [IssueNode]

Expand Down
60 changes: 49 additions & 11 deletions Sources/App/Models/FundingLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,57 @@ import Foundation

struct FundingLink: Codable, Equatable {
enum Platform: String, Codable {
case communityBridge = "COMMUNITYBRIDGE"
case customUrl = "CUSTOMURL"
case gitHub = "GITHUB"
case issueHunt = "ISSUEHUNT"
case koFi = "KOFI"
case lfxCrowdfunding = "LFXCROWDFUNDING"
case liberaPay = "LIBERAPAY"
case openCollective = "OPENCOLLECTIVE"
case otechie = "OTECHIE"
case patreon = "PATREON"
case tideLift = "TIDELIFT"
case communityBridge
case customUrl
case gitHub
case issueHunt
case koFi
case lfxCrowdfunding
case liberaPay
case openCollective
case otechie
case patreon
case tideLift
}

var platform: Platform
var url: String
}


extension FundingLink {
init(from node: Github.Metadata.FundingLinkNode) {
platform = .init(from: node.platform)
url = node.url
}
}


extension FundingLink.Platform {
init(from platform: Github.Metadata.FundingLinkNode.Platform) {
switch platform {
case .communityBridge:
self = .communityBridge
case .customUrl:
self = .customUrl
case .gitHub:
self = .gitHub
case .issueHunt:
self = .issueHunt
case .koFi:
self = .koFi
case .lfxCrowdfunding:
self = .lfxCrowdfunding
case .liberaPay:
self = .liberaPay
case .openCollective:
self = .openCollective
case .otechie:
self = .otechie
case .patreon:
self = .patreon
case .tideLift:
self = .tideLift
}
}
}
2 changes: 1 addition & 1 deletion Tests/AppTests/Mocks/GithubMetadata+mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Github.Metadata {

init(defaultBranch: String,
forks: Int,
fundingLinks: [FundingLink] = [],
fundingLinks: [FundingLinkNode] = [],
homepageUrl: String?,
isInOrganization: Bool,
issuesClosedAtDates: [Date],
Expand Down

0 comments on commit b7bd083

Please sign in to comment.