Last active
August 29, 2015 14:04
-
-
Save atosimitu/003fe1c02ab23fc504f2 to your computer and use it in GitHub Desktop.
Backlog Wiki List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Get Backlog Wiki List | |
.EXAMPLE | |
Get-Wikis.ps1 -apiKey <API KEY> -spaceName <SPACE NAME> (Defaults Out-Gridview) | |
Get-Wikis.ps1 -apiKey <API KEY> -spaceName <SPACE NAME> -peco (use peco (https://github.com/peco/peco/releases)) | |
.DESCRIPTION | |
バックログスペース内のWikiを一覧表示(peco(-peco)もしくはGridView)、Wikiページを選択 | |
.NOTES | |
.LINK | |
#requires -version 3.0 | |
#> | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True,HelpMessage="http://www.backlog.jp/help/usersguide/personal-settings/userguide2378.html")] | |
[string]$apiKey = '', | |
[Parameter(Mandatory=$True,HelpMessage="http://developer.nulab-inc.com/ja/docs/backlog/auth")] | |
[string]$spaceName = '', | |
[switch]$peco, | |
[string]$backlogUrl = "https://$spaceName.backlog.jp/", | |
[Uri]$proxyUri = "$([System.Net.WebRequest]::DefaultWebProxy.GetProxy([uri]("$backlogUrl")))" | |
) | |
function Proxy-InvokeRestMethod | |
{ | |
Param( | |
[string]$uri = '' | |
) | |
if ("$proxyUri" -ne "$backlogUrl") | |
{ | |
Invoke-RestMethod -Uri $uri -UseDefaultCredentials -Proxy $proxyUri -ProxyUseDefaultCredentials | |
} | |
else | |
{ | |
Invoke-RestMethod -Uri $uri | |
} | |
} | |
#http://developer.nulab-inc.com/ja/docs/backlog/api/2/get-projects | |
function Get-Projects | |
{ | |
$projects = @() | |
Proxy-InvokeRestMethod -uri "https://$spaceName.backlog.jp/api/v2/projects`?apiKey=$apiKey" | | |
% { $projects += $_ } | |
$projects | |
} | |
#http://developer.nulab-inc.com/ja/docs/backlog/api/2/get-wikis | |
function Get-Wikis | |
{ | |
$wikis = @() | |
foreach ($project in $input) | |
{ | |
Write-Progress -id 1 -activity "Get Wikis" -Status "Projects..." -CurrentOperation ($project.projectKey) | |
Proxy-InvokeRestMethod -uri "https://$spaceName.backlog.jp/api/v2/wikis`?apiKey=$apiKey`&projectIdOrKey=$($project.projectKey)" | | |
% { | |
foreach ($w in $_) | |
{ | |
$uri = "https://$spaceName.backlog.jp/wiki/$($project.projectKey)/$([System.Web.HttpUtility]::UrlEncode("$($w.name)"))" | |
$wiki = New-Object psobject | | |
Add-Member -Name projectKey -type NoteProperty $project.projectKey -PassThru | | |
Add-Member -Name name -type NoteProperty $w.name -PassThru | | |
Add-Member -Name uri -type NoteProperty $uri -PassThru | |
$wikis += $wiki | |
} | |
} | |
} | |
$wikis | |
} | |
$OutputEncoding = [System.Text.Encoding]::UTF8 | |
if ( $peco ) | |
{ | |
Get-Projects | | |
Get-Wikis | | |
%{ Write-Output "$($_.projectKey)/$($_.name)`0$($_.uri)" } | | |
peco --null | | |
% { start $_ } | |
} | |
else | |
{ | |
Get-Projects | | |
Get-Wikis | | |
Out-GridView -PassThru | | |
% { start $_.uri } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment