Skip to content

Commit

Permalink
feat: Add GHES support (#23)
Browse files Browse the repository at this point in the history
This PR adds support for generating user and team links when VSCode is
configured with a Github Enterprise Server authentication provider, as
suggested in #22 .

One consequence is links to users and teams will use the GHES url when
switching to a repo that was cloned from github.com. This is an issue
any plugin will face in this scenario and not unique to this one. In
situations like this, it may be advisable for users to utilize VSCode's
Workspace feature, keeping GHES-based repos in one Workspace and
Github.com-based repos in another while syncing their extensions and
settings appropriately.
  • Loading branch information
jeffstoner committed Aug 17, 2023
1 parent c3164f0 commit 30716f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 3.2.0 - 2023-08-16

### Added

- GitHub Enterprise support (#23). Thanks @jeffstoner!

## 3.1.0 - 2023-08-08

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion 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.1.0",
"version": "3.2.0",
"icon": "images/logo256.png",
"homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md",
"keywords": [
Expand Down
22 changes: 20 additions & 2 deletions src/github-usernames-link-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@ import { findUsernameRanges } from "./owner-name-completion-item-provider"

function githubUserToUrl(username: string): vscode.Uri {
const isTeamName = username.includes("/")
const gitHubUrl = getGitHubUrl()

if (isTeamName) {
const [org, name] = username.split(/\//)
return vscode.Uri.parse(`https://github.com/orgs/${org}/teams/${name}`)
return vscode.Uri.parse(gitHubUrl + `/orgs/${org}/teams/${name}`)
}
return vscode.Uri.parse(`https://github.com/${username}`)
return vscode.Uri.parse(gitHubUrl + `/${username}`)
}

function getGitHubUrl(): string {
/*
* When using GitHub Enterprise Server, you should have a 'github-enterprise.uri'
* configuration setting.
*
* This configuration option is provided by built in "GitHub Authentication" extension
* https://github.com/microsoft/vscode/blob/ccb95fd921349023027a0df25ed291b0992b9a18/extensions/github-authentication/src/extension.ts#L10
*/
const setting = vscode.workspace
.getConfiguration()
.get<string>("github-enterprise.uri")
if (!setting) {
return "https://github.com"
}
return setting
}

/**
Expand Down

0 comments on commit 30716f4

Please sign in to comment.