GitHub Webhook
목표
github에 푸시가 되면 webhook을 사용해서 특정 서버에 통보한다.
Settings > webHooks >> Add Webhook


let me select individual events
를 선택하면 옵션이 나오는데 선택하면된다.
나는 기본적으로 just the push event
만 선택햇다.
create a webhook

content type은 그림과 다르게 application/json
으로 선택했다.
이제 푸시가 들어오면 웹훅이 호출된다.

payload
페이로드는 25MB로 제한됩니다. 이벤트가 더 큰 페이로드를 생성하는 경우, GitHub는 해당 웹훅 이벤트에 대한 페이로드를 제공하지 않습니다.
header
X-GitHub-Hook-ID: The unique identifier of the webhook.
X-GitHub-Event: The name of the event that triggered the delivery.
X-GitHub-Delivery: A globally unique identifier (GUID) to identify the delivery.
X-Hub-Signature: This header is sent if the webhook is configured with a secret. This is the HMAC hex digest of the request body, and is generated using the SHA-1 hash function and the secret as the HMAC key. X-Hub-Signature is provided for compatibility with existing integrations. We recommend that you use the more secure X-Hub-Signature-256 instead.
X-Hub-Signature-256: This header is sent if the webhook is configured with a secret. This is the HMAC hex digest of the request body, and is generated using the SHA-256 hash function and the secret as the HMAC key. For more information, see "Validating webhook deliveries."
User-Agent: This header will always have the prefix GitHub-Hookshot/.
X-GitHub-Hook-Installation-Target-Type: The type of resource where the webhook was created.
X-GitHub-Hook-Installation-Target-ID: The unique identifier of the resource where the webhook was created.
webapi서버 만들기
간단히 webapi서버를 만들고 디비를 만들어서 리퀘스트를 받아보면 될거같다.
test
git push
를 해보자.

실서버에서 리퀘스트가 들어온것을 알수있다.
payload를 확인하여 디비에 저장하면 끝

여기서 실행된 결과를 볼수 있고 실제 payload를 확인할수 있다.

실패하면 알림마크가 보인다.
추가
참고로 webhook를 바로 쓰지 않고 action을 써서 webhook을 발생시킬수 있다.
https://github.com/marketplace/actions/workflow-webhook-action
이걸 yaml에 사용하면 된다.
Last updated
Was this helpful?