Skip to content

Commit cfac5aa

Browse files
authored
document "open in slack". reload on settings change (#28)
1 parent 1159791 commit cfac5aa

11 files changed

Lines changed: 120 additions & 26 deletions

.github/CODEOWNERS

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence,
6+
# @global-owner1 and @global-owner2 will be requested for
7+
# review when someone opens a pull request.
8+
* @global-owner1 @global-owner2
9+
10+
# Order is important; the last matching pattern takes the most
11+
# precedence. When someone opens a pull request that only
12+
# modifies JS files, only @js-owner and not the global
13+
# owner(s) will be requested for a review.
14+
*.js @js-owner #This is an inline comment.
15+
16+
# You can also use email addresses if you prefer. They'll be
17+
# used to look up users just like we do for commit author
18+
# emails.
19+
*.go docs@example.com
20+
21+
# Teams can be specified as code owners as well. Teams should
22+
# be identified in the format @org/team-name. Teams must have
23+
# explicit write access to the repository. In this example,
24+
# the octocats team in the octo-org organization owns all .txt files.
25+
*.txt @octo-org/octocats
26+
27+
# In this example, @doctocat owns any files in the build/logs
28+
# directory at the root of the repository and any of its
29+
# subdirectories.
30+
/build/logs/ @doctocat
31+
32+
# The `docs/*` pattern will match files like
33+
# `docs/getting-started.md` but not further nested files like
34+
# `docs/build-app/troubleshooting.md`.
35+
docs/* docs@example.com
36+
37+
# In this example, @octocat owns any file in an apps directory
38+
# anywhere in your repository.
39+
apps/ @octocat
40+
41+
# In this example, @doctocat owns any file in the `/docs`
42+
# directory in the root of your repository and any of its
43+
# subdirectories.
44+
/docs/ @doctocat
45+
46+
# In this example, any change inside the `/scripts` directory
47+
# will require approval from @doctocat or @octocat.
48+
/scripts/ @doctocat @octocat
49+
50+
# In this example, @octocat owns any file in a `/logs` directory such as
51+
# `/build/logs`, `/scripts/logs`, and `/deeply/nested/logs`. Any changes
52+
# in a `/logs` directory will require approval from @octocat.
53+
**/logs @octocat
54+
55+
# In this example, @octocat owns any file in the `/apps`
56+
# directory in the root of your repository except for the `/apps/github`
57+
# subdirectory, as its owners are left empty.
58+
/apps/ @octocat
59+
/apps/github
60+
61+
# In this example, @octocat owns any file in the `/apps`
62+
# directory in the root of your repository except for the `/apps/github`
63+
# subdirectory, as this subdirectory has its own owner @doctocat
64+
/apps/ @octocat
65+
/apps/github @doctocat

.vscode/settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,12 @@
1313
"[codeowners]": {
1414
// never autoformat test files
1515
"editor.defaultFormatter": null
16-
}
16+
},
17+
"github-code-owners.team-mapping.slack": [
18+
{
19+
"team": "@octo-org/octocats",
20+
"domain": "octo-org.slack.com",
21+
"channel": "#help-octo-ui"
22+
}
23+
]
1724
}

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## 4.0.0 - 2024-04-11
11+
12+
### Added
13+
14+
- Reload link provider when settings change (#28).
15+
- Center editor on CODEOWNERS line when jumping to owner via status bar (#28).
16+
17+
### Changed
18+
19+
- Rename GitHub "team" setting to "username" to be consistent with existing features (#28).
20+
1021
## 3.4.0 - 2024-04-10
1122

1223
### Added

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Shows the first code owner. Click to see matching line in CODEOWNERS file.
1616

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

19+
#### Link usernames to Slack
20+
21+
<img src="./images/open-in-slack.png" alt="click to open username in GitHub" height="110px"/>
22+
23+
> Define a Slack mapping in your VSCode settings (`github-code-owners.team-mapping.slack`) to enable this feature.
24+
1925
#### Auto complete
2026

2127
<img src="./images/autocomplete.gif" alt="auto complete of paths and usernames" width="618px" height="359px"/>
@@ -26,7 +32,6 @@ Shows the first code owner. Click to see matching line in CODEOWNERS file.
2632

2733
#### Formatting
2834

29-
> [!TIP]
3035
> Enable formatting by setting `github-code-owners.format.enabled` to `true`.
3136
3237
<img src="./images/formatting.gif" alt="auto complete of paths and usernames" width="408px" height="185px"/>

images/open-in-slack.png

55.5 KB
Loading

package-lock.json

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

package.json

Lines changed: 5 additions & 5 deletions
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": "3.4.0",
7+
"version": "4.0.0",
88
"icon": "images/logo256.png",
99
"homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md",
1010
"keywords": [
@@ -80,14 +80,14 @@
8080
"items": {
8181
"type": "object",
8282
"properties": {
83-
"team": {
83+
"username": {
8484
"type": "string",
8585
"examples": [
8686
"@acme-corp/frontend"
8787
],
88-
"markdownDescription": "GitHub team",
88+
"markdownDescription": "GitHub username",
8989
"pattern": "^@",
90-
"patternErrorMessage": "GitHub teams must start with @",
90+
"patternErrorMessage": "GitHub usernames must start with @",
9191
"required": true
9292
},
9393
"domain": {
@@ -112,7 +112,7 @@
112112
"required": true,
113113
"examples": [
114114
{
115-
"team": "@acme-corp/frontend",
115+
"username": "@acme-corp/frontend",
116116
"domain": "acme-corp.slack.com",
117117
"channel": "#eng-frontend"
118118
}

src/codeowners-hover-provider.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@ export class CodeownersHoverProvider implements vscode.HoverProvider {
66
provideHover(
77
document: vscode.TextDocument,
88
position: vscode.Position,
9-
token: vscode.CancellationToken,
109
): vscode.ProviderResult<vscode.Hover> {
11-
console.log({ document, position, token })
1210
const line = document.lineAt(position.line)
13-
// if (line.text.match(/^\s/))
14-
console.log(line)
15-
const start = line.text.split(" ")[0]
16-
console.log({ start })
1711
const m = line.text.match(/^\s*(\S+)/)?.[1]
1812
if (m == null) {
1913
return { contents: [] }
@@ -27,7 +21,10 @@ export class CodeownersHoverProvider implements vscode.HoverProvider {
2721
try {
2822
isDirectory = fs.statSync(myPath).isDirectory()
2923
} catch (e) {
30-
console.error(e)
24+
// @ts-expect-error we should see this error.
25+
if (e.code !== "ENOENT") {
26+
console.error("github-code-owners", e)
27+
}
3128
}
3229
const x = new vscode.MarkdownString()
3330
x.appendCodeblock(m)
@@ -50,9 +47,7 @@ export class CodeownersHoverProvider implements vscode.HoverProvider {
5047
: isDirectory
5148
? `Matches all files in directory and subdirectories`
5249
: `Matches path exactly`,
53-
// !isPattern && isDirectory == null ? "Path does not exist" : "",
5450
],
5551
}
56-
// return { contents: [] }
5752
}
5853
}

src/extension.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ export function activate(context: vscode.ExtensionContext) {
1616
console.log("CODEOWNERS: activated")
1717
const outputChannel = vscode.window.createOutputChannel("Github Code Owners")
1818

19-
vscode.languages.registerDocumentLinkProvider(
20-
"codeowners",
21-
new GitHubUsernamesLinkProvider(),
22-
)
19+
const handles = {
20+
linkProvider: vscode.languages.registerDocumentLinkProvider(
21+
"codeowners",
22+
new GitHubUsernamesLinkProvider(),
23+
),
24+
}
2325

2426
vscode.languages.registerDocumentFormattingEditProvider(
2527
"codeowners",
@@ -66,4 +68,13 @@ export function activate(context: vscode.ExtensionContext) {
6668
statusBarTextEditorListener(statusBarItem, outputChannel),
6769
),
6870
)
71+
72+
vscode.workspace.onDidChangeConfiguration(() => {
73+
outputChannel.appendLine("Configuration changed: Reloading link provider")
74+
handles.linkProvider.dispose()
75+
handles.linkProvider = vscode.languages.registerDocumentLinkProvider(
76+
"codeowners",
77+
new GitHubUsernamesLinkProvider(),
78+
)
79+
})
6980
}

src/github-usernames-link-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function getGitHubUrl(): string {
3232
type SlackMappingConfigurationItem = {
3333
domain: string
3434
channel: string
35-
team: string
35+
username: string
3636
}
3737

3838
function getTeamMappingSlack() {
@@ -44,7 +44,7 @@ function getTeamMappingSlack() {
4444
) ?? []
4545
const mapping: Record<string, SlackMappingConfigurationItem | undefined> = {}
4646
for (const team of setting) {
47-
mapping[team.team] = team
47+
mapping[team.username] = team
4848
}
4949
return mapping
5050
}

0 commit comments

Comments
 (0)