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

  • 相关阅读:
    AjaxPro.2.dll基本使用
    能够按页号提取word文档文本内容的小程序,由C#实现
    Reflect反编译C#程序
    模态对话框
    【转】Google Chrome如何保存密码口令
    Android 应用的签名的基本原则
    几款keylogger
    对一个利用短链接进行钓鱼行为的小小分析
    2011年10月百度笔试 RD3—第4题
    TCP中有哪些机制保证了可靠传输
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/5467142.html
Copyright © 2020-2023  润新知