A Swift compiler plugin to propagate CODEOWNERS attribution to Swift types
Setup the compiler plugin and the runtime library in your project:
In your Package.swift
add the plugin dependency:
let package = Package(
name: "MyProject",
dependencies: [
.package(url: "https://github.com/gmazzo/swift-codeowners-plugin", from: "x.y.z"),
],
targets: [
.target(
name: "MyProjectTarget",
dependencies: [
.product(name: "CodeOwnersAPI", package: "swift-codeowners-plugin")
],
plugins: [
.plugin(name: "CodeOwnersPlugin", package: "swift-codeowners-plugin")
]
)
]
)
Then you can use the codeOwnersOf
function on any struct
, class
or enum
to query their owners at runtime:
struct MyType {
func printOwner() {
print("This type is owned by \(codeOwnersOf(self))") // or
print("This type is owned by \(codeOwnersOf(MyType.self))") // or
print("This type is owned by \(codeOwnersOf(MyType()))") // or
}
}
The expected format is the same as GitHub's and it can be located at any of the following paths:
$rootDir/CODEOWNERS
$rootDir/.github/CODEOWNERS
$rootDir/.gitlab/CODEOWNERS
$rootDir/docs/CODEOWNERS
Where rootDir
is either project's or GIT's root directory