This case is included ingithub.com/chengxy-nds/Springboot-…
Hello, I’m Xiaofu~
Recently received a task, with
webhookA code submission monitoring function is made, that is, after someone submits code to the remote warehouse, a message will be sent in the enterprise wechat group, similar to
@XXX submits XXXX code to XXX project at XXX timeSuch a copy.
As for why I want to make such a tool, I can’t crush people at the senior level. In fact, I refuse in my heart. I always feel strange like being monitored. Is it difficult to find that I usually secretly mention the code and repair the bug quietly?
webhookThat’s what we often say
hook, if you are not familiar with hooks, it doesn’t matter. Let’s change the concept to callback
URLI should have heard of it. For example, three-party platforms such as wechat payment support configuring callback URLs to notify payment status.
When some events are triggered, such as:
pushCode to “remote warehouse”, or “pick one up”
issue“Wait, the source website can initiate a
webhookThe URL of the configuration.
The following figure shows the workflow of the tool. The developer
GitHubThe project submission code will trigger GitHub
pull eventNext, send a message to the third-party URL configured in GitHub webhook
POSTRequest, this tripartite platform can be such platforms as nailing, flying book and enterprise wechat.
Now let’s take
GitHub+Enterprise wechat to realize code submission monitoring and automatically push messages to enterprise wechat groups.
First, enter the corresponding project of GitHub
webhookBasic configuration of.
The main configuration consists of four parts:
Payload URLThe address of the callback service;
Content typeCallback request header, suggestion
SecretIn order to perform security verification, it will be set in the request
headerThe following two attributes are added to distinguish the source of the request to avoid malicious access to the exposed request;
X-Hub-Signature: sha1=2478e400758f6114aa18abc4380ef8fad0b16fb9 X-Hub-Signature-256: sha256=68bde5bee18bc36fd95c9b71b4a89f238cb01ab3bf92fd67de3a1de12b4f5c72
Finally, we choose which events to trigger
push event(code push event)
everything(all events) and some specific events.
webhookCallback records, as well as complete request and parameter data, can also
redeliverySimulate sending requests.
The configuration of enterprise wechat is actually simpler. Let’s create a group and right-click on it
Add robotOption, which will be generated after successful addition
webhookAddress. We just send it to this address
POSTRequest, the group will receive a push message.
The message content supports four message types: text, markdown, image and news. It also supports @ group members in the group. The following is a text format demonstration.
curl ' https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=145a516a -dd15-421f-97a3-ba3bf1479369' \
Directly request the URL and find that the message is pushed successfully, indicating that the configuration is OK.
But did you find a problem here,
Enterprise wechatOne just starts the request and the other just accepts the request in a fixed data format. The data of the two interfaces are not compatible at all?
Since they are incompatible, we have no choice but to make a layer of adaptation in the middle. Who can’t provoke both sides!
The forwarding logic is also relatively simple, just accept
GitHubThe callback request data can be slightly modified and assembled into the data format required by the enterprise wechat, and can be sent directly.
GitHubThe pushed data includes warehouse, author, submitter, submission content and other information, which is basically enough.
The code implementation is relatively rough. I’ll take a look
Here’s a reminder. Some of the data called back by GitHub webhook can’t be used directly. Some scenarios still need to be called
GitHub APIIn exchange for some data.
After the above configuration is completed, deploy the forwarded code to the server, test the whole link, see the effect, and deliberately modify it
pom.xmlAfter submitting the file, we found that after submitting the code, we successfully sent a message to the enterprise wechat, which is consistent with our expected effect.
This project includes all the cases in my previous articles, such as:
Tiktok to watermark tool source、
Face recognition project source code, and
MQAnd other middleware problem solving cases, interested students can
StarOne, the actual development will be used.
Hundreds of various technical e-books have been sorted out, which can be taken by students in need. The technology group is almost full. Students who want to enter can add my friends and blow the technology with the big guys.
This work adoptsCC agreement, reprint must indicate the author and the link to this article