Skip to content

Commit 95a903f

Browse files
committed
Accept compiled branch pin organizations
1 parent 529bce2 commit 95a903f

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

Sources/GitHub Continuous Integration Validation/GitHub.ContinuousIntegration.Validation.BranchPins.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,39 @@ extension GitHub.ContinuousIntegration.Validation {
4141
/// invocation wants; a sweep over a foreign checkout names it.
4242
public let organizationsFile: String?
4343

44+
/// A caller-supplied organization set. This is the compiled-control
45+
/// path: the Institute policy owner can provide its typed set directly
46+
/// without recreating the retired YAML transport beside the subject.
47+
public let organizations: Organizations?
48+
4449
/// The burn-down ledger. `nil` is an empty ledger.
4550
public let baselineFile: String?
4651

4752
public init(organizationsFile: String? = nil, baselineFile: String? = nil) {
4853
self.organizationsFile = organizationsFile
54+
self.organizations = nil
55+
self.baselineFile = baselineFile
56+
}
57+
58+
public init(organizations: Organizations, baselineFile: String? = nil) {
59+
self.organizationsFile = nil
60+
self.organizations = organizations
4961
self.baselineFile = baselineFile
5062
}
5163

5264
public func findings(in subject: Subject) throws(EnvironmentDefect) -> [Finding] {
53-
let manifestPath =
54-
organizationsFile
55-
?? Organizations.locateManifest(startingAt: subject.root)
56-
guard let manifestPath else {
57-
throw .missingSupportFile(path: Organizations.manifestPath)
65+
let organizations: Organizations
66+
if let supplied = self.organizations {
67+
organizations = supplied
68+
} else {
69+
let manifestPath =
70+
organizationsFile
71+
?? Organizations.locateManifest(startingAt: subject.root)
72+
guard let manifestPath else {
73+
throw .missingSupportFile(path: Organizations.manifestPath)
74+
}
75+
organizations = try Organizations.read(at: manifestPath)
5876
}
59-
let organizations = try Organizations.read(at: manifestPath)
6077
let baseline = try Baseline.read(at: baselineFile)
6178

6279
var findings: [Finding] = []

Tests/GitHub Continuous Integration Validation Tests/GitHub.ContinuousIntegration.Validation.BranchPins Tests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ struct CIValidationBranchPinsTests {
3737
)
3838
}
3939

40+
@Test func `a supplied organization set needs no support manifest`() throws {
41+
let repository = TemporaryRepository(repository: "example-organization-one/consumer")
42+
repository.write(
43+
Self.pinnedManifest(#"branch: "develop""#),
44+
to: "Package.swift"
45+
)
46+
let validator = GitHub.ContinuousIntegration.Validation.BranchPins(
47+
organizations: .init(names: ["example-organization-one"]))
48+
49+
let findings = try validator.findings(in: repository.subject)
50+
51+
#expect(findings.map(\.rule) == ["BRANCH-PIN-001"])
52+
}
53+
4054
@Suite
4155
struct `Baseline Contract` {
4256
@Test func `an unbaselined pin fires the rule`() throws {

0 commit comments

Comments
 (0)