Skip to content

Commit 1159791

Browse files
add slack channel mapping (#26)
1 parent cd4c8ea commit 1159791

5 files changed

Lines changed: 98 additions & 5 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"files.associations": {
77
"test/data/**/*": "codeowners"
88
},
9+
"[typescript]": {
10+
"editor.defaultFormatter": "esbenp.prettier-vscode",
11+
"editor.formatOnSave": true
12+
},
913
"[codeowners]": {
1014
// never autoformat test files
1115
"editor.defaultFormatter": null

CHANGELOG.md

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

88
## [Unreleased]
99

10+
## 3.4.0 - 2024-04-10
11+
12+
### Added
13+
14+
- Slack channel mapping via `github-code-owners.team-mapping.slack` setting (#26).
15+
1016
## 3.3.0 - 2023-11-15
1117

1218
### Added

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: 47 additions & 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": "3.3.0",
7+
"version": "3.4.0",
88
"icon": "images/logo256.png",
99
"homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md",
1010
"keywords": [
@@ -72,6 +72,52 @@
7272
"default": 4,
7373
"minimum": 1,
7474
"description": "Space offset to use from the longest file pattern the first code owner when aligning."
75+
},
76+
"github-code-owners.team-mapping.slack": {
77+
"type": "array",
78+
"default": [],
79+
"markdownDescription": "Map GitHub teams to Slack channels.",
80+
"items": {
81+
"type": "object",
82+
"properties": {
83+
"team": {
84+
"type": "string",
85+
"examples": [
86+
"@acme-corp/frontend"
87+
],
88+
"markdownDescription": "GitHub team",
89+
"pattern": "^@",
90+
"patternErrorMessage": "GitHub teams must start with @",
91+
"required": true
92+
},
93+
"domain": {
94+
"type": "string",
95+
"markdownDescription": "Slack domain",
96+
"examples": [
97+
"acme-corp.slack.com"
98+
],
99+
"required": true
100+
},
101+
"channel": {
102+
"type": "string",
103+
"markdownDescription": "Slack channel",
104+
"examples": [
105+
"#eng-frontend"
106+
],
107+
"pattern": "^#",
108+
"patternErrorMessage": "Slack channels must start with #",
109+
"required": true
110+
}
111+
},
112+
"required": true,
113+
"examples": [
114+
{
115+
"team": "@acme-corp/frontend",
116+
"domain": "acme-corp.slack.com",
117+
"channel": "#eng-frontend"
118+
}
119+
]
120+
}
75121
}
76122
}
77123
}

src/github-usernames-link-provider.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ function getGitHubUrl(): string {
2929
return setting
3030
}
3131

32+
type SlackMappingConfigurationItem = {
33+
domain: string
34+
channel: string
35+
team: string
36+
}
37+
38+
function getTeamMappingSlack() {
39+
const setting =
40+
vscode.workspace
41+
.getConfiguration()
42+
.get<Array<SlackMappingConfigurationItem>>(
43+
"github-code-owners.team-mapping.slack",
44+
) ?? []
45+
const mapping: Record<string, SlackMappingConfigurationItem | undefined> = {}
46+
for (const team of setting) {
47+
mapping[team.team] = team
48+
}
49+
return mapping
50+
}
51+
3252
/**
3353
* Add links to usernames in CODEOWNERS file that open on GitHub.
3454
*/
@@ -38,6 +58,7 @@ export class GitHubUsernamesLinkProvider
3858
provideDocumentLinks(
3959
document: vscode.TextDocument,
4060
): vscode.ProviderResult<vscode.DocumentLink[]> {
61+
const slackTeamMapping = getTeamMappingSlack()
4162
const links = []
4263
for (const range of findUsernameRanges(document)) {
4364
if (range) {
@@ -52,9 +73,25 @@ export class GitHubUsernamesLinkProvider
5273
range,
5374
githubUserToUrl(username.replace(/^@/, "")),
5475
)
55-
link.tooltip = `View ${username} on Github`
56-
76+
link.tooltip = `Open ${username} on Github`
5777
links.push(link)
78+
79+
const slackMapping = slackTeamMapping[username]
80+
if (slackMapping) {
81+
const linkslack = new vscode.DocumentLink(
82+
range,
83+
// https://api.slack.com/reference/deep-linking
84+
// https://acme-corp.slack.com/channels/eng-frontend
85+
vscode.Uri.parse(
86+
`https://${
87+
slackMapping.domain
88+
}/app_redirect?channel=${slackMapping.channel.replace(/^#/, "")}`,
89+
),
90+
)
91+
linkslack.tooltip = `Open ${slackMapping.channel} on Slack`
92+
93+
links.push(linkslack)
94+
}
5895
}
5996
}
6097
return links

0 commit comments

Comments
 (0)