+86
-5
src/utils/sendDeploymentNotification.ts
+86
-5
src/utils/sendDeploymentNotification.ts
···
4
5
function getGitInfo() {
6
try {
7
-
const commitHash =
8
-
process.env.SOURCE_COMMIT || execSync('git rev-parse HEAD').toString().trim();
9
-
const commitMessage = execSync('git log -1 --pretty=%B').toString().trim();
10
const branch =
11
process.env.GIT_BRANCH ||
12
process.env.VERCEL_GIT_COMMIT_REF ||
13
process.env.COOLIFY_BRANCH ||
14
-
execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
15
16
return {
17
-
commitHash: commitHash.substring(0, 7),
18
commitMessage,
19
branch,
20
};
···
4
5
function getGitInfo() {
6
try {
7
+
try {
8
+
execSync('git rev-parse --is-inside-work-tree');
9
+
10
+
try {
11
+
execSync('git remote get-url origin');
12
+
} catch {
13
+
execSync('git remote add origin https://github.com/aethel/aethel-labs');
14
+
}
15
+
16
+
try {
17
+
execSync('git fetch --depth=100 origin');
18
+
} catch (e) {
19
+
logger.debug('git fetch failed or unnecessary; continuing', {
20
+
error: (e as Error).message,
21
+
});
22
+
}
23
+
} catch (e) {
24
+
logger.debug('Not a git repository; initializing temporary repo for metadata', {
25
+
error: (e as Error).message,
26
+
});
27
+
try {
28
+
execSync('git init');
29
+
try {
30
+
execSync('git remote add origin https://github.com/aethel/aethel-labs');
31
+
} catch (e) {
32
+
logger.debug('origin remote already exists or cannot be added', {
33
+
error: (e as Error).message,
34
+
});
35
+
}
36
+
const sourceCommit = process.env.SOURCE_COMMIT;
37
+
if (sourceCommit) {
38
+
try {
39
+
execSync(`git fetch --depth=1 origin ${sourceCommit}`);
40
+
} catch (err) {
41
+
logger.debug('Failed to fetch SOURCE_COMMIT from origin', {
42
+
error: (err as Error).message,
43
+
});
44
+
}
45
+
} else {
46
+
try {
47
+
const remoteHead = execSync('git ls-remote origin HEAD').toString().split('\t')[0];
48
+
if (remoteHead) {
49
+
execSync(`git fetch --depth=1 origin ${remoteHead}`);
50
+
process.env.SOURCE_COMMIT = remoteHead;
51
+
}
52
+
} catch (err) {
53
+
logger.debug('Failed to resolve remote HEAD', { error: (err as Error).message });
54
+
}
55
+
}
56
+
} catch (err) {
57
+
logger.debug('Failed to bootstrap temporary git repo', { error: (err as Error).message });
58
+
}
59
+
}
60
+
61
+
let commitHash: string | null = null;
62
+
try {
63
+
commitHash = process.env.SOURCE_COMMIT || execSync('git rev-parse HEAD').toString().trim();
64
+
} catch {
65
+
try {
66
+
const remoteHead = execSync('git ls-remote origin HEAD').toString().split('\t')[0];
67
+
commitHash = remoteHead || null;
68
+
} catch (e) {
69
+
logger.debug('Failed to resolve remote HEAD for commit hash', {
70
+
error: (e as Error).message,
71
+
});
72
+
}
73
+
}
74
+
75
+
const shortHash = commitHash ? commitHash.substring(0, 7) : 'unknown';
76
+
let commitMessage = 'No commit message';
77
+
try {
78
+
commitMessage = commitHash
79
+
? execSync(`git log -1 --pretty=%B ${commitHash}`).toString().trim()
80
+
: commitMessage;
81
+
} catch (e) {
82
+
logger.debug('Failed to resolve commit message', { error: (e as Error).message });
83
+
}
84
const branch =
85
process.env.GIT_BRANCH ||
86
process.env.VERCEL_GIT_COMMIT_REF ||
87
process.env.COOLIFY_BRANCH ||
88
+
(() => {
89
+
try {
90
+
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
91
+
} catch (e) {
92
+
logger.debug('Failed to resolve branch', { error: (e as Error).message });
93
+
return 'unknown';
94
+
}
95
+
})();
96
97
return {
98
+
commitHash: shortHash,
99
commitMessage,
100
branch,
101
};