Skip to content

Commit 248b2a1

Browse files
🩹 [Patch]: Update all classes formats to hyperlink to resources (#438)
## Description This pull request introduces several enhancements and fixes across the codebase, focusing on improving functionality, readability, and modularity. Key changes include updates to the `GitHubArtifact` class, refinements in configuration handling, improved hyperlink formatting, and adjustments to environment detection logic. ### Enhancements to `GitHubArtifact` Class: * Added a new `HostName` parameter to the `GitHubArtifact` constructor to dynamically construct artifact URLs based on the host. Updated all relevant artifact retrieval functions (`Get-GitHubArtifactById`, `Get-GitHubArtifactFromRepository`, and `Get-GitHubArtifactFromWorkflowRun`) to pass the `HostName` parameter. ### Configuration Improvements: * Introduced a new `EnvironmentType` property in the `GitHubConfig` class to better define the context for GitHub API calls. * Added a new XML format definition (`GitHubConfig.Format.ps1xml`) for displaying `GitHubConfig` objects in a list view, including properties such as `HostName`, `ApiBaseUri`, and `EnvironmentType`. * Refactored the `Get-GitHubConfig` function to support two parameter sets for retrieving either the entire module configuration or a specific configuration item. ### Hyperlink Formatting: * Updated hyperlink formatting across multiple XML format files (`GitHubArtifact.Format.ps1xml`, `GitHubEnvironment.Format.ps1xml`, `GitHubLicense.Format.ps1xml`, `GitHubOwner.Format.ps1xml`, `GitHubRelease.Format.ps1xml`, `GitHubRepository.Format.ps1xml`, `GitHubTeam.Format.ps1xml`) to use `PSStyle.FormatHyperlink` for better compatibility with virtual terminal support. Fallback ensures plain text formatting when virtual terminal is not supported or in GitHub Actions environments. ### Environment Detection Logic: * Replaced direct checks for `GITHUB_ACTIONS` and `WEBSITE_PLATFORM_VERSION` environment variables with new script-level flags (`IsGitHubActions` and `IsFunctionApp`) for determining runtime environments. Updated references across multiple functions (`Set-GitHubContext`, `Get-GitHubEnvironmentType`, `Connect-GitHubAccount`, `Connect-GitHubApp`, `Disconnect-GitHubAccount`). ### Minor Changes: * Added support for additional type names (`GitHubUser` and `GitHubOrganization`) in the `GitHubOwnerTable` view definition. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent bfe8771 commit 248b2a1

23 files changed

+166
-38
lines changed

src/classes/public/Artifacts/GitHubArtifact.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737

3838
GitHubArtifact() {}
3939

40-
GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository) {
40+
GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [string]$HostName) {
4141
$this.ID = $Object.id
4242
$this.NodeID = $Object.node_id
4343
$this.Name = $Object.name
4444
$this.Owner = $Owner
4545
$this.Repository = $Repository
4646
$this.Size = $Object.size_in_bytes
47-
$this.Url = $Object.url
47+
$this.Url = "https://$($HostName)/$Owner/$Repository/actions/runs/$($Object.workflow_run.id)/artifacts/$($Object.id)"
4848
$this.ArchiveDownloadUrl = $Object.archive_download_url
4949
$this.Expired = $Object.expired
5050
$this.Digest = $Object.digest

src/classes/public/Config/GitHubConfig.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
# The tolerance time in seconds for JWT token validation.
3939
[System.Nullable[int]] $JwtTimeTolerance
4040

41+
# The environment type, which is used to determine the context of the GitHub API calls.
42+
[string] $EnvironmentType
43+
4144
# Simple parameterless constructor
4245
GitHubConfig() {}
4346

src/formats/GitHubArtifact.Format.ps1xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434
<PropertyName>ID</PropertyName>
3535
</TableColumnItem>
3636
<TableColumnItem>
37-
<ScriptBlock>"`e]8;;$($_.Url)`e\$($_.Name)`e]8;;`e\"</ScriptBlock>
37+
<ScriptBlock>
38+
if ($Host.UI.SupportsVirtualTerminal -and
39+
($env:GITHUB_ACTIONS -ne 'true')) {
40+
$PSStyle.FormatHyperlink($_.Name,$_.Url)
41+
} else {
42+
$_.Name
43+
}
44+
</ScriptBlock>
3845
</TableColumnItem>
3946
<TableColumnItem>
4047
<ScriptBlock>'{0:F2}' -f ([math]::Round($_.Size / 1KB, 2))</ScriptBlock>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Configuration>
3+
<ViewDefinitions>
4+
<View>
5+
<Name>GitHubConfigListView</Name>
6+
<ViewSelectedBy>
7+
<TypeName>GitHubConfig</TypeName>
8+
</ViewSelectedBy>
9+
<ListControl>
10+
<ListEntries>
11+
<ListEntry>
12+
<ListItems>
13+
<ListItem>
14+
<PropertyName>HostName</PropertyName>
15+
</ListItem>
16+
<ListItem>
17+
<PropertyName>ApiBaseUri</PropertyName>
18+
</ListItem>
19+
<ListItem>
20+
<PropertyName>GitHubAppClientID</PropertyName>
21+
</ListItem>
22+
<ListItem>
23+
<PropertyName>OAuthAppClientID</PropertyName>
24+
</ListItem>
25+
<ListItem>
26+
<PropertyName>EnvironmentType</PropertyName>
27+
</ListItem>
28+
<ListItem>
29+
<PropertyName>DefaultContext</PropertyName>
30+
</ListItem>
31+
<ListItem>
32+
<PropertyName>AccessTokenGracePeriodInHours</PropertyName>
33+
</ListItem>
34+
<ListItem>
35+
<PropertyName>JwtTimeTolerance</PropertyName>
36+
</ListItem>
37+
<ListItem>
38+
<PropertyName>ApiVersion</PropertyName>
39+
</ListItem>
40+
<ListItem>
41+
<PropertyName>HttpVersion</PropertyName>
42+
</ListItem>
43+
<ListItem>
44+
<PropertyName>PerPage</PropertyName>
45+
</ListItem>
46+
<ListItem>
47+
<PropertyName>RetryCount</PropertyName>
48+
</ListItem>
49+
<ListItem>
50+
<PropertyName>RetryInterval</PropertyName>
51+
</ListItem>
52+
</ListItems>
53+
</ListEntry>
54+
</ListEntries>
55+
</ListControl>
56+
</View>
57+
</ViewDefinitions>
58+
</Configuration>

src/formats/GitHubEnvironment.Format.ps1xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
<TableRowEntry>
2323
<TableColumnItems>
2424
<TableColumnItem>
25-
<ScriptBlock>"`e]8;;$($_.Url)`e\$($_.Name)`e]8;;`e\"</ScriptBlock>
25+
<ScriptBlock>
26+
if ($Host.UI.SupportsVirtualTerminal -and
27+
($env:GITHUB_ACTIONS -ne 'true')) {
28+
$PSStyle.FormatHyperlink($_.Name,$_.Url)
29+
} else {
30+
$_.Name
31+
}
32+
</ScriptBlock>
2633
</TableColumnItem>
2734
<TableColumnItem>
2835
<PropertyName>Repository</PropertyName>

src/formats/GitHubLicense.Format.ps1xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@
3131
<PropertyName>Key</PropertyName>
3232
</TableColumnItem>
3333
<TableColumnItem>
34-
<ScriptBlock>"`e]8;;$($_.Url)`e\$($_.Name)`e]8;;`e\"</ScriptBlock>
34+
<ScriptBlock>
35+
if ($Host.UI.SupportsVirtualTerminal -and
36+
($env:GITHUB_ACTIONS -ne 'true')) {
37+
$PSStyle.FormatHyperlink($_.Name,$_.Url)
38+
} else {
39+
$_.Name
40+
}
41+
</ScriptBlock>
3542
</TableColumnItem>
3643
<TableColumnItem>
3744
<PropertyName>SpdxId</PropertyName>

src/formats/GitHubOwner.Format.ps1xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<Name>GitHubOwnerTable</Name>
66
<ViewSelectedBy>
77
<TypeName>GitHubOwner</TypeName>
8+
<TypeName>GitHubUser</TypeName>
9+
<TypeName>GitHubOrganization</TypeName>
810
</ViewSelectedBy>
911
<TableControl>
1012
<TableHeaders>
@@ -28,7 +30,14 @@
2830
<TableRowEntry>
2931
<TableColumnItems>
3032
<TableColumnItem>
31-
<ScriptBlock>"`e]8;;$($_.Url)`e\$($_.Name)`e]8;;`e\"</ScriptBlock>
33+
<ScriptBlock>
34+
if ($Host.UI.SupportsVirtualTerminal -and
35+
($env:GITHUB_ACTIONS -ne 'true')) {
36+
$PSStyle.FormatHyperlink($_.Name,$_.Url)
37+
} else {
38+
$_.Name
39+
}
40+
</ScriptBlock>
3241
</TableColumnItem>
3342
<TableColumnItem>
3443
<PropertyName>ID</PropertyName>

src/formats/GitHubRelease.Format.ps1xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@
3131
<TableRowEntry>
3232
<TableColumnItems>
3333
<TableColumnItem>
34-
<ScriptBlock>"`e]8;;$($_.Url)`e\$($_.Tag)`e]8;;`e\"</ScriptBlock>
34+
<ScriptBlock>
35+
if ($Host.UI.SupportsVirtualTerminal -and
36+
($env:GITHUB_ACTIONS -ne 'true')) {
37+
$PSStyle.FormatHyperlink($_.Tag,$_.Url)
38+
} else {
39+
$_.Tag
40+
}
41+
</ScriptBlock>
3542
</TableColumnItem>
3643
<TableColumnItem>
3744
<PropertyName>Owner</PropertyName>

src/formats/GitHubRepository.Format.ps1xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
<TableRowEntry>
2626
<TableColumnItems>
2727
<TableColumnItem>
28-
<ScriptBlock>"`e]8;;$($_.Url)`e\$($_.Name)`e]8;;`e\"</ScriptBlock>
28+
<ScriptBlock>
29+
if ($Host.UI.SupportsVirtualTerminal -and
30+
($env:GITHUB_ACTIONS -ne 'true')) {
31+
$PSStyle.FormatHyperlink($_.Name,$_.Url)
32+
} else {
33+
$_.Name
34+
}
35+
</ScriptBlock>
2936
</TableColumnItem>
3037
<TableColumnItem>
3138
<PropertyName>Owner</PropertyName>

src/formats/GitHubTeam.Format.ps1xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
<TableRowEntry>
2020
<TableColumnItems>
2121
<TableColumnItem>
22-
<ScriptBlock>"`e]8;;$($_.Url)`e\$($_.Name)`e]8;;`e\"</ScriptBlock>
22+
<ScriptBlock>
23+
if ($Host.UI.SupportsVirtualTerminal -and
24+
($env:GITHUB_ACTIONS -ne 'true')) {
25+
$PSStyle.FormatHyperlink($_.Name,$_.Url)
26+
} else {
27+
$_.Name
28+
}
29+
</ScriptBlock>
2330
</TableColumnItem>
2431
<TableColumnItem>
2532
<PropertyName>Owner</PropertyName>

0 commit comments

Comments
 (0)