PowerShell调用jira rest api实现对个人提交bug数的统计
通过PowerShell的invoke-webrequest和net.client联合实现个人指定项目jira提交数的统计,其中涉及到了JSON对象的提交,代码如下:
$content = @{username='用户名';password='密码'} $JSON = $content|convertto-JSON -Compress $jiraUri = "http://jira.ms.netease.com" $apiUri = $jiraUri+"/rest/auth/1/session" $res = Invoke-WebRequest -Uri $apiUri -Method Post -Body $JSON -ContentType application/json $webClient = new-object net.webclient #Set encoding style here. $webClient.Encoding = [System.Text.Encoding]::GetEncoding("utf-8") $webClient.Headers.add("Cookie", $res.Headers["Set-Cookie"]) $keyWord = Read-Host "请输入搜索关键词(多个关键词请用空格隔开)" $jql = "reporter in (用户名) AND text ~ '"+$keyWord+"'" $JSON = @" { "jql": "$jql", "startAt": 0, "maxResults": 1000, "fields": [ "summary", "status", "assignee" ] } "@ $apiUri = "/rest/api/2/search" $uri = $jiraUri+$apiUri #Post json must added header. $webClient.Headers.Add("Content-Type", "application/json"); $searchResult = $webClient.UploadString($uri,$JSON) #Get issues. $issues = ($searchResult|ConvertFrom-Json).issues foreach($issue in $issues){ $issue.fields.summary } Write-Host "与关键词相关的jira共有"$issues.Count"个" -ForegroundColor Green Read-Host
保存脚本到桌面右键PowerShell运行或者直接在ise中按F5反复运行都可以,效果如下:
原理:根据jql来实现通过标题关键字对jira的查找,也用到了jira rest api。
本文来自博客园,作者:天外归云,转载请注明原文链接:https://www.cnblogs.com/LanTianYou/p/5467142.html