gitgit 설명서
gitgit.kr 로 가기

Webhook 받기

Webhook은 저장소에 일이 생길 때 gitgit이 내 서버로 보내는 알림입니다. 주기적으로 조회하지 않아도 Push, Issue, Pull Request의 변화를 바로 받을 수 있습니다.

Webhook 만들기

  1. 저장소의 설정 → Webhook을 엽니다. 저장소의 관리자 이상만 할 수 있고, 저장소마다 20개까지 만들 수 있습니다.
  2. 받을 URL을 적습니다. https:// 주소여야 하고, 주소에 사용자 정보(user:pass@)나 # 뒤 부분을 넣을 수 없습니다. 내부망 주소, 루프백, gitgit 자신의 주소로는 보낼 수 없습니다.
  3. 이벤트를 하나 이상 고릅니다.
  4. 서명 시크릿을 정합니다. 직접 정하면 16자 이상 256자 이하로 적고, 비우면 gitgit이 만들어 한 번만 보여 줍니다. 수신 서버가 요청이 진짜인지 확인할 때 쓰므로 비밀로 보관하세요.

이벤트

이벤트언제action
push브랜치나 태그가 바뀜pushed
issuesIssue가 열리거나 바뀜opened, edited, closed, reopened
pull_requestPull Request가 열리거나 바뀜opened, edited, closed, reopened, merged
pull_request_review리뷰가 제출됨submitted
releaseRelease가 게시, 수정, 삭제됨 (초안 작업은 보내지 않음)published, edited, deleted

요청의 모양

gitgit은 JSON 본문을 POST로 보냅니다. 10초 안에 2xx로 답해야 성공으로 봅니다.

헤더내용
User-AgentGitGit-Webhook/1.0
X-GitGit-Event이벤트 종류
X-GitGit-Event-Id이벤트의 고유 ID. 다시 보내도 같습니다.
X-GitGit-Delivery-Attempt몇 번째 시도인지(1부터)
X-GitGit-Timestamp보낸 시각(Unix 초)
X-GitGit-Signature-256sha256= 뒤에 서명

본문에는 공통 필드와 이벤트별 내용이 함께 옵니다. 아래는 push의 예입니다.

{
    "eventId": "0b8f6a0e-3f0c-4c2e-9d53-0d6a5f1f6c11",
    "event": "push",
    "occurredAt": "2026-11-22T08:25:15.480Z",
    "repository": { "id": "3e824349-…", "owner": "acme", "name": "app", "visibility": "private" },
    "sender": { "id": "…", "username": "alice", "name": "Alice", "accountType": "user" },
    "action": "pushed",
    "ref": "refs/heads/main",
    "before": "9f2c…",
    "after": "41ab…",
    "created": false,
    "deleted": false,
    "forced": false,
    "pusher": { "id": "…", "username": "alice", "name": "Alice", "accountType": "user" }
}

서명 확인하기

받을 URL은 누구나 부를 수 있으므로, 요청이 gitgit에서 온 것인지 반드시 확인하세요. 서명은 <X-GitGit-Timestamp 값>.<요청 본문 원문>을 서명 시크릿으로 HMAC-SHA256 계산한 값입니다.

Node.js

import { createHmac, timingSafeEqual } from "node:crypto";
import { createServer } from "node:http";

const secret = process.env.GITGIT_WEBHOOK_SECRET;

function verify(headers, rawBody) {
    const timestamp = headers["x-gitgit-timestamp"];
    const given = Buffer.from(headers["x-gitgit-signature-256"] ?? "");
    const expected = Buffer.from(
        "sha256=" + createHmac("sha256", secret).update(timestamp + ".").update(rawBody).digest("hex"),
    );
    const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) < 300;
    return fresh && given.length === expected.length && timingSafeEqual(given, expected);
}

createServer(async (request, response) => {
    const chunks = [];
    for await (const chunk of request) chunks.push(chunk);
    const rawBody = Buffer.concat(chunks);
    if (!verify(request.headers, rawBody)) {
        response.writeHead(401).end();
        return;
    }
    // 먼저 받았다고 답하고, 오래 걸리는 일은 그 뒤에 처리합니다.
    response.writeHead(204).end();
    const event = JSON.parse(rawBody.toString("utf8"));
    console.log(request.headers["x-gitgit-event"], event.action, event.repository.name);
}).listen(8000);

Python

import hashlib
import hmac
import os
import time

SECRET = os.environ["GITGIT_WEBHOOK_SECRET"].encode()


def verify(headers, raw_body: bytes) -> bool:
    timestamp = headers.get("X-GitGit-Timestamp", "")
    given = headers.get("X-GitGit-Signature-256", "")
    digest = hmac.new(SECRET, timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    fresh = timestamp.isdigit() and abs(time.time() - int(timestamp)) < 300
    return fresh and hmac.compare_digest(given, "sha256=" + digest)

재시도와 중복

API로 관리하기

개인 액세스 토큰으로도 Webhook을 관리할 수 있습니다. 저장소의 관리자 이상이어야 하고, Bot 토큰으로는 할 수 없습니다.

curl -X POST https://api.gitgit.kr/api/v1/repositories/acme/app/webhooks \
    -H "Authorization: Bearer $GITGIT_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"url": "https://ci.example.com/hooks/gitgit", "events": ["push", "pull_request"], "active": true}'

시크릿을 보내지 않으면 응답에 gitgit이 만든 시크릿이 한 번만 들어 있습니다.