无法从服务Hook的事件中获取几乎所有信息

时间:2017-07-21 17:12:24

标签: visual-studio service tfs hook trello

我正在尝试使用Team Foundation Server的Trello服务挂钩。我有followed this tutorial并且连接没有问题,但我无法从Event JSON获取所需的信息: The Description I Tried

这是Event JSON:

{
    "id": "03c164c2-8912-4d5e-8009-3707d5f83734",
    "eventType": "git.push",
    "publisherId": "tfs",
    "scope": 0,
    "message": {
        "text": "Jamal Hartnett pushed updates to Fabrikam-Fiber-Git:master.",
        "html": "Jamal Hartnett pushed updates to Fabrikam-Fiber-Git:master.",
        "markdown": "Jamal Hartnett pushed updates to `Fabrikam-Fiber-Git`:`master`."
    },
    "detailedMessage": {
        "text": "Jamal Hartnett pushed a commit to Fabrikam-Fiber-Git:master.\n - Fixed bug in web.config file 33b55f7c",
        "html": "Jamal Hartnett pushed a commit to <a href=\"https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/\">Fabrikam-Fiber-Git</a>:<a href=\"https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/#version=GBmaster\">master</a>.\n<ul>\n<li>Fixed bug in web.config file <a href=\"https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74\">33b55f7c</a>\n</ul>",
        "markdown": "Jamal Hartnett pushed a commit to [Fabrikam-Fiber-Git](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/):[master](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/#version=GBmaster).\n* Fixed bug in web.config file [33b55f7c](https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74)"
    },
    "resource": {
        "commits": [
            {
                "commitId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74",
                "author": {
                    "name": "Jamal Hartnett",
                    "email": "fabrikamfiber4@hotmail.com",
                    "date": "2015-02-25T19:01:00Z"
                },
                "committer": {
                    "name": "Jamal Hartnett",
                    "email": "fabrikamfiber4@hotmail.com",
                    "date": "2015-02-25T19:01:00Z"
                },
                "comment": "Fixed bug in web.config file",
                "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git/commit/33b55f7cb7e7e245323987634f960cf4a6e6bc74"
            }
        ],
        "refUpdates": [
            {
                "name": "refs/heads/master",
                "oldObjectId": "aad331d8d3b131fa9ae03cf5e53965b51942618a",
                "newObjectId": "33b55f7cb7e7e245323987634f960cf4a6e6bc74"
            }
        ],
        "repository": {
            "id": "278d5cd2-584d-4b63-824a-2ba458937249",
            "name": "Fabrikam-Fiber-Git",
            "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249",
            "project": {
                "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
                "name": "Fabrikam-Fiber-Git",
                "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
                "state": "wellFormed",
                "visibility": "unchanged"
            },
            "defaultBranch": "refs/heads/master",
            "remoteUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git"
        },
        "pushedBy": {
            "id": "00067FFED5C7AF52@Live.com",
            "displayName": "Jamal Hartnett",
            "uniqueName": "Windows Live ID\\fabrikamfiber4@hotmail.com"
        },
        "pushId": 14,
        "date": "2014-05-02T19:17:13.3309587Z",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/pushes/14"
    },
    "resourceVersion": "1.0",
    "resourceContainers": {
        "collection": {
            "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2"
        },
        "account": {
            "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e"
        },
        "project": {
            "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f"
        }
    },
    "createdDate": "2017-07-21T16:48:44.312Z"
}

这是发送给Trello的请求:

Method: POST
URI: https://api.trello.com/1/cards?key=7d6630fd03ac2b6fc9fde2f2ef0c4096&token=********
HTTP Version: 1.1
Headers:
{
  Content-Type: application/json; charset=utf-8
}
Content:
{
  "name": "Test Nº  ",
  "desc": "Description: ",
  "pos": "top",
  "due": null,
  "labels": "green",
  "idList": "5935a0d45ff8e5a6c8f828b9"
}

我可以从事件JSON获取/读取的唯一字段是&#34;消息&#34;。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

更新

Eddie 是对的,在这种情况下你应该使用push作为资源。文档不太清楚。最后,它是如此简单。但是,相应的checkin不适用于 事件中的代码。

对于每个用于帮助避免这种混淆的事件,文档肯定会更清楚。

  

占位符的基本形式是{{resource.field}}   资源是引发事件的资源的名称(workitem,build等),字段是资源部分中的字段   事件,就像id一样。因此,如果订阅是针对已完成的构建,   它可能是这样的:

Build {{build.id}} completed at {{build.finishTime}}

似乎问题是你在这种情况下使用了错误的占位符。根据您的发送请求,resource.pushID&amp; resource.commits.[0].comment不会被引发的事件中的值替换。

答案 1 :(得分:0)

如果您想获取推送ID和评论,说明如下:

{{push.pushId}}

{{push.commits[0].comment}}