courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

Time:2021-9-10

This case is included ingithub.com/chengxy-nds/Springboot-…

Hello, I’m Xiaofu~

Recently received a task, withwebhookA 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?

webhook

webhookThat’s what we often sayhook, if you are not familiar with hooks, it doesn’t matter. Let’s change the concept to callbackURLI 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 aHTTPRequest towebhookThe URL of the configuration.

The following figure shows the workflow of the tool. The developerGitHubThe project submission code will trigger GitHubpull eventNext, send a message to the third-party URL configured in GitHub webhookPOSTRequest, this tripartite platform can be such platforms as nailing, flying book and enterprise wechat.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

Now let’s takeGitHub+Enterprise wechat to realize code submission monitoring and automatically push messages to enterprise wechat groups.

Configure GitHub webhook

First, enter the corresponding project of GitHubSettings, dowebhookBasic configuration of.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

The main configuration consists of four parts:

Payload URLThe address of the callback service;

Content typeCallback request header, suggestionJSONFormat;

SecretIn order to perform security verification, it will be set in the requestheaderThe 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 triggerwebhookCallback,push event(code push event)everything(all events) and some specific events.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

We canRecent DeliveriesseewebhookCallback records, as well as complete request and parameter data, can alsoredeliverySimulate sending requests.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

Configure enterprise wechat

The configuration of enterprise wechat is actually simpler. Let’s create a group and right-click on itAdd robotOption, which will be generated after successful additionwebhookAddress. We just send it to this addressPOSTRequest, the group will receive a push message.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

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.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

But did you find a problem here,GitHubandEnterprise 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?

Request forwarding

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 acceptGitHubThe 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

@Slf4j

Here’s a reminder. Some of the data called back by GitHub webhook can’t be used directly. Some scenarios still need to be calledGitHub APIIn exchange for some data.

Document address:https://docs.github.com/en/rest/reference

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

After the above configuration is completed, deploy the forwarded code to the server, test the whole link, see the effect, and deliberately modify itpom.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.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

Source address:github.com/chengxy-nds/Springboot-…

This project includes all the cases in my previous articles, such as:Tiktok to watermark tool sourceFace recognition project source code, andredisSeataMQAnd other middleware problem solving cases, interested students canStarOne, the actual development will be used.

courting envy! Webhook + enterprise wechat made a code submission monitoring tool for colleagues

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.

E-book address

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

Detailed steps for installing Perl and Komodo IDE for windows

Perl official website: https://www.perl.org/Perl document: https://perldoc.perl.org/Download address: https://www.perl.org/get.html The installation package of Perl Windows version is divided into activestate Perl and strawberry Perl. For the difference between the two, see: http://www.zzvips.com/article/202134.htm Note: the download speed of activestate Perl is slow. You may need KX to surf the Internet I have uploaded all the versions of […]