Skip to content

Commit c74eace

Browse files
Filter out files that are not Markdown
- Add isMarkdownFile property to GitHubContentItem - Add filter to fetchProposalContentItems() - Update comments and indentation - Resolved #50
1 parent a9075bb commit c74eace

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Sources/EvolutionMetadataExtraction/ExtractionJob.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extension ExtractionJob {
102102
// in those subdirectories are filtered out of this proposal
103103
// specs array.
104104
let proposalSpecs = proposalContentItems.enumerated().compactMap {
105-
$1.proposalSpec(sortIndex: $0)
105+
$1.proposalSpec(sortIndex: $0)
106106
}
107107

108108
return ExtractionJob(source: source, output: output, branchInfo: mainBranchInfo, proposalListing: proposalContentItems, proposalSpecs: proposalSpecs, previousResults: try await previousResults, expectedResults: nil, forcedExtractionIDs: forcedExtractionIDs, toolVersion: toolVersion, extractionDate: extractionDate)

Sources/EvolutionMetadataExtraction/Utilities/Networking.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@ struct GitHubContentItem: Codable {
5454
var url: String
5555
var html_url: String
5656
var git_url: String
57-
var download_url: String?
58-
var type: String
57+
var download_url: String? // nil when type is "dir"
58+
var type: String // "file" or "dir"
5959
var _links: LinkContainer
6060

6161
struct LinkContainer: Codable {
6262
var `self`: String
6363
var git: String
6464
var html: String
6565
}
66+
67+
var isMarkdownFile: Bool {
68+
type == "file" && name.hasSuffix(".md")
69+
}
6670

6771
/// Returns `nil` if this content item corresponds to a
6872
/// subdirectory instead of a direct proposal document.
@@ -123,13 +127,14 @@ struct GitHubFetcher {
123127
return branchInfo
124128
}
125129

126-
// For creating snapshots we need access to the 'raw' GitHub content items
130+
// Returns only content items that are Markdown files in the /proposals directory of the repo.
131+
// Filters out subdirectories and files without ".md" suffix.
127132
static func fetchProposalContentItems(for reference: String? = nil) async throws -> [GitHubContentItem] {
128133
var endpoint = Endpoint.githubProposalsEndpoint
129134
if let reference {
130135
endpoint.append(queryItems: [URLQueryItem(name: "ref", value: reference)])
131136
}
132-
return try await getGitHubAPIValue(for: endpoint, type: [GitHubContentItem].self)
137+
return try await getGitHubAPIValue(for: endpoint, type: [GitHubContentItem].self).filter { $0.isMarkdownFile }
133138
}
134139

135140
static func fetchPullRequestProposalList(for pullNumber: String) async throws -> [GitHubPullFileItem] {

0 commit comments

Comments
 (0)