码迷,mamicode.com
首页 > Windows程序 > 详细

PowerShell调用jira rest api实现对个人提交bug数的统计

时间:2016-05-06 21:56:06      阅读:856      评论:0      收藏:0      [点我收藏+]

标签:

通过PowerShell的invoke-webrequest和net.client联合实现个人指定项目jira提交数的统计,代码如下:

$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。

PowerShell调用jira rest api实现对个人提交bug数的统计

标签:

原文地址:http://www.cnblogs.com/LanTianYou/p/5467142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!