diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..8c0d802 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,65 @@ +# This is a comment. +# Each line is a file pattern followed by one or more owners. + +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# @global-owner1 and @global-owner2 will be requested for +# review when someone opens a pull request. +* @global-owner1 @global-owner2 + +# Order is important; the last matching pattern takes the most +# precedence. When someone opens a pull request that only +# modifies JS files, only @js-owner and not the global +# owner(s) will be requested for a review. +*.js @js-owner #This is an inline comment. + +# You can also use email addresses if you prefer. They'll be +# used to look up users just like we do for commit author +# emails. +*.go docs@example.com + +# Teams can be specified as code owners as well. Teams should +# be identified in the format @org/team-name. Teams must have +# explicit write access to the repository. In this example, +# the octocats team in the octo-org organization owns all .txt files. +*.txt @octo-org/octocats + +# In this example, @doctocat owns any files in the build/logs +# directory at the root of the repository and any of its +# subdirectories. +/build/logs/ @doctocat + +# The `docs/*` pattern will match files like +# `docs/getting-started.md` but not further nested files like +# `docs/build-app/troubleshooting.md`. +docs/* docs@example.com + +# In this example, @octocat owns any file in an apps directory +# anywhere in your repository. +apps/ @octocat + +# In this example, @doctocat owns any file in the `/docs` +# directory in the root of your repository and any of its +# subdirectories. +/docs/ @doctocat + +# In this example, any change inside the `/scripts` directory +# will require approval from @doctocat or @octocat. +/scripts/ @doctocat @octocat + +# In this example, @octocat owns any file in a `/logs` directory such as +# `/build/logs`, `/scripts/logs`, and `/deeply/nested/logs`. Any changes +# in a `/logs` directory will require approval from @octocat. +**/logs @octocat + +# In this example, @octocat owns any file in the `/apps` +# directory in the root of your repository except for the `/apps/github` +# subdirectory, as its owners are left empty. +/apps/ @octocat +/apps/github + +# In this example, @octocat owns any file in the `/apps` +# directory in the root of your repository except for the `/apps/github` +# subdirectory, as this subdirectory has its own owner @doctocat +/apps/ @octocat +/apps/github @doctocat diff --git a/.vscode/settings.json b/.vscode/settings.json index eb72a1a..f313efb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,12 @@ "[codeowners]": { // never autoformat test files "editor.defaultFormatter": null - } + }, + "github-code-owners.team-mapping.slack": [ + { + "team": "@octo-org/octocats", + "domain": "octo-org.slack.com", + "channel": "#help-octo-ui" + } + ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 03c8265..d1cdf9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## 4.0.0 - 2024-04-11 + +### Added + +- Reload link provider when settings change (#28). +- Center editor on CODEOWNERS line when jumping to owner via status bar (#28). + +### Changed + +- Rename GitHub "team" setting to "username" to be consistent with existing features (#28). + ## 3.4.0 - 2024-04-10 ### Added diff --git a/README.md b/README.md index 150e713..ec3296a 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,12 @@ Shows the first code owner. Click to see matching line in CODEOWNERS file. click to open username in GitHub +#### Link usernames to Slack + +click to open username in GitHub + +> Define a Slack mapping in your VSCode settings (`github-code-owners.team-mapping.slack`) to enable this feature. + #### Auto complete auto complete of paths and usernames @@ -26,7 +32,6 @@ Shows the first code owner. Click to see matching line in CODEOWNERS file. #### Formatting -> [!TIP] > Enable formatting by setting `github-code-owners.format.enabled` to `true`. auto complete of paths and usernames diff --git a/images/open-in-slack.png b/images/open-in-slack.png new file mode 100644 index 0000000..59ccd97 Binary files /dev/null and b/images/open-in-slack.png differ diff --git a/package-lock.json b/package-lock.json index fd754f0..5958464 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "github-code-owners", - "version": "3.4.0", + "version": "4.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "github-code-owners", - "version": "3.4.0", + "version": "4.0.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "@snyk/github-codeowners": "github:chdsbd/github-codeowners#chris/line-number-information", diff --git a/package.json b/package.json index f62d4b5..0b806f3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Quickly see GitHub Code Owners for the current file. Add syntax highlighting for CODEOWNERS files.", "publisher": "chdsbd", "license": "SEE LICENSE IN LICENSE", - "version": "3.4.0", + "version": "4.0.0", "icon": "images/logo256.png", "homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md", "keywords": [ @@ -80,14 +80,14 @@ "items": { "type": "object", "properties": { - "team": { + "username": { "type": "string", "examples": [ "@acme-corp/frontend" ], - "markdownDescription": "GitHub team", + "markdownDescription": "GitHub username", "pattern": "^@", - "patternErrorMessage": "GitHub teams must start with @", + "patternErrorMessage": "GitHub usernames must start with @", "required": true }, "domain": { @@ -112,7 +112,7 @@ "required": true, "examples": [ { - "team": "@acme-corp/frontend", + "username": "@acme-corp/frontend", "domain": "acme-corp.slack.com", "channel": "#eng-frontend" } diff --git a/src/codeowners-hover-provider.ts b/src/codeowners-hover-provider.ts index 07e1c2e..1d112a3 100644 --- a/src/codeowners-hover-provider.ts +++ b/src/codeowners-hover-provider.ts @@ -6,14 +6,8 @@ export class CodeownersHoverProvider implements vscode.HoverProvider { provideHover( document: vscode.TextDocument, position: vscode.Position, - token: vscode.CancellationToken, ): vscode.ProviderResult { - console.log({ document, position, token }) const line = document.lineAt(position.line) - // if (line.text.match(/^\s/)) - console.log(line) - const start = line.text.split(" ")[0] - console.log({ start }) const m = line.text.match(/^\s*(\S+)/)?.[1] if (m == null) { return { contents: [] } @@ -27,7 +21,10 @@ export class CodeownersHoverProvider implements vscode.HoverProvider { try { isDirectory = fs.statSync(myPath).isDirectory() } catch (e) { - console.error(e) + // @ts-expect-error we should see this error. + if (e.code !== "ENOENT") { + console.error("github-code-owners", e) + } } const x = new vscode.MarkdownString() x.appendCodeblock(m) @@ -50,9 +47,7 @@ export class CodeownersHoverProvider implements vscode.HoverProvider { : isDirectory ? `Matches all files in directory and subdirectories` : `Matches path exactly`, - // !isPattern && isDirectory == null ? "Path does not exist" : "", ], } - // return { contents: [] } } } diff --git a/src/extension.ts b/src/extension.ts index 7ac0f1e..20897e0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -16,10 +16,12 @@ export function activate(context: vscode.ExtensionContext) { console.log("CODEOWNERS: activated") const outputChannel = vscode.window.createOutputChannel("Github Code Owners") - vscode.languages.registerDocumentLinkProvider( - "codeowners", - new GitHubUsernamesLinkProvider(), - ) + const handles = { + linkProvider: vscode.languages.registerDocumentLinkProvider( + "codeowners", + new GitHubUsernamesLinkProvider(), + ), + } vscode.languages.registerDocumentFormattingEditProvider( "codeowners", @@ -66,4 +68,13 @@ export function activate(context: vscode.ExtensionContext) { statusBarTextEditorListener(statusBarItem, outputChannel), ), ) + + vscode.workspace.onDidChangeConfiguration(() => { + outputChannel.appendLine("Configuration changed: Reloading link provider") + handles.linkProvider.dispose() + handles.linkProvider = vscode.languages.registerDocumentLinkProvider( + "codeowners", + new GitHubUsernamesLinkProvider(), + ) + }) } diff --git a/src/github-usernames-link-provider.ts b/src/github-usernames-link-provider.ts index effed5e..510ad84 100644 --- a/src/github-usernames-link-provider.ts +++ b/src/github-usernames-link-provider.ts @@ -32,7 +32,7 @@ function getGitHubUrl(): string { type SlackMappingConfigurationItem = { domain: string channel: string - team: string + username: string } function getTeamMappingSlack() { @@ -44,7 +44,7 @@ function getTeamMappingSlack() { ) ?? [] const mapping: Record = {} for (const team of setting) { - mapping[team.team] = team + mapping[team.username] = team } return mapping } diff --git a/src/show-owners-command.ts b/src/show-owners-command.ts index 6c58743..ad848ff 100644 --- a/src/show-owners-command.ts +++ b/src/show-owners-command.ts @@ -10,7 +10,7 @@ async function fileExists(path: string): Promise { } catch (e: unknown) { // @ts-expect-error we should see this error. if (e.code !== "FileNotFound") { - console.error(e) + console.error("github-code-owners:", e) } return false } @@ -108,7 +108,7 @@ export function showOwnersCommandHandler(outputChannel: vscode.OutputChannel) { line.range.end, ) // scroll the line into focus. - textEditor.revealRange(line.range) + textEditor.revealRange(line.range, vscode.TextEditorRevealType.InCenter) } } }