-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-webhook.js
More file actions
executable file
·90 lines (82 loc) · 2.31 KB
/
Copy pathtest-webhook.js
File metadata and controls
executable file
·90 lines (82 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
/**
* Test GitHub webhook locally
* Usage: node test-webhook.js <integration_id> [branch]
*/
const axios = require('axios');
const integrationId = process.argv[2];
const branch = process.argv[3] || 'main';
if (!integrationId) {
console.error('❌ Error: Integration ID is required');
console.log('Usage: node test-webhook.js <integration_id> [branch]');
console.log('Example: node test-webhook.js 507f1f77bcf86cd799439011 main');
process.exit(1);
}
const API_URL = `http://localhost:5000/api/github/webhook/${integrationId}`;
// Realistic GitHub push webhook payload
const payload = {
ref: `refs/heads/${branch}`,
before: 'abc123def456',
after: 'def456abc789',
commits: [
{
id: 'def456abc789',
message: 'Add new components and update existing ones',
timestamp: new Date().toISOString(),
added: [
'src/components/NewComponent.jsx',
'src/components/AnotherComponent.jsx'
],
modified: [
'src/components/ExistingComponent.jsx',
'package.json'
],
removed: []
}
],
head_commit: {
id: 'def456abc789',
message: 'Add new components and update existing ones',
timestamp: new Date().toISOString()
},
repository: {
id: 123456,
name: 'test-repo',
full_name: 'owner/test-repo',
html_url: 'https://github.com/owner/test-repo'
},
pusher: {
name: 'testuser',
email: 'testuser@example.com'
},
sender: {
login: 'testuser'
}
};
console.log(`🔔 Testing webhook for integration: ${integrationId}`);
console.log(`📌 Branch: ${branch}`);
console.log(`🌐 URL: ${API_URL}`);
console.log(`📦 Payload:`, JSON.stringify(payload, null, 2));
console.log('\n⏳ Sending request...\n');
axios.post(API_URL, payload, {
headers: {
'Content-Type': 'application/json',
'X-GitHub-Event': 'push',
'User-Agent': 'GitHub-Hookshot/test'
}
})
.then(response => {
console.log('✅ Success!');
console.log('Status:', response.status);
console.log('Response:', JSON.stringify(response.data, null, 2));
})
.catch(error => {
console.error('❌ Error!');
if (error.response) {
console.error('Status:', error.response.status);
console.error('Response:', JSON.stringify(error.response.data, null, 2));
} else {
console.error('Message:', error.message);
}
process.exit(1);
});