繁体   English   中英

如何从shell漂亮地打印Github Webhook有效负载?

[英]How to pretty print a Github Webhook payload from shell?

我有一个CGI Webhook端点,它只是将$ POST邮寄给我。

我现在希望漂亮地打印JSON,以便可以轻松阅读电子邮件:

payload=%7B%22ref%22%3A%22refs%2Fheads%2Fmaster%22%2C%22after%22%3A%2255deef96327f0625b5f1f724636a84ded63540c3%22%2C%22before%22%3A%22c87b66be0d2bcc93be6de0f0c4ac248642d5abf5%22%2C%22created%22%3Afalse%2C%22deleted%22%3Afalse%2C%22forced%22%3Afalse%2C%22compare%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%2Fcompare%2Fc87b66be0d2b...55deef96327f%22%2C%22commits%22%3A%5B%7B%22id%22%3A%2255deef96327f0625b5f1f724636a84ded63540c3%22%2C%22distinct%22%3Atrue%2C%22message%22%3A%22Harmonising+directory+structure+for+punch%22%2C%22timestamp%22%3A%222013-11-25T23%3A27%3A01-08%3A00%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%2Fcommit%2F55deef96327f0625b5f1f724636a84ded63540c3%22%2C%22author%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22committer%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22added%22%3A%5B%22contents%2Fcalendar%2F_index%2Fmain.markdown%22%2C%22contents%2Fconnect%2F_index%2Fmain.markdown%22%2C%22contents%2Fmembership%2F_index%2FMembershipAgreement.pdf%22%2C%22contents%2Fmembership%2F_index%2Fmain.markdown%22%5D%2C%22removed%22%3A%5B%22contents%2F_calendar%2Fmain.markdown%22%2C%22contents%2F_connect%2Fmain.markdown%22%2C%22contents%2F_membership%2FMembershipAgreement.pdf%22%2C%22contents%2F_membership%2Fmain.markdown%22%5D%2C%22modified%22%3A%5B%5D%7D%5D%2C%22head_commit%22%3A%7B%22id%22%3A%2255deef96327f0625b5f1f724636a84ded63540c3%22%2C%22distinct%22%3Atrue%2C%22message%22%3A%22Harmonising+directory+structure+for+punch%22%2C%22timestamp%22%3A%222013-11-25T23%3A27%3A01-08%3A00%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%2Fcommit%2F55deef96327f0625b5f1f724636a84ded63540c3%22%2C%22author%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22committer%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22added%22%3A%5B%22contents%2Fcalendar%2F_index%2Fmain.markdown%22%2C%22contents%2Fconnect%2F_index%2Fmain.markdown%22%2C%22contents%2Fmembership%2F_index%2FMembershipAgreement.pdf%22%2C%22contents%2Fmembership%2F_index%2Fmain.markdown%22%5D%2C%22removed%22%3A%5B%22contents%2F_calendar%2Fmain.markdown%22%2C%22contents%2F_connect%2Fmain.markdown%22%2C%22contents%2F_membership%2FMembershipAgreement.pdf%22%2C%22contents%2F_membership%2Fmain.markdown%22%5D%2C%22modified%22%3A%5B%5D%7D%2C%22repository%22%3A%7B%22id%22%3A14509629%2C%22name%22%3A%22hackerspace.sg%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%22%2C%22description%22%3A%22Hackerspace.sg+2.0+using+Punch%22%2C%22homepage%22%3A%22http%3A%2F%2Fhsg.dabase.com%2F%22%2C%22watchers%22%3A1%2C%22stargazers%22%3A1%2C%22forks%22%3A0%2C%22fork%22%3Afalse%2C%22size%22%3A264%2C%22owner%22%3A%7B%22name%22%3A%22hackerspacesg%22%2C%22email%22%3Anull%7D%2C%22private%22%3Afalse%2C%22open_issues%22%3A0%2C%22has_issues%22%3Atrue%2C%22has_downloads%22%3Atrue%2C%22has_wiki%22%3Afalse%2C%22language%22%3A%22CSS%22%2C%22created_at%22%3A1384821217%2C%22pushed_at%22%3A1385450838%2C%22master_branch%22%3A%22master%22%2C%22organization%22%3A%22hackerspacesg%22%7D%2C%22pusher%22%3A%7B%22name%22%3A%22kaihendry%22%2C%22email%22%3A%22hendry%40iki.fi%22%7D%7D

通过命令行管道。

是否有出色的node.js工具可胜任? 我猜我需要urldecode并通过JSON漂亮打印机运行“有效载荷”。 如果答案是一行,则获得加分。 ;)

这个怎么样?

var payload = "your_big_string";
console.log(JSON.stringify(JSON.parse(decodeURIComponent(payload)), null, 4));

如果要使用process.stdin作为输入, accum模块可以帮助您将流变成缓冲区(使用npm i accum安装):

var accum = require('accum');
process.stdin.pipe(accum(function (data) {
  console.log(JSON.stringify(JSON.parse(decodeURIComponent(data.toString())), null, 4));
}));

看看项目https://github.com/nlf/node-github-hook

随着项目页面的读取,

This is a very simple, easy to use evented web hook for github.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM