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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
import { config } from "../lib/config";
import { autoRepair } from "../lib/autorepair";
import { analyzePush, computeHealthScore } from "../lib/intelligence";
interface PushRef {
oldSha: string;
newSha: string;
refName: string;
}
export async function onPostReceive(
owner: string,
repo: string,
refs: PushRef[]
): Promise<void> {
for (const ref of refs) {
if (ref.newSha.startsWith("0000")) continue;
const branchName = ref.refName.replace("refs/heads/", "");
try {
const repair = await autoRepair(owner, repo, branchName);
if (repair.repaired) {
console.log(
`[autorepair] ${owner}/${repo}@${branchName}: ${repair.repairs.length} repairs committed`
);
}
} catch (err) {
console.error(`[autorepair] error:`, err);
}
try {
const analysis = await analyzePush(owner, repo, ref.oldSha, ref.newSha);
console.log(
`[push-analysis] ${owner}/${repo}: ${analysis.summary}`
);
if (analysis.riskScore > 50) {
console.warn(
`[push-analysis] HIGH RISK push detected (score: ${analysis.riskScore})`
);
}
if (analysis.breakingChangeSignals.length > 0) {
console.warn(
`[push-analysis] Breaking changes: ${analysis.breakingChangeSignals.join("; ")}`
);
}
} catch (err) {
console.error(`[push-analysis] error:`, err);
}
computeHealthScore(owner, repo).then((report) => {
console.log(
`[health] ${owner}/${repo}: ${report.grade} (${report.score}/100)`
);
}).catch((err) => {
console.error(`[health] error:`, err);
});
}
triggerGateTest(owner, repo, refs).catch((err) =>
console.error(`[gatetest] error:`, err)
);
const mainPush = refs.find(
(r) => r.refName === "refs/heads/main" && !r.newSha.startsWith("0000")
);
if (mainPush) {
triggerCrontechDeploy(owner, repo, mainPush.newSha).catch((err) =>
console.error(`[crontech] error:`, err)
);
}
}
async function triggerGateTest(
owner: string,
repo: string,
refs: PushRef[]
): Promise<void> {
try {
const response = await fetch(config.gatetestUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
repository: `${owner}/${repo}`,
refs: refs.map((r) => ({
ref: r.refName,
before: r.oldSha,
after: r.newSha,
})),
source: "gluecron",
}),
});
console.log(
`[gatetest] scan triggered for ${owner}/${repo}: ${response.status}`
);
} catch (err) {
console.error(`[gatetest] failed to trigger scan:`, err);
}
}
async function triggerCrontechDeploy(
owner: string,
repo: string,
sha: string
): Promise<void> {
try {
const response = await fetch(config.crontechDeployUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
repository: `${owner}/${repo}`,
sha,
branch: "main",
source: "gluecron",
}),
});
console.log(
`[crontech] deploy triggered for ${owner}/${repo}@${sha.slice(0, 7)}: ${response.status}`
);
} catch (err) {
console.error(`[crontech] failed to trigger deploy:`, err);
}
}
|