Skip to content

Commit f875330

Browse files
authored
fix finding and parsing code owners files (#9)
1 parent 963d559 commit f875330

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## 2.2.0 - 2023-01-02
10+
## 2.3.0 - 2023-03-06
11+
12+
### Fixed
13+
14+
- Find `CODEOWNERS` file in `.github/` and repository root directories. (#9)
15+
- Handle parsing code owners [files with inline comments](https://github.com/snyk/github-codeowners/commit/64dc4df353de62f0c96dae96897e283e66d5be37). (#9)
16+
17+
## 2.2.0 - 2023-03-02
1118

1219
### Added
1320

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Quickly see GitHub Code Owners for the current file. Add syntax highlighting for CODEOWNERS files.",
55
"publisher": "chdsbd",
66
"license": "SEE LICENSE IN LICENSE",
7-
"version": "2.2.0",
7+
"version": "2.3.0",
88
"icon": "images/logo256.png",
99
"homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md",
1010
"keywords": [

‎src/extension.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@ const COMMAND_ID = "github-code-owners.show-owners"
88

99
const STATUS_BAR_PRIORITY = 100
1010

11+
async function fileExists(path: string): Promise<boolean> {
12+
try {
13+
await vscode.workspace.fs.stat(vscode.Uri.parse(path))
14+
return true
15+
} catch (e: unknown) {
16+
// @ts-expect-error
17+
if (e.code !== "FileNotFound") {
18+
console.error(e)
19+
}
20+
return false
21+
}
22+
}
23+
const PathOptions = [".github/CODEOWNERS", "CODEOWNERS"]
24+
25+
async function findCodeOwnersFile(
26+
startDirectory: string,
27+
): Promise<string | null> {
28+
for (const pathOption of PathOptions) {
29+
const codeownersPath = path.join(startDirectory, pathOption)
30+
if (await fileExists(codeownersPath)) {
31+
return codeownersPath
32+
}
33+
}
34+
return null
35+
}
36+
1137
async function getOwnership(): Promise<{
1238
owners: string[]
1339
lineno: number
@@ -29,7 +55,7 @@ async function getOwnership(): Promise<{
2955
uri: { fsPath: workspacePath },
3056
} = workspaceFolder
3157

32-
const codeownersFilePath = findUp.sync("CODEOWNERS", { cwd: workspacePath })
58+
const codeownersFilePath = await findCodeOwnersFile(workspacePath)
3359
if (codeownersFilePath == null) {
3460
return null
3561
}

0 commit comments

Comments
 (0)