Skip to content
28 changes: 25 additions & 3 deletions Docs/Get-GitModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ This cmdlet will check for existence of PowerShell module in given repository an

## SYNTAX

### ByUri
```
Get-GitModule [-ProjectUri] <String[]> [-Branch <String>] [-KeepTempCopy] [<CommonParameters>]
```

### ByName
```
Get-GitModule -Name <String[]> [-Branch <String>] [-KeepTempCopy] [<CommonParameters>]
```

## DESCRIPTION
This cmdlet will check for existence of PowerShell module in given repository and return its version.
You can also specify desired git branch.
Expand All @@ -24,7 +30,7 @@ Cmdlet requires \`git\` client tool to work.
It will download (\`git clone\`) specified repository to temporary directory and analyze it.
By default, it will delete this temporary copy, but if needed, it can be kept.

Cmdlet searches for module manifest ( .psd1) file or if that is not found for module (.psm1) file itself.
Cmdlet searches for module manifest ( .psd1) file. If that is not found, then it searches for module (.psm1) file itself.

## EXAMPLES

Expand All @@ -39,7 +45,7 @@ Root : True
Git : https://github.com/iricigor/FIFA2018
```

This cmdlet will check for existence of PowerShell module in given repository (https://github.com/iricigor/FIFA2018') and return its version (currently 0.3.46) .
This cmdlet will check for existence of PowerShell module in given repository (https://github.com/iricigor/FIFA2018') and return its version (currently 0.3.46).

### Example 2
```
Expand Down Expand Up @@ -90,6 +96,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Name
You can query already installed modules for their online version if ProjectUri is specified in the module info.
To do this, just specify module name(s) with parameter -Names.

```yaml
Type: String[]
Parameter Sets: ByName
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ProjectUri
Mandatory parameter specifying URL or the repository.
Multiple values are supported.
Expand All @@ -100,7 +122,7 @@ You can pass this parameter also via pipeline, for example via \`Find-Module\` b

```yaml
Type: String[]
Parameter Sets: (All)
Parameter Sets: ByUri
Aliases:

Required: True
Expand Down
36 changes: 33 additions & 3 deletions Public/Get-GitModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ function Get-GitModule {
param (


[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)]
[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0,ParameterSetName='ByUri')]
[string[]]$ProjectUri,
# https://github.com/dfinke/InstallModuleFromGitHub
# https://github.com/iricigor/FIFA2018

[Parameter(Mandatory,ParameterSetName='ByName')]
[string[]]$Name,

[string]$Branch = "master",
[switch]$KeepTempCopy

Expand All @@ -28,7 +31,29 @@ function Get-GitModule {
$tmpRoot = $env:AGENT_TEMPDIRECTORY
} else {
$tmpRoot = [System.IO.Path]::GetTempPath()
}
}

if ($Name) {
Write-Verbose -Message "$(Get-Date -f T) searching module URIs from their names"
$ProjectUri = foreach ($N1 in $Name) {
$Module = Get-InstalledModule $N1 -ea 0
if (!$Module) {$Module = Get-Module $N1 -ListAvailable -ea 0}

if (!$Module) {
Write-Error "$FunctionName found no module $N1"
continue
}

if (!($Module | ? ProjectUri)) {
Write-Warning "$FunctionName found module $N1, but it has no ProjectUri information"
continue
}

# return information to $ProjectUri variable
$Module | Sort-Object Version | Select-Object -Last 1 -ExpandProperty ProjectUri

}
}

}

Expand Down Expand Up @@ -62,8 +87,13 @@ function Get-GitModule {
}
}

if($psd1 -is [array]) {
$psd0 = $psd1 | ? BaseName -eq $ModuleName
if (($psd1 -is [array]) -and (@($psd0).Count -ne 1)) {
$errorText = "$FunctionName found multiple module manifests for $ModuleName"
} elseif (($psd1 -is [array]) -and (@($psd0).Count -eq 1)) {
$ModuleVersion = (Get-Content -Raw $psd0.FullName | Invoke-Expression).ModuleVersion
$errorText = $null
$psd1 = $psd0
} elseif (!($psd1.FullName -is [string])) {
$errorText = "$FunctionName found no module manifest for $ModuleName"
} else {
Expand Down
6 changes: 5 additions & 1 deletion Tests/functions/Get-GitModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Describe "$CommandName basic testing" -Tag 'Functionality' {
(Get-GitModule $moduleURL).Name | Should -Be $moduleName
}


$moduleName = 'FIFA2018'
Install-Module -Name $moduleName -Repository PSGallery -Scope CurrentUser -Force
It "$CommandName finds module $moduleName by name" {
(Get-GitModule -Name $moduleName).Name | Should -Be $moduleName
}

}
4 changes: 2 additions & 2 deletions Tests/module/InstallModuleFromGit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ Describe 'Proper Documentation' -Tag 'Documentation' {

# update documentation
Push-Location -Path $root
Update-MarkdownHelp -Path .\Docs
Update-MarkdownHelp -Path .\Docs -AlphabeticParamsOrder
New-ExternalHelp -Path .\Docs -OutputPath .\en-US -Force

# test it
$diff = git diff --ignore-space-change .\Docs .\en-US
$diff = git diff --ignore-space-change .\Docs .\en-US
Pop-Location
$diff | Should -Be $null
}
Expand Down