Skip to content

Commit

Permalink
Merge pull request #13 from PowerShell/dev
Browse files Browse the repository at this point in the history
Merge dev into master
  • Loading branch information
KarolKaczmarek authored Jul 26, 2016
2 parents 8fc3a5f + 913e897 commit 6a3b400
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 238 deletions.
Binary file removed GiPS.psd1
Binary file not shown.
511 changes: 329 additions & 182 deletions GitHubAnalytics.psm1

Large diffs are not rendered by default.

102 changes: 82 additions & 20 deletions GitHubLabels.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
{
Write-Host "$apiTokensFilePath does not exist, skipping import"
Write-Host @'
This module should define $global:gitHubApiToken with your GitHub API access token. Create this file it if it doesn't exist.
This module should define $global:gitHubApiToken with your GitHub API access token in ApiTokens.psm1. Create this file if it doesn't exist.
You can simply rename ApiTokensTemplate.psm1 to ApiTokens.psm1 and update value of $global:gitHubApiToken.
You can get GitHub token from https://github.com/settings/tokens
If you don't provide it, you can still use this module, but you will be limited to 60 queries per hour.
Expand All @@ -40,7 +40,7 @@ $script:gitHubApiReposUrl = "https://api.github.com/repos"
Get-GitHubLabel -repositoryName DesiredStateConfiguration -ownerName Powershell -labelName TestLabel
Get-GitHubLabel -repositoryName DesiredStateConfiguration -ownerName Powershell
#>
function Get-GitHubLabel
function Get-GitHubLabel
{
param(
[Parameter(Mandatory=$true)]
Expand All @@ -51,37 +51,64 @@ function Get-GitHubLabel
[string]$gitHubAccessToken = $script:gitHubToken
)

$resultToReturn = @()
$index = 0
$headers = @{"Authorization"="token $gitHubAccessToken"}

if ($labelName -eq "")
{
$url = "$script:gitHubApiReposUrl/{0}/{1}/labels" -f $ownerName, $repositoryName
$query = "$script:gitHubApiReposUrl/{0}/{1}/labels" -f $ownerName, $repositoryName
Write-Host "Getting all labels for repository $repositoryName"
$result = Invoke-WebRequest $url -Method Get -Headers $headers

if ($result.StatusCode -ne 200)

do
{
Write-Error "Couldn't obtain labels. Result: $result"
return
}
Write-Host "Got all labels"
try
{
$jsonResult = Invoke-WebRequest $query -Method Get -Headers $headers
$labels = ConvertFrom-Json -InputObject $jsonResult.content
}
catch [System.Net.WebException] {
Write-Error "Failed to execute query with exception: $($_.Exception)`nHTTP status code: $($_.Exception.Response.StatusCode)"
return $null
}
catch {
Write-Error "Failed to execute query with exception: $($_.Exception)"
return $null
}

foreach ($label in $labels)
{
Write-Verbose "$index. $($label.name)"
$index++
$resultToReturn += $label
}
$query = Get-NextResultPage -jsonResult $jsonResult
} while ($query -ne $null)
}
else
{
$url = "$script:gitHubApiReposUrl/{0}/{1}/labels/{2}" -f $ownerName, $repositoryName, $labelName
$query = "$script:gitHubApiReposUrl/{0}/{1}/labels/{2}" -f $ownerName, $repositoryName, $labelName
Write-Host "Getting label $labelName for repository $repositoryName"
$result = Invoke-WebRequest $url -Method Get -Headers $headers

if ($result.StatusCode -ne 200)

try
{
Write-Error "Couldn't obtain label $labelName. Result: $result"
return
}
Write-Host "Got label $labelName"
$jsonResult = Invoke-WebRequest $query -Method Get -Headers $headers
$label = ConvertFrom-Json -InputObject $jsonResult.content
}
catch [System.Net.WebException] {
Write-Error "Failed to execute query with exception: $($_.Exception)`nHTTP status code: $($_.Exception.Response.StatusCode)"
return $null
}
catch {
Write-Error "Failed to execute query with exception: $($_.Exception)"
return $null
}

Write-Verbose "$index. $($label.name)"
$resultToReturn = $label
}

$labels = ConvertFrom-Json -InputObject $result.content
return $labels
return $resultToReturn
}

<#
Expand Down Expand Up @@ -339,4 +366,39 @@ $labelJson = @"
Remove-GitHubLabel -repositoryName $repositoryName -ownerName $ownerName -labelName $label -gitHubAccessToken $gitHubAccessToken
}
}
}

<#
.SYNOPSIS Function to get next page with results from query to GitHub API
.PARAM
jsonResult Result from the query to GitHub API
#>
function Get-NextResultPage
{
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$jsonResult
)

if($jsonResult.Headers.Link -eq $null)
{
return $null
}

$nextLinkString = $jsonResult.Headers.Link.Split(',')[0]

# Get url query for the next page
$query = $nextLinkString.Split(';')[0].replace('<','').replace('>','')
if ($query -notmatch 'page=1')
{

return $query
}
else
{
return $null
}
}
31 changes: 10 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
The MIT License (MIT)

Copyright (c) 2016 PowerShell Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------ START OF LICENSE -----------------------------------------
PowerShellForGitHub

Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------- END OF LICENSE ------------------------------------------
120 changes: 120 additions & 0 deletions PowerShellForGitHub.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#
# Module manifest for module 'manifest'
#
# Generated by: KarolKaczmarek
#
# Generated on: 5/5/2016
#

@{

# Script module or binary module file associated with this manifest.
# RootModule = ''

# Version number of this module.
ModuleVersion = '0.1.0'

# ID used to uniquely identify this module
GUID = '9e8dfd44-f782-445a-883c-70614f71519c'

# Author of this module
Author = 'Microsoft Corporation'

# Company or vendor of this module
CompanyName = 'Microsoft Corporation'

# Copyright statement for this module
Copyright = '(c) 2016 Microsoft Corporation. All rights reserved.'

# Description of the functionality provided by this module
Description = 'PowerShell wrapper for GitHub API'

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @('GitHubAnalytics.psm1','GitHubLabels.psm1')

# Functions to export from this module
FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('GitHub','API','PowerShell')

# A URL to the license for this module.
LicenseUri = 'https://github.com/PowerShell/PowerShellForGitHub/blob/master/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/PowerShell/PowerShellForGitHub'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

Loading

0 comments on commit 6a3b400

Please sign in to comment.