Skip to content

Commit

Permalink
document "open in slack". reload on settings change (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
chdsbd authored May 11, 2024
1 parent 1159791 commit cfac5aa
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 26 deletions.
65 changes: 65 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -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 [email protected]

# 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/* [email protected]

# 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
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Shows the first code owner. Click to see matching line in CODEOWNERS file.

<img src="./images/open-in-github.png" alt="click to open username in GitHub" height="70px"/>

#### Link usernames to Slack

<img src="./images/open-in-slack.png" alt="click to open username in GitHub" height="110px"/>

> Define a Slack mapping in your VSCode settings (`github-code-owners.team-mapping.slack`) to enable this feature.
#### Auto complete

<img src="./images/autocomplete.gif" alt="auto complete of paths and usernames" width="618px" height="359px"/>
Expand All @@ -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`.
<img src="./images/formatting.gif" alt="auto complete of paths and usernames" width="408px" height="185px"/>
Expand Down
Binary file added images/open-in-slack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": {
Expand All @@ -112,7 +112,7 @@
"required": true,
"examples": [
{
"team": "@acme-corp/frontend",
"username": "@acme-corp/frontend",
"domain": "acme-corp.slack.com",
"channel": "#eng-frontend"
}
Expand Down
13 changes: 4 additions & 9 deletions src/codeowners-hover-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ export class CodeownersHoverProvider implements vscode.HoverProvider {
provideHover(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken,
): vscode.ProviderResult<vscode.Hover> {
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: [] }
Expand All @@ -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)
Expand All @@ -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: [] }
}
}
19 changes: 15 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(),
)
})
}
4 changes: 2 additions & 2 deletions src/github-usernames-link-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getGitHubUrl(): string {
type SlackMappingConfigurationItem = {
domain: string
channel: string
team: string
username: string
}

function getTeamMappingSlack() {
Expand All @@ -44,7 +44,7 @@ function getTeamMappingSlack() {
) ?? []
const mapping: Record<string, SlackMappingConfigurationItem | undefined> = {}
for (const team of setting) {
mapping[team.team] = team
mapping[team.username] = team
}
return mapping
}
Expand Down
4 changes: 2 additions & 2 deletions src/show-owners-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function fileExists(path: string): Promise<boolean> {
} 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
}
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit cfac5aa

Please sign in to comment.