Skip to content

Commit 4d83c75

Browse files
🩹 [Patch]: Add OwnerUrl and RepositoryUrl properties to GitHubEnvironment class and enable hyperlinks in format display (#502)
## Changes Made Added two new properties to the `GitHubEnvironment` class: - `OwnerUrl` - URL to the owner/organization profile (e.g., `https://github.com/octocat`) - `RepositoryUrl` - URL to the repository (e.g., `https://github.com/octocat/Hello-World`) These properties are automatically populated in the constructor using the existing `Context.HostName` pattern, ensuring compatibility with both GitHub.com and GitHub Enterprise instances. Updated the URL property comments to include examples following the same format used in other classes: - `OwnerUrl` - Example: `https://github.com/octocat` - `RepositoryUrl` - Example: `https://github.com/octocat/Hello-World` - `Url` - Example: `https://github.com/octocat/Hello-World/settings/environments/123/edit` Updated the `GitHubEnvironment.Format.ps1xml` file to add hyperlinks to Owner and Repository columns when the host supports virtual terminal (and not running in GitHub Actions), following the same pattern used in other format files. ## Example Usage ```powershell $environment = Get-GitHubEnvironment -Owner 'octocat' -Repository 'Hello-World' -Name 'production' # New properties provide direct access to related URLs Write-Host "Owner URL: $($environment.OwnerUrl)" # https://github.com/octocat Write-Host "Repository URL: $($environment.RepositoryUrl)" # https://github.com/octocat/Hello-World Write-Host "Environment URL: $($environment.Url)" # https://github.com/octocat/Hello-World/settings/environments/123/edit ``` Now when displaying GitHubEnvironment objects in a table format, the Owner and Repository names will be clickable hyperlinks (when terminal supports it) that navigate to their respective GitHub pages. ## Benefits - **Consistency**: Follows the same URL pattern and documentation format established by other classes like `GitHubRepository` and `GitHubOwner` - **Enhanced UX**: Owner and Repository names are now clickable links in terminal environments that support hyperlinks - **Convenience**: Users no longer need to manually construct organization or repository URLs - **Enterprise Support**: Works seamlessly with custom GitHub Enterprise hostnames - **Non-breaking**: Purely additive changes that don't affect existing functionality Fixes #455. <!-- START COPILOT CODING AGENT TIPS --> --- đź’ˇ You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: MariusStorhaug <[email protected]>
1 parent fff966d commit 4d83c75

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

‎src/classes/public/Environment/GitHubEnvironment.ps1‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
# The owner of the environment.
99
[string] $Owner
1010

11+
# URL to the owner/organization profile.
12+
# Example: https://github.com/octocat
13+
[string] $OwnerUrl
14+
15+
# URL to the repository.
16+
# Example: https://github.com/octocat/Hello-World
17+
[string] $RepositoryUrl
18+
1119
# URL of the environment.
20+
# Example: https://github.com/octocat/Hello-World/settings/environments/123/edit
1221
[string] $Url
1322

1423
# The date and time the environment was created.
@@ -34,6 +43,8 @@
3443
$this.Name = $Object.name
3544
$this.Owner = $Owner
3645
$this.Repository = $Repository
46+
$this.OwnerUrl = "https://$($Context.HostName)/$Owner"
47+
$this.RepositoryUrl = "https://$($Context.HostName)/$Owner/$Repository"
3748
$this.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($Object.id)/edit"
3849
$this.CreatedAt = $Object.created_at
3950
$this.UpdatedAt = $Object.updated_at

‎src/formats/GitHubEnvironment.Format.ps1xml‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,24 @@
3232
</ScriptBlock>
3333
</TableColumnItem>
3434
<TableColumnItem>
35-
<PropertyName>Repository</PropertyName>
35+
<ScriptBlock>
36+
if ($Host.UI.SupportsVirtualTerminal -and
37+
($env:GITHUB_ACTIONS -ne 'true')) {
38+
$PSStyle.FormatHyperlink($_.Repository,$_.RepositoryUrl)
39+
} else {
40+
$_.Repository
41+
}
42+
</ScriptBlock>
3643
</TableColumnItem>
3744
<TableColumnItem>
38-
<PropertyName>Owner</PropertyName>
45+
<ScriptBlock>
46+
if ($Host.UI.SupportsVirtualTerminal -and
47+
($env:GITHUB_ACTIONS -ne 'true')) {
48+
$PSStyle.FormatHyperlink($_.Owner,$_.OwnerUrl)
49+
} else {
50+
$_.Owner
51+
}
52+
</ScriptBlock>
3953
</TableColumnItem>
4054
</TableColumnItems>
4155
</TableRowEntry>

0 commit comments

Comments
 (0)