diff --git a/.vscode/settings.json b/.vscode/settings.json index aa2c374..eb72a1a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,10 @@ "files.associations": { "test/data/**/*": "codeowners" }, + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, "[codeowners]": { // never autoformat test files "editor.defaultFormatter": null diff --git a/CHANGELOG.md b/CHANGELOG.md index fda21d3..a11a36b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## 3.4.0 - 2024-04-10 + +### Added + +- Slack channel mapping via `github-code-owners.team-mapping.slack` setting. + ## 3.3.0 - 2023-11-15 ### Added diff --git a/package-lock.json b/package-lock.json index a475f1a..beb5bbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "github-code-owners", - "version": "3.2.0", + "version": "3.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "github-code-owners", - "version": "3.2.0", + "version": "3.4.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 75691a6..93ff5b2 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.3.0", + "version": "3.4.0", "icon": "images/logo256.png", "homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md", "keywords": [ @@ -72,6 +72,52 @@ "default": 4, "minimum": 1, "description": "Space offset to use from the longest file pattern the first code owner when aligning." + }, + "github-code-owners.team-mapping.slack": { + "type": "array", + "default": [], + "markdownDescription": "Map GitHub teams to Slack channels.", + "items": { + "type": "object", + "properties": { + "team": { + "type": "string", + "examples": [ + "@acme-corp/frontend" + ], + "markdownDescription": "GitHub team", + "pattern": "^@", + "patternErrorMessage": "GitHub teams must start with @", + "required": true + }, + "domain": { + "type": "string", + "markdownDescription": "Slack domain", + "examples": [ + "acme-corp.slack.com" + ], + "required": true + }, + "channel": { + "type": "string", + "markdownDescription": "Slack channel", + "examples": [ + "#eng-frontend" + ], + "pattern": "^#", + "patternErrorMessage": "Slack channels must start with #", + "required": true + } + }, + "required": true, + "examples": [ + { + "team": "@acme-corp/frontend", + "domain": "acme-corp.slack.com", + "channel": "#eng-frontend" + } + ] + } } } } diff --git a/src/github-usernames-link-provider.ts b/src/github-usernames-link-provider.ts index a03e20f..effed5e 100644 --- a/src/github-usernames-link-provider.ts +++ b/src/github-usernames-link-provider.ts @@ -29,6 +29,26 @@ function getGitHubUrl(): string { return setting } +type SlackMappingConfigurationItem = { + domain: string + channel: string + team: string +} + +function getTeamMappingSlack() { + const setting = + vscode.workspace + .getConfiguration() + .get>( + "github-code-owners.team-mapping.slack", + ) ?? [] + const mapping: Record = {} + for (const team of setting) { + mapping[team.team] = team + } + return mapping +} + /** * Add links to usernames in CODEOWNERS file that open on GitHub. */ @@ -38,6 +58,7 @@ export class GitHubUsernamesLinkProvider provideDocumentLinks( document: vscode.TextDocument, ): vscode.ProviderResult { + const slackTeamMapping = getTeamMappingSlack() const links = [] for (const range of findUsernameRanges(document)) { if (range) { @@ -52,9 +73,25 @@ export class GitHubUsernamesLinkProvider range, githubUserToUrl(username.replace(/^@/, "")), ) - link.tooltip = `View ${username} on Github` - + link.tooltip = `Open ${username} on Github` links.push(link) + + const slackMapping = slackTeamMapping[username] + if (slackMapping) { + const linkslack = new vscode.DocumentLink( + range, + // https://api.slack.com/reference/deep-linking + // https://acme-corp.slack.com/channels/eng-frontend + vscode.Uri.parse( + `https://${ + slackMapping.domain + }/app_redirect?channel=${slackMapping.channel.replace(/^#/, "")}`, + ), + ) + linkslack.tooltip = `Open ${slackMapping.channel} on Slack` + + links.push(linkslack) + } } } return links