episoda 0.2.17 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/daemon/daemon-process.js +2221 -390
- package/dist/daemon/daemon-process.js.map +1 -1
- package/dist/hooks/post-commit +137 -0
- package/dist/index.js +337 -715
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# EP837: Record commits made on main branch for machine-aware tracking
|
|
4
|
+
#
|
|
5
|
+
# This hook runs after every successful commit. When on main branch,
|
|
6
|
+
# it records the commit in the local_commit table so that main branch
|
|
7
|
+
# protection only triggers for commits made on THIS machine.
|
|
8
|
+
#
|
|
9
|
+
# Problem: git log origin/main..HEAD shows ALL unpushed commits including
|
|
10
|
+
# commits made on other machines. This causes false positives when
|
|
11
|
+
# origin/main is stale.
|
|
12
|
+
#
|
|
13
|
+
# Solution: Track which commits were made on which machine. Main branch
|
|
14
|
+
# check queries local_commit table filtered by machine_id.
|
|
15
|
+
|
|
16
|
+
# Get current branch
|
|
17
|
+
BRANCH=$(git branch --show-current)
|
|
18
|
+
|
|
19
|
+
# Only track commits on main or master branch
|
|
20
|
+
if [ "$BRANCH" != "main" ] && [ "$BRANCH" != "master" ]; then
|
|
21
|
+
exit 0
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
# Get the commit that was just made
|
|
25
|
+
COMMIT_SHA=$(git rev-parse HEAD)
|
|
26
|
+
COMMIT_MESSAGE=$(git log -1 --pretty=format:%s)
|
|
27
|
+
COMMIT_AUTHOR=$(git log -1 --pretty=format:%an)
|
|
28
|
+
|
|
29
|
+
# Read config from ~/.episoda/config.json
|
|
30
|
+
CONFIG_FILE="$HOME/.episoda/config.json"
|
|
31
|
+
|
|
32
|
+
if [ ! -f "$CONFIG_FILE" ]; then
|
|
33
|
+
# No config file - CLI not authenticated, skip silently
|
|
34
|
+
exit 0
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
# Record the commit using the API
|
|
38
|
+
RESULT=$(node -e "
|
|
39
|
+
const fs = require('fs');
|
|
40
|
+
const https = require('https');
|
|
41
|
+
const http = require('http');
|
|
42
|
+
const { execSync } = require('child_process');
|
|
43
|
+
|
|
44
|
+
(async () => {
|
|
45
|
+
try {
|
|
46
|
+
// Read config
|
|
47
|
+
const config = JSON.parse(fs.readFileSync('$CONFIG_FILE', 'utf8'));
|
|
48
|
+
const token = config.access_token;
|
|
49
|
+
const apiUrl = config.api_url || 'https://episoda.dev';
|
|
50
|
+
const deviceId = config.device_id;
|
|
51
|
+
const projectId = config.project_id;
|
|
52
|
+
|
|
53
|
+
if (!token) {
|
|
54
|
+
console.log('SKIP:No token');
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!deviceId) {
|
|
59
|
+
console.log('SKIP:No device_id');
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!projectId) {
|
|
64
|
+
console.log('SKIP:No project_id');
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Record the commit
|
|
69
|
+
const url = new URL('/api/commits/local', apiUrl);
|
|
70
|
+
const client = url.protocol === 'https:' ? https : http;
|
|
71
|
+
|
|
72
|
+
const postData = JSON.stringify({
|
|
73
|
+
sha: '$COMMIT_SHA',
|
|
74
|
+
machine_id: deviceId,
|
|
75
|
+
project_id: projectId,
|
|
76
|
+
branch: '$BRANCH',
|
|
77
|
+
message: \`$COMMIT_MESSAGE\`,
|
|
78
|
+
author: \`$COMMIT_AUTHOR\`
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const req = client.request(url, {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers: {
|
|
84
|
+
'Authorization': 'Bearer ' + token,
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
'Content-Length': Buffer.byteLength(postData)
|
|
87
|
+
},
|
|
88
|
+
timeout: 5000
|
|
89
|
+
}, (res) => {
|
|
90
|
+
let data = '';
|
|
91
|
+
res.on('data', chunk => data += chunk);
|
|
92
|
+
res.on('end', () => {
|
|
93
|
+
try {
|
|
94
|
+
const json = JSON.parse(data);
|
|
95
|
+
if (json.success) {
|
|
96
|
+
console.log('SUCCESS:' + (json.created ? 'recorded' : 'exists'));
|
|
97
|
+
} else {
|
|
98
|
+
console.log('ERROR:' + (json.error?.message || 'Unknown error'));
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.log('ERROR:Parse error - ' + e.message);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
req.on('error', (e) => {
|
|
107
|
+
console.log('ERROR:Network - ' + e.message);
|
|
108
|
+
});
|
|
109
|
+
req.on('timeout', () => {
|
|
110
|
+
req.destroy();
|
|
111
|
+
console.log('ERROR:Timeout');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
req.write(postData);
|
|
115
|
+
req.end();
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.log('ERROR:' + e.message);
|
|
118
|
+
}
|
|
119
|
+
})();
|
|
120
|
+
" 2>/dev/null)
|
|
121
|
+
|
|
122
|
+
# Log result (non-blocking, don't fail the commit)
|
|
123
|
+
case "$RESULT" in
|
|
124
|
+
SUCCESS:*)
|
|
125
|
+
# Commit recorded successfully
|
|
126
|
+
;;
|
|
127
|
+
SKIP:*)
|
|
128
|
+
# Configuration incomplete - skip silently
|
|
129
|
+
;;
|
|
130
|
+
ERROR:*)
|
|
131
|
+
# Log error but don't fail the commit
|
|
132
|
+
echo "Warning: Failed to record commit for tracking: ${RESULT#ERROR:}" >&2
|
|
133
|
+
;;
|
|
134
|
+
esac
|
|
135
|
+
|
|
136
|
+
# Always exit successfully - don't block commits
|
|
137
|
+
exit 0
|