GitHub Connector

เชื่อมต่อ GitHub repositories กับ Brevo สำหรับการติดตามการมีส่วนร่วมของนักพัฒนา เวิร์กโฟลว์การแจ้งเตือน release และการตรวจสอบกิจกรรมชุมชนผ่าน Tajo

ภาพรวม

คุณสมบัติค่า
แพลตฟอร์มGitHub
หมวดหมู่แบบกำหนดเอง
ความซับซ้อนในการตั้งค่าปานกลาง
การผสานรวมอย่างเป็นทางการไม่
ข้อมูลที่ซิงค์เหตุการณ์ ผู้ใช้ Repositories
ประเภท APIREST API, GraphQL API
การยืนยันตัวตนGitHub App / Personal Access Token / OAuth 2.0
Base URLhttps://api.github.com
เวอร์ชัน API2022-11-28 (header-based versioning)

ฟีเจอร์

  • การติดตามปัญหาและ PR - ซิงค์เหตุการณ์ปัญหาและ pull request กับไทม์ไลน์ผู้ติดต่อ Brevo
  • การแจ้งเตือน Release - ทริกเกอร์แคมเปญ Brevo เมื่อมี repository release ใหม่
  • การซิงค์ผู้ร่วมพัฒนา - แมปผู้ร่วมพัฒนา GitHub กับผู้ติดต่อ Brevo สำหรับการมีส่วนร่วมของชุมชน
  • การติดตาม Star และ Fork - ตรวจสอบตัวชี้วัดความนิยมของ repository
  • การส่งต่อเหตุการณ์ Webhook - ส่งต่อเหตุการณ์ GitHub ไปยังระบบอัตโนมัติ Brevo
  • Repository catalog - ซิงค์ metadata ของ repository เป็นรายการ catalog ของ Brevo

ข้อกำหนดเบื้องต้น

ก่อนเริ่มต้น ตรวจสอบให้แน่ใจว่าคุณมี:

  1. บัญชี GitHub ที่มีสิทธิ์เข้าถึง repositories เป้าหมาย
  2. GitHub App หรือ Personal Access Token (แนะนำแบบ fine-grained)
  3. สิทธิ์ผู้ดูแลระบบสำหรับ repositories สำหรับการกำหนดค่า webhook
  4. บัญชี Brevo ที่มีสิทธิ์เข้าถึง API
  5. บัญชี Tajo ที่มีการสมัครสมาชิกที่ใช้งานอยู่

การยืนยันตัวตน

GitHub รองรับวิธีการยืนยันตัวตนหลายแบบ Tajo แนะนำให้ใช้ GitHub Apps สำหรับการเข้าถึงระดับองค์กร

ตัวเลือกที่ 1: GitHub App (แนะนำ)

  1. ไปที่ Settings > Developer settings > GitHub Apps
  2. คลิก New GitHub App
  3. กำหนดค่า app ด้วยสิทธิ์เหล่านี้:
Repository permissions:
Issues: Read
Pull requests: Read
Contents: Read
Metadata: Read
Organization permissions:
Members: Read
Subscribe to events:
Issues
Pull request
Push
Release
Star
Fork

ตัวเลือกที่ 2: Fine-Grained Personal Access Token

  1. ไปที่ Settings > Developer settings > Personal access tokens > Fine-grained tokens
  2. คลิก Generate new token
  3. เลือก repositories เป้าหมาย
  4. ให้สิทธิ์เหล่านี้:
Repository access: Selected repositories
Permissions:
Issues: Read-only
Pull requests: Read-only
Contents: Read-only
Metadata: Read-only

ความปลอดภัย Token

Fine-grained tokens มีวันหมดอายุ ตั้งค่าการหมุนเวียน token ก่อนหมดอายุ GitHub App installation tokens รีเฟรชโดยอัตโนมัติและเป็นที่นิยมสำหรับการใช้งานจริง

เชื่อมต่อกับ Tajo

Terminal window
# Using GitHub App
tajo connectors install github \
--app-id $GITHUB_APP_ID \
--private-key-path ./github-app-key.pem \
--installation-id $GITHUB_INSTALLATION_ID
# Using Personal Access Token
tajo connectors install github \
--token $GITHUB_TOKEN

การกำหนดค่า

การตั้งค่าพื้นฐาน

connectors:
github:
enabled: true
auth_type: "github_app" # or "token"
repositories:
- owner/repo-1
- owner/repo-2
sync:
issues: true
pull_requests: true
releases: true
contributors: true
stars: true
lists:
contributors: 20
stargazers: 21

การแมปฟิลด์

แมปข้อมูลผู้ใช้ GitHub กับแอตทริบิวต์ผู้ติดต่อ Brevo:

field_mapping:
# Standard fields
login: GITHUB_USERNAME
email: email
name: FIRSTNAME
# Developer metrics
contributions: GITHUB_CONTRIBUTIONS
repositories_count: GITHUB_REPOS
followers: GITHUB_FOLLOWERS
created_at: GITHUB_JOINED
# Custom attributes
company: COMPANY
location: LOCATION
bio: GITHUB_BIO

API Endpoints

Tajo ผสานรวมกับ GitHub REST API endpoints ต่อไปนี้:

Endpointเมธอดจุดประสงค์
/repos/{owner}/{repo}/issuesGETแสดงรายการปัญหาของ repository
/repos/{owner}/{repo}/pullsGETแสดงรายการ pull requests
/repos/{owner}/{repo}/releasesGETแสดงรายการ releases
/repos/{owner}/{repo}/contributorsGETแสดงรายการผู้ร่วมพัฒนา
/repos/{owner}/{repo}/stargazersGETแสดงรายการผู้ติดดาว
/repos/{owner}/{repo}/forksGETแสดงรายการ forks
/repos/{owner}/{repo}/eventsGETแสดงรายการเหตุการณ์ repository
/users/{username}GETดูโปรไฟล์ผู้ใช้
/orgs/{org}/membersGETแสดงรายการสมาชิกองค์กร
/repos/{owner}/{repo}/hooksPOSTสร้าง webhook

ตัวอย่างโค้ด

เริ่มต้น Connector

import { TajoClient } from '@tajo/sdk';
const tajo = new TajoClient({
apiKey: process.env.TAJO_API_KEY,
brevoApiKey: process.env.BREVO_API_KEY
});
await tajo.connectors.connect('github', {
appId: process.env.GITHUB_APP_ID,
privateKey: process.env.GITHUB_PRIVATE_KEY,
installationId: process.env.GITHUB_INSTALLATION_ID
});

ซิงค์ผู้ร่วมพัฒนากับ Brevo

await tajo.connectors.sync('github', {
type: 'full',
resources: ['contributors'],
repositories: ['owner/repo-1', 'owner/repo-2']
});
const status = await tajo.connectors.status('github');
console.log(status);
// {
// connected: true,
// lastSync: '2024-03-15T11:00:00Z',
// contributorsCount: 245,
// issuesTracked: 1890,
// releasesTracked: 34
// }

จัดการเหตุการณ์ Webhook

app.post('/webhooks/github', async (req, res) => {
const signature = req.get('X-Hub-Signature-256');
const event = req.get('X-GitHub-Event');
// Verify webhook signature
if (!verifyGitHubSignature(req.body, signature)) {
return res.status(401).send('Unauthorized');
}
await tajo.connectors.handleWebhook('github', {
event,
payload: req.body
});
res.status(200).send('OK');
});

ทริกเกอร์แคมเปญ Release

// Listen for new releases and trigger Brevo campaign
tajo.connectors.on('github', 'release.published', async (event) => {
await tajo.campaigns.trigger('release-announcement', {
listId: 21,
params: {
version: event.release.tag_name,
release_notes: event.release.body,
download_url: event.release.html_url
}
});
});

ขีดจำกัดอัตรา

GitHub ใช้ขีดจำกัดอัตราตามวิธีการยืนยันตัวตน:

การยืนยันตัวตนขีดจำกัดอัตราหลักSearch API
ไม่ยืนยันตัวตน60 คำขอ/ชั่วโมง10 คำขอ/นาที
Personal Access Token5,000 คำขอ/ชั่วโมง30 คำขอ/นาที
GitHub App (installation)5,000 คำขอ/ชั่วโมง30 คำขอ/นาที
GitHub App (user-to-server)5,000 คำขอ/ชั่วโมง30 คำขอ/นาที

Conditional Requests

Tajo ใช้ conditional requests (headers If-None-Match / If-Modified-Since) เพื่อลดการใช้ API การตอบสนองที่มี 304 Not Modified ไม่นับต่อขีดจำกัดอัตรา

ขีดจำกัดเพิ่มเติม:

  • ขีดจำกัดอัตราทุติยภูมิ: ไม่เกิน 100 คำขอพร้อมกัน ไม่เกิน 900 points ต่อนาทีสำหรับ REST API endpoints
  • GraphQL: 5,000 points ต่อชั่วโมง (ต้นทุน query แตกต่างกันตามความซับซ้อน)

การแก้ไขปัญหา

ปัญหาทั่วไป

ปัญหาสาเหตุวิธีแก้
401 UnauthorizedToken หมดอายุหรือข้อมูลรับรองไม่ถูกต้องสร้าง token ใหม่หรือติดตั้ง GitHub App ใหม่
403 Forbiddenสิทธิ์ไม่เพียงพอตรวจสอบ scope ของ token หรือสิทธิ์ App
404 Not Foundrepo ส่วนตัวไม่มีสิทธิ์เข้าถึงให้สิทธิ์เข้าถึง repository กับ token หรือ App
เกินขีดจำกัดอัตราการเรียก API มากเกินไปเปิดใช้ conditional requests และลดความถี่การซิงค์
ไม่ได้รับ WebhooksURL ไม่ถูกต้องหรือไฟร์วอลล์ตรวจสอบว่า URL webhook เข้าถึงได้สาธารณะ

โหมด Debug

connectors:
github:
debug: true
log_level: verbose
log_webhooks: true

ทดสอบการเชื่อมต่อ

Terminal window
tajo connectors test github
# ✓ API authentication successful
# ✓ Repository access verified
# ✓ Issue data readable
# ✓ Webhook delivery active
# ✓ Rate limit healthy (4,850/5,000 remaining)

แนวทางปฏิบัติที่ดีที่สุด

  1. ใช้ GitHub Apps แทน PATs - GitHub Apps ให้สิทธิ์แบบละเอียดและ tokens ที่รีเฟรชอัตโนมัติ
  2. เปิดใช้ webhook secrets - ตรวจสอบลายเซ็น webhook เสมอด้วย HMAC-SHA256
  3. ใช้ conditional requests - ใช้ ETags เพื่อหลีกเลี่ยงการสิ้นเปลือง quota ขีดจำกัดอัตรา
  4. Paginate การตอบสนองขนาดใหญ่ - GitHub ส่งคืนสูงสุด 100 รายการต่อหน้า วนซ้ำด้วย Link headers
  5. ซิงค์ระหว่างกิจกรรมน้อย - กำหนดการซิงค์แบบเต็มนอกชั่วโมงการพัฒนาสูงสุด
  6. ตรวจสอบ headers ขีดจำกัดอัตรา - ตรวจสอบ X-RateLimit-Remaining เพื่อลดความเร็วเชิงรุก

ความปลอดภัย

  • การยืนยันตัวตน GitHub App - JWT ตาม RSA key พร้อม installation tokens อายุสั้น
  • ลายเซ็น Webhook - การตรวจสอบลายเซ็น HMAC-SHA256 บน webhook payloads ทั้งหมด
  • Fine-Grained Tokens - กำหนดขอบเขตกับ repositories และสิทธิ์เฉพาะ
  • HTTPS เท่านั้น - การสื่อสาร API ทั้งหมดเข้ารหัสผ่าน TLS 1.2+
  • การจัดเก็บที่เข้ารหัส - Private keys และ tokens เข้ารหัสที่เก็บใน Tajo
  • การหมดอายุ Token - Fine-grained tokens หมดอายุโดยอัตโนมัติ ตั้งค่าการแจ้งเตือนการหมุนเวียน

แหล่งข้อมูลที่เกี่ยวข้อง

Subscribe to updates

developer-docs

Drop your email or phone number — we'll send you what matters next.

auto-detect
ผู้ช่วย AI

สวัสดี! ถามฉันเกี่ยวกับเอกสารได้เลย