GitHub Webhook

๋ชฉํ‘œ

github์— ํ‘ธ์‹œ๊ฐ€ ๋˜๋ฉด webhook์„ ์‚ฌ์šฉํ•ด์„œ ํŠน์ • ์„œ๋ฒ„์— ํ†ต๋ณดํ•œ๋‹ค.

Settings > webHooks >> Add Webhook

alt text
alt text

let me select individual events๋ฅผ ์„ ํƒํ•˜๋ฉด ์˜ต์…˜์ด ๋‚˜์˜ค๋Š”๋ฐ ์„ ํƒํ•˜๋ฉด๋œ๋‹ค.

๋‚˜๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ just the push event๋งŒ ์„ ํƒํ–‡๋‹ค.

create a webhook

alt text

content type์€ ๊ทธ๋ฆผ๊ณผ ๋‹ค๋ฅด๊ฒŒ application/json์œผ๋กœ ์„ ํƒํ–ˆ๋‹ค.

์ด์ œ ํ‘ธ์‹œ๊ฐ€ ๋“ค์–ด์˜ค๋ฉด ์›นํ›…์ด ํ˜ธ์ถœ๋œ๋‹ค.

alt text

payload

ํŽ˜์ด๋กœ๋“œ๋Š” 25MB๋กœ ์ œํ•œ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ๊ฐ€ ๋” ํฐ ํŽ˜์ด๋กœ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒฝ์šฐ, GitHub๋Š” ํ•ด๋‹น ์›นํ›… ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ํŽ˜์ด๋กœ๋“œ๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

  • 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๋ฅผ ํ•ด๋ณด์ž.

alt text

์‹ค์„œ๋ฒ„์—์„œ ๋ฆฌํ€˜์ŠคํŠธ๊ฐ€ ๋“ค์–ด์˜จ๊ฒƒ์„ ์•Œ์ˆ˜์žˆ๋‹ค.

payload๋ฅผ ํ™•์ธํ•˜์—ฌ ๋””๋น„์— ์ €์žฅํ•˜๋ฉด ๋

alt text

์—ฌ๊ธฐ์„œ ์‹คํ–‰๋œ ๊ฒฐ๊ณผ๋ฅผ ๋ณผ์ˆ˜ ์žˆ๊ณ  ์‹ค์ œ payload๋ฅผ ํ™•์ธํ• ์ˆ˜ ์žˆ๋‹ค.

alt text

์‹คํŒจํ•˜๋ฉด ์•Œ๋ฆผ๋งˆํฌ๊ฐ€ ๋ณด์ธ๋‹ค.

์ถ”๊ฐ€

์ฐธ๊ณ ๋กœ webhook๋ฅผ ๋ฐ”๋กœ ์“ฐ์ง€ ์•Š๊ณ  action์„ ์จ์„œ webhook์„ ๋ฐœ์ƒ์‹œํ‚ฌ์ˆ˜ ์žˆ๋‹ค.

https://github.com/marketplace/actions/workflow-webhook-action

์ด๊ฑธ yaml์— ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

Last updated

Was this helpful?