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

简介: 通过PowerShell的invoke-webrequest和net.client联合实现个人指定项目jira提交数的统计,其中涉及到了JSON对象的提交,代码如下: $content = @{username='用户名';password='密码'} $JSON = $content|convertto-JSON -Compress $jiraUri = "http://jira.

通过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。

相关文章
|
6天前
|
安全 Java API
第7章 Spring Security 的 REST API 与微服务安全(2024 最新版)(上)
第7章 Spring Security 的 REST API 与微服务安全(2024 最新版)
26 0
第7章 Spring Security 的 REST API 与微服务安全(2024 最新版)(上)
|
28天前
|
前端开发 JavaScript API
基于React的简易REST API客户端设计与实现
基于React的简易REST API客户端设计与实现
21 3
|
3月前
|
JSON 缓存 API
title: 深入理解REST API设计的最佳实践
title: 深入理解REST API设计的最佳实践
36 0
|
4月前
|
分布式计算 Hadoop Java
[hadoop3.x系列]HDFS REST HTTP API的使用(二)HttpFS
[hadoop3.x系列]HDFS REST HTTP API的使用(二)HttpFS
54 1
|
4月前
|
分布式计算 Hadoop API
✨[hadoop3.x系列]HDFS REST HTTP API的使用(一)WebHDFS
✨[hadoop3.x系列]HDFS REST HTTP API的使用(一)WebHDFS
63 1
|
3月前
|
存储 Ubuntu Linux
windows可以安装Ubuntu,ubuntu上也可以安装Powershell
powerhsell除了可以在windows上使用外,还可以在Ubuntu上部署开发环境。下面介绍Ubuntu上安装powershell的方法。
51 0
|
5月前
|
Shell Linux 开发工具
windows中cmd和PowerShell批处理命令
之前在 Git 批量删除本地分支,有用到 Linux 或 MacOS 下的批处理命令,这个命令中的 grep、xargs 本身是 Shell script,在 windows 中的 cmd 和 PowerShell 中是不能用的
51 0
|
8月前
|
JavaScript Windows
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题
|
8月前
|
Windows
使用PowerShell获取Windows当前锁屏壁纸
使用PowerShell获取Windows当前锁屏壁纸 如果原始图片丢了,用这段代码就可以提取当前锁屏壁纸了!
102 0
|
应用服务中间件 nginx Windows
Windows PowerShell 中启动 Nginx 报错解决方案
Windows PowerShell 中启动 Nginx 报错解决方案
Windows PowerShell 中启动 Nginx 报错解决方案