2

【代码】SpringBoot项目实现GitHub的WebHook

 1 year ago
source link: https://feiju12138.github.io/2022/10/25/SpringBoot%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0GitHub%E7%9A%84WebHook/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【代码】SpringBoot项目实现GitHub的WebHook

2022-10-25

1

SpringBoot项目实现GitHub的WebHook

  • 当Github仓库被提交时,会向指定URL发送一条POST请求,当接收到请求时,执行想要执行的脚本即可

创建一个接口用于接收请求

src/main/java/com/controller/HookController.java

package com.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class HookController {

@RequestMapping("/hook")
public void hook() throws IOException {
// 需要执行的操作
...
}
}
  • 通过maven打包后部署

在GitHub上添加WebHook配置

  • 在项目中打开Settings->Webhooks->Add webhook

01.png
  • 指定请求路径->Add webhook

02.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK