Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions docs/examples/connectors/github/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"id": "34567890123",
"type": "IssuesEvent",
"actor": {
"id": 12345678,
"login": "octocat",
"display_login": "octocat",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"avatar_url": "https://avatars.githubusercontent.com/u/12345678?"
},
"repo": {
"id": 98765432,
"name": "octocat/Hello-World",
"url": "https://api.github.com/repos/octocat/Hello-World"
},
"payload": {
"action": "opened",
"issue": {
"id": 1234567890,
"node_id": "I_kwDOBcXXXX5XXXXXX",
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
"repository_url": "https://api.github.com/repos/octocat/Hello-World",
"labels_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/labels{/name}",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/comments",
"events_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/events",
"html_url": "https://github.com/octocat/Hello-World/issues/1347",
"number": 1347,
"state": "open",
"title": "Found a bug",
"body": "I'm having a problem with this.",
"user": {
"login": "octocat",
"id": 12345678,
"node_id": "MDQ6VXNlcjEyMzQ1Njc4",
"avatar_url": "https://avatars.githubusercontent.com/u/12345678?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"type": "User"
},
"labels": [
{
"id": 208045946,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
"name": "bug",
"description": "Something isn't working",
"color": "d73a4a",
"default": true
}
],
"assignee": null,
"assignees": [],
"milestone": null,
"locked": false,
"active_lock_reason": null,
"comments": 0,
"created_at": "2023-11-23T12:00:00Z",
"updated_at": "2023-11-23T12:00:00Z",
"closed_at": null,
"author_association": "OWNER"
}
},
"public": true,
"created_at": "2023-11-23T12:00:00Z"
}
48 changes: 48 additions & 0 deletions docs/examples/connectors/github/github.vjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# connector: github — Comprehensive GitHub API integration
#
# Platform connector for GitHub. Supports multiple operations:
# - Issues (create, update, list, comment)
# - Pull Requests (create, update, list, review, merge)
# - Repositories (create, update, list, webhooks)
# - Events (webhook processing via polling)
# - Commits (list, get, create)
# - Releases (create, update, list)
#
# Uses oauth-poll driver for event streaming. Individual operations use http-out
# in flows that consume from vx.github.events or make direct API calls.
#
# Subjects:
# OUT: vx.github.events (all GitHub repository events)
#
# Secrets:
# github/token - GitHub personal access token or OAuth token
#
# Rate limits: 5000 req/hour for authenticated requests
# Pagination: Link header-based with page/per_page parameters
#
# Authentication: Bearer token in Authorization header
# API Version: 2022-11-28 (specified in X-GitHub-Api-Version header)

driver "oauth-poll"

# Event polling configuration
SUBJECT = "vx.github.events"
BASE_URL = "https://api.github.com"
POLL_ENDPOINT = "/repos/{owner}/{repo}/events"
POLL_INTERVAL = 300
CURSOR_PATH = "[0].id"
CURSOR_PARAM = "since"

# Authentication
HEADERS = {
Authorization: "Bearer " + secret("github/token"),
"X-GitHub-Api-Version": "2022-11-28",
Accept: "application/vnd.github+json"
}

# Pagination
LIMIT_PARAM = "per_page"
LIMIT_VALUE = 100

# Response handling - GitHub events are returned as array
DATA_PATH = "."
160 changes: 160 additions & 0 deletions docs/examples/connectors/github/mock.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env node
// Mock GitHub API server for admission testing
// Simulates /repos/{owner}/{repo}/events endpoint

import http from 'http';

const events = [
{
id: '34567890123',
type: 'IssuesEvent',
actor: {
id: 12345678,
login: 'octocat',
display_login: 'octocat',
url: 'https://api.github.com/users/octocat'
},
repo: {
id: 98765432,
name: 'octocat/Hello-World',
url: 'https://api.github.com/repos/octocat/Hello-World'
},
payload: {
action: 'opened',
issue: {
id: 1234567890,
number: 1347,
state: 'open',
title: 'Found a bug',
body: "I'm having a problem with this.",
user: {
login: 'octocat',
id: 12345678
},
labels: [
{
name: 'bug',
color: 'd73a4a'
}
],
created_at: '2023-11-23T12:00:00Z'
}
},
public: true,
created_at: '2023-11-23T12:00:00Z'
},
{
id: '34567890124',
type: 'PullRequestEvent',
actor: {
id: 12345679,
login: 'contributor',
display_login: 'contributor',
url: 'https://api.github.com/users/contributor'
},
repo: {
id: 98765432,
name: 'octocat/Hello-World',
url: 'https://api.github.com/repos/octocat/Hello-World'
},
payload: {
action: 'opened',
number: 42,
pull_request: {
id: 987654321,
number: 42,
state: 'open',
title: 'Fix bug in authentication',
user: {
login: 'contributor',
id: 12345679
},
created_at: '2023-11-23T12:05:00Z'
}
},
public: true,
created_at: '2023-11-23T12:05:00Z'
}
];

const server = http.createServer((req, res) => {
// CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, X-GitHub-Api-Version, Accept, Content-Type');

if (req.method === 'OPTIONS') {
res.writeHead(200);
res.end();
return;
}

const url = new URL(req.url, `http://${req.headers.host}`);

// GET /repos/{owner}/{repo}/events - list repository events
if (req.method === 'GET' && url.pathname.match(/^\/repos\/[^\/]+\/[^\/]+\/events$/)) {
const perPage = parseInt(url.searchParams.get('per_page') || '30');
const page = parseInt(url.searchParams.get('page') || '1');
const since = url.searchParams.get('since');

let filteredEvents = events;
if (since) {
const sinceIndex = events.findIndex(e => e.id === since);
filteredEvents = sinceIndex >= 0 ? events.slice(0, sinceIndex) : events;
}

const startIndex = (page - 1) * perPage;
const data = filteredEvents.slice(startIndex, startIndex + perPage);

// GitHub uses Link header for pagination
const linkHeader = [];
if (page > 1) {
linkHeader.push(`<${url.pathname}?page=${page - 1}&per_page=${perPage}>; rel="prev"`);
}
if (startIndex + perPage < filteredEvents.length) {
linkHeader.push(`<${url.pathname}?page=${page + 1}&per_page=${perPage}>; rel="next"`);
}

res.writeHead(200, {
'Content-Type': 'application/json',
'Link': linkHeader.join(', ')
});
res.end(JSON.stringify(data));
return;
}

// POST /repos/{owner}/{repo}/issues - create issue
if (req.method === 'POST' && url.pathname.match(/^\/repos\/[^\/]+\/[^\/]+\/issues$/)) {
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
const data = JSON.parse(body);
res.writeHead(201, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
id: Date.now(),
number: Math.floor(Math.random() * 10000),
state: 'open',
title: data.title,
body: data.body,
user: {
login: 'octocat',
id: 12345678
},
created_at: new Date().toISOString()
}));
});
return;
}

// 404 for unknown endpoints
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
message: 'Not Found',
documentation_url: 'https://docs.github.com/rest'
}));
});

const PORT = process.env.PORT || 8081;
server.listen(PORT, () => {
console.log(`Mock GitHub API listening on port ${PORT}`);
});
5 changes: 5 additions & 0 deletions docs/examples/connectors/github/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"BASE_URL": "http://localhost:8081",
"POLL_ENDPOINT": "/repos/octocat/Hello-World/events",
"POLL_INTERVAL": 5
}
Loading