如何通过Curl在单个Pull Request评论中提交多个JSON对象?
问题描述
我想把以下失败测试用例的输出内容发布为GitHub Pull Request的评论,但执行相关命令后遇到了问题。
失败测试用例数据
{ "@name": "testWalletDeepLinkLoginFlow", "@classname": "iphone13pro-15.7-en-portrait#.AppUI-Tests.WalletDeepLinkLoginFlowTest", "@time": "30.246", "failure": "Failure at /Users/vagrant/git/AppUITests/Extensions/XCUIElement+Additions.swift:30 - Assertion Failure at XCUIElement+Additions.swift:30: Failed to get matching snapshot: No matches found for first query match sequence: `Descendants matching type TextField` -> `Elements matching predicate '\"input_country_search\" IN identifiers'`, given input App element pid: 627 (no attribute values faulted in)", "webLink": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/9067272573409626190/details" } { "@name": "testWalletDeepLinkMainFlow", "@classname": "iphone13pro-15.7-en-portrait#.AppUI-Tests.WalletDeepLinkMainFlowTest", "@time": "50.672", "failure": "Failure at /Users/vagrant/git/AppUITests/DeepLinks/Wallet/WalletDeepLinkMainFlowTest.swift:17 - Assertion Failure at WalletDeepLinkMainFlowTest.swift:17: XCTAssertTrue failed", "webLink": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/7233833673388432629/details" }
使用的脚本与提交命令
我通过以下Shell函数生成PR评论的请求体:
generate_pull_request_payload() { cat <<EOF { "body": "$FAILED_TESTS" } EOF }
先用xq工具筛选出仅失败的测试用例,再执行以下curl命令提交到GitHub API:
curl -X POST "https://api.github.com/repos/owner/repo/issues/3943/comments" \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Content-type: text/json; charset=utf-8" \ --data "$(generate_pull_request_payload)"
内容的提问来源于stack exchange,提问作者ziad_tawfeek
相关产品推荐
相关产品推荐

