Skip to content

WIP: Populate companyname and other properties for PSResourceInfo #723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ private List<PSResourceInfo> InstallPackage(
}

moduleManifestVersion = parsedMetadataHashtable["ModuleVersion"] as string;
pkg.CompanyName = parsedMetadataHashtable["CompanyName"] as string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know that parsedMetadataHashtable will always have these entries?

pkg.Copyright = parsedMetadataHashtable["Copyright"] as string;
pkg.ReleaseNotes = parsedMetadataHashtable["ReleaseNotes"] as string;
pkg.RepositorySourceLocation = repoUri;

// Accept License verification
if (!_savePkg && !CallAcceptLicense(pkg, moduleManifest, tempInstallPath, newVersion))
Expand All @@ -553,6 +557,28 @@ private List<PSResourceInfo> InstallPackage(
continue;
}
}
else
{
// is script
if (!PSScriptFileInfo.TryTestPSScriptFile(
scriptFileInfoPath: scriptPath,
out PSScriptFileInfo parsedScript,
out ErrorRecord[] errors,
out string[] _))
{
foreach (ErrorRecord parseError in errors)
{
WriteError(parseError);
}

continue;
}

pkg.CompanyName = parsedScript.ScriptMetadataComment.CompanyName;
pkg.Copyright = parsedScript.ScriptMetadataComment.Copyright;
pkg.ReleaseNotes = parsedScript.ScriptMetadataComment.ReleaseNotes;
pkg.RepositorySourceLocation = repoUri;
}

// Delete the extra nupkg related files that are not needed and not part of the module/script
DeleteExtraneousFiles(pkgIdentity, tempDirNameVersion);
Expand Down
8 changes: 4 additions & 4 deletions src/code/PSResourceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public sealed class PSResourceInfo

public Dictionary<string, string> AdditionalMetadata { get; }
public string Author { get; }
public string CompanyName { get; }
public string Copyright { get; }
public string CompanyName { get; internal set; }
public string Copyright { get; internal set; }
public Dependency[] Dependencies { get; }
public string Description { get; }
public Uri IconUri { get; }
Expand All @@ -250,9 +250,9 @@ public sealed class PSResourceInfo
public string Prerelease { get; }
public Uri ProjectUri { get; }
public DateTime? PublishedDate { get; }
public string ReleaseNotes { get; }
public string ReleaseNotes { get; internal set; }
public string Repository { get; }
public string RepositorySourceLocation { get; }
public string RepositorySourceLocation { get; internal set; }
public string[] Tags { get; }
public ResourceType Type { get; }
public DateTime? UpdatedDate { get; }
Expand Down
12 changes: 12 additions & 0 deletions test/InstallPSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Describe 'Test Install-PSResource for Module' {
BeforeAll {
$PSGalleryName = Get-PSGalleryName
$NuGetGalleryName = Get-NuGetGalleryName
$PSGalleryUri = Get-PSGalleryLocation
$testModuleName = "test_module"
$testModuleName2 = "TestModule99"
$testScriptName = "test_script"
Expand Down Expand Up @@ -173,6 +174,17 @@ Describe 'Test Install-PSResource for Module' {
$pkg.Version | Should -Be "5.0.0.0"
}

It "Install resource with companyname, copyright and repository source location and validate" {
Install-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository PSGallery -TrustRepository
$pkg = Get-PSResource $testModuleName
$pkg.Version | Should -Be "5.2.5"
$pkg.Prerelease | Should -Be "alpha001"

$pkg.CompanyName | Should -Be "Anam"
$pkg.Copyright | Should -Be "(c) Anam Navied. All rights reserved."
$pkg.RepositorySourceLocation | Should -Be $PSGalleryUri
}

# Windows only
It "Install resource under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) {
Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -Scope CurrentUser
Expand Down