@sentry/junior-github 0.176.2 → 0.178.0
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/index.js +174 -7
- package/dist/workspace-prepare.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5227,6 +5227,10 @@ async function prepareWorkspace(ctx) {
|
|
|
5227
5227
|
}
|
|
5228
5228
|
paths.add(key);
|
|
5229
5229
|
}
|
|
5230
|
+
const gitEnv = {
|
|
5231
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
5232
|
+
GIT_CONFIG_NOSYSTEM: "1"
|
|
5233
|
+
};
|
|
5230
5234
|
for (const { owner, name, path, repo } of repos) {
|
|
5231
5235
|
const parent = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : void 0;
|
|
5232
5236
|
if (parent) {
|
|
@@ -5241,18 +5245,181 @@ async function prepareWorkspace(ctx) {
|
|
|
5241
5245
|
);
|
|
5242
5246
|
}
|
|
5243
5247
|
}
|
|
5244
|
-
const
|
|
5248
|
+
const cloneUrl = `https://github.com/${owner}/${name}.git`;
|
|
5249
|
+
const worktree = await ctx.sandbox.run({
|
|
5250
|
+
cmd: "git",
|
|
5251
|
+
args: ["-C", path, "rev-parse", "--is-inside-work-tree"],
|
|
5252
|
+
cwd: ctx.sandbox.root,
|
|
5253
|
+
env: gitEnv
|
|
5254
|
+
});
|
|
5255
|
+
const branch = worktree.exitCode === 0 ? await ctx.sandbox.run({
|
|
5256
|
+
cmd: "git",
|
|
5257
|
+
args: ["-C", path, "symbolic-ref", "--quiet", "--short", "HEAD"],
|
|
5258
|
+
cwd: ctx.sandbox.root,
|
|
5259
|
+
env: gitEnv
|
|
5260
|
+
}) : void 0;
|
|
5261
|
+
const branchName = branch?.stdout.trim();
|
|
5262
|
+
const detachedHead = worktree.exitCode === 0 && !branchName ? await ctx.sandbox.run({
|
|
5263
|
+
cmd: "git",
|
|
5264
|
+
args: ["-C", path, "rev-parse", "--verify", "HEAD^{commit}"],
|
|
5265
|
+
cwd: ctx.sandbox.root,
|
|
5266
|
+
env: gitEnv
|
|
5267
|
+
}) : void 0;
|
|
5268
|
+
const detachedSha = detachedHead?.stdout.trim();
|
|
5269
|
+
const validDetachedSha = detachedHead?.exitCode === 0 && detachedSha && /^[0-9a-f]{40,64}$/.test(detachedSha) ? detachedSha : void 0;
|
|
5270
|
+
const upstream = branch?.exitCode === 0 && branchName ? await ctx.sandbox.run({
|
|
5245
5271
|
cmd: "git",
|
|
5246
5272
|
args: [
|
|
5247
|
-
"
|
|
5248
|
-
|
|
5249
|
-
"
|
|
5250
|
-
"--",
|
|
5251
|
-
|
|
5252
|
-
path
|
|
5273
|
+
"-C",
|
|
5274
|
+
path,
|
|
5275
|
+
"rev-parse",
|
|
5276
|
+
"--symbolic-full-name",
|
|
5277
|
+
"@{upstream}"
|
|
5253
5278
|
],
|
|
5279
|
+
cwd: ctx.sandbox.root,
|
|
5280
|
+
env: gitEnv
|
|
5281
|
+
}) : void 0;
|
|
5282
|
+
const upstreamRef = upstream?.stdout.trim();
|
|
5283
|
+
const upstreamPrefix = "refs/remotes/origin/";
|
|
5284
|
+
const upstreamBranch = upstreamRef?.startsWith(upstreamPrefix) ? upstreamRef.slice(upstreamPrefix.length) : void 0;
|
|
5285
|
+
if (worktree.exitCode === 0 && (branchName || validDetachedSha)) {
|
|
5286
|
+
const localBranch = branchName || "workspace-detached";
|
|
5287
|
+
const remoteBranch = upstreamBranch || branchName;
|
|
5288
|
+
const remoteRef = remoteBranch ? `${upstreamPrefix}${remoteBranch}` : validDetachedSha;
|
|
5289
|
+
const tempDir = await ctx.sandbox.run({
|
|
5290
|
+
cmd: "mktemp",
|
|
5291
|
+
args: ["-d", `${ctx.sandbox.juniorRoot}/workspace-refresh.XXXXXX`],
|
|
5292
|
+
cwd: ctx.sandbox.root
|
|
5293
|
+
});
|
|
5294
|
+
const refreshGitDir = tempDir.stdout.trim();
|
|
5295
|
+
if (tempDir.exitCode !== 0 || !refreshGitDir) {
|
|
5296
|
+
throw new Error(
|
|
5297
|
+
`GitHub workspace refresh temp directory failed for ${repo}: ${tempDir.stderr.trim() || `exit ${tempDir.exitCode}`}`
|
|
5298
|
+
);
|
|
5299
|
+
}
|
|
5300
|
+
for (const args of [
|
|
5301
|
+
[
|
|
5302
|
+
"--git-dir",
|
|
5303
|
+
refreshGitDir,
|
|
5304
|
+
"--work-tree",
|
|
5305
|
+
path,
|
|
5306
|
+
"init",
|
|
5307
|
+
"--quiet",
|
|
5308
|
+
"--initial-branch",
|
|
5309
|
+
localBranch
|
|
5310
|
+
],
|
|
5311
|
+
[
|
|
5312
|
+
"--git-dir",
|
|
5313
|
+
refreshGitDir,
|
|
5314
|
+
"--work-tree",
|
|
5315
|
+
path,
|
|
5316
|
+
"remote",
|
|
5317
|
+
"add",
|
|
5318
|
+
"origin",
|
|
5319
|
+
cloneUrl
|
|
5320
|
+
],
|
|
5321
|
+
[
|
|
5322
|
+
"--git-dir",
|
|
5323
|
+
refreshGitDir,
|
|
5324
|
+
"--work-tree",
|
|
5325
|
+
path,
|
|
5326
|
+
"fetch",
|
|
5327
|
+
"--quiet",
|
|
5328
|
+
"--prune",
|
|
5329
|
+
"--tags",
|
|
5330
|
+
"origin",
|
|
5331
|
+
"+refs/heads/*:refs/remotes/origin/*",
|
|
5332
|
+
...validDetachedSha ? [validDetachedSha] : []
|
|
5333
|
+
],
|
|
5334
|
+
...validDetachedSha ? [
|
|
5335
|
+
[
|
|
5336
|
+
"--git-dir",
|
|
5337
|
+
refreshGitDir,
|
|
5338
|
+
"--work-tree",
|
|
5339
|
+
path,
|
|
5340
|
+
"update-ref",
|
|
5341
|
+
"--no-deref",
|
|
5342
|
+
"HEAD",
|
|
5343
|
+
validDetachedSha
|
|
5344
|
+
]
|
|
5345
|
+
] : [],
|
|
5346
|
+
[
|
|
5347
|
+
"--git-dir",
|
|
5348
|
+
refreshGitDir,
|
|
5349
|
+
"--work-tree",
|
|
5350
|
+
path,
|
|
5351
|
+
"reset",
|
|
5352
|
+
"--hard",
|
|
5353
|
+
remoteRef
|
|
5354
|
+
],
|
|
5355
|
+
...remoteBranch && branchName ? [
|
|
5356
|
+
[
|
|
5357
|
+
"--git-dir",
|
|
5358
|
+
refreshGitDir,
|
|
5359
|
+
"--work-tree",
|
|
5360
|
+
path,
|
|
5361
|
+
"branch",
|
|
5362
|
+
`--set-upstream-to=origin/${remoteBranch}`,
|
|
5363
|
+
branchName
|
|
5364
|
+
]
|
|
5365
|
+
] : []
|
|
5366
|
+
]) {
|
|
5367
|
+
const result2 = await ctx.sandbox.run({
|
|
5368
|
+
cmd: "git",
|
|
5369
|
+
args,
|
|
5370
|
+
cwd: ctx.sandbox.root,
|
|
5371
|
+
env: gitEnv
|
|
5372
|
+
});
|
|
5373
|
+
if (result2.exitCode !== 0) {
|
|
5374
|
+
throw new Error(
|
|
5375
|
+
`GitHub workspace refresh failed for ${repo}: ${result2.stderr.trim() || `exit ${result2.exitCode}`}`
|
|
5376
|
+
);
|
|
5377
|
+
}
|
|
5378
|
+
}
|
|
5379
|
+
for (const [cmd, args] of [
|
|
5380
|
+
["rm", ["-rf", "--", `${path}/.git`]],
|
|
5381
|
+
["mv", ["--", refreshGitDir, `${path}/.git`]]
|
|
5382
|
+
]) {
|
|
5383
|
+
const result2 = await ctx.sandbox.run({
|
|
5384
|
+
cmd,
|
|
5385
|
+
args: [...args],
|
|
5386
|
+
cwd: ctx.sandbox.root
|
|
5387
|
+
});
|
|
5388
|
+
if (result2.exitCode !== 0) {
|
|
5389
|
+
throw new Error(
|
|
5390
|
+
`GitHub workspace metadata replacement failed for ${repo}: ${result2.stderr.trim() || `exit ${result2.exitCode}`}`
|
|
5391
|
+
);
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
const clean = await ctx.sandbox.run({
|
|
5395
|
+
cmd: "git",
|
|
5396
|
+
args: ["-C", path, "clean", "-fd"],
|
|
5397
|
+
cwd: ctx.sandbox.root,
|
|
5398
|
+
env: gitEnv
|
|
5399
|
+
});
|
|
5400
|
+
if (clean.exitCode !== 0) {
|
|
5401
|
+
throw new Error(
|
|
5402
|
+
`GitHub workspace refresh failed for ${repo}: ${clean.stderr.trim() || `exit ${clean.exitCode}`}`
|
|
5403
|
+
);
|
|
5404
|
+
}
|
|
5405
|
+
continue;
|
|
5406
|
+
}
|
|
5407
|
+
const cleanup = await ctx.sandbox.run({
|
|
5408
|
+
cmd: "rm",
|
|
5409
|
+
args: ["-rf", "--", path],
|
|
5254
5410
|
cwd: ctx.sandbox.root
|
|
5255
5411
|
});
|
|
5412
|
+
if (cleanup.exitCode !== 0) {
|
|
5413
|
+
throw new Error(
|
|
5414
|
+
`GitHub workspace checkout cleanup failed for ${repo}: ${cleanup.stderr.trim() || `exit ${cleanup.exitCode}`}`
|
|
5415
|
+
);
|
|
5416
|
+
}
|
|
5417
|
+
const result = await ctx.sandbox.run({
|
|
5418
|
+
cmd: "git",
|
|
5419
|
+
args: ["clone", "--quiet", "--", cloneUrl, path],
|
|
5420
|
+
cwd: ctx.sandbox.root,
|
|
5421
|
+
env: gitEnv
|
|
5422
|
+
});
|
|
5256
5423
|
if (result.exitCode !== 0) {
|
|
5257
5424
|
throw new Error(
|
|
5258
5425
|
`GitHub workspace clone failed for ${repo}: ${result.stderr.trim() || `exit ${result.exitCode}`}`
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { WorkspacePrepareHookContext } from "@sentry/junior-plugin-api";
|
|
2
|
-
/** Clone GitHub repositories
|
|
2
|
+
/** Clone missing GitHub repositories or refresh existing Workspace checkouts. */
|
|
3
3
|
export declare function prepareWorkspace(ctx: WorkspacePrepareHookContext): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior-github",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.178.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@sinclair/typebox": "^0.34.49",
|
|
32
32
|
"drizzle-orm": "^0.45.2",
|
|
33
33
|
"zod": "^4.4.3",
|
|
34
|
-
"@sentry/junior-plugin-api": "0.
|
|
34
|
+
"@sentry/junior-plugin-api": "0.178.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^25.9.1",
|