@intentius/chant 0.124.55 → 0.124.56
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/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +1 -2
- package/dist/ci-audit/attribution.d.ts +111 -0
- package/dist/ci-audit/attribution.d.ts.map +1 -0
- package/dist/ci-audit/attribution.js +194 -0
- package/dist/ci-audit/audit-log.d.ts +144 -0
- package/dist/ci-audit/audit-log.d.ts.map +1 -0
- package/dist/ci-audit/audit-log.js +149 -0
- package/dist/ci-audit/index.d.ts +12 -0
- package/dist/ci-audit/index.d.ts.map +1 -0
- package/dist/ci-audit/index.js +12 -0
- package/dist/ci-audit/unrecorded.d.ts +74 -0
- package/dist/ci-audit/unrecorded.d.ts.map +1 -0
- package/dist/ci-audit/unrecorded.js +95 -0
- package/dist/ci-audit.d.ts +3 -0
- package/dist/ci-audit.d.ts.map +1 -0
- package/dist/ci-audit.js +2 -0
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +3 -4
- package/dist/ci-estate.d.ts +24 -0
- package/dist/ci-estate.d.ts.map +1 -1
- package/dist/ci-estate.js +1 -2
- package/dist/ci-identity.d.ts.map +1 -1
- package/dist/ci-identity.js +2 -3
- package/dist/ci-job-guard.d.ts +139 -0
- package/dist/ci-job-guard.d.ts.map +1 -0
- package/dist/ci-job-guard.js +287 -0
- package/dist/ci-jobs.d.ts +7 -0
- package/dist/ci-jobs.d.ts.map +1 -1
- package/dist/ci-jobs.js +7 -0
- package/dist/ci-product-words.d.ts +7 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +38 -4
- package/dist/ci-product.d.ts +35 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +38 -3
- package/dist/ci-respond-run.d.ts +73 -0
- package/dist/ci-respond-run.d.ts.map +1 -0
- package/dist/ci-respond-run.js +247 -0
- package/dist/ci-respond.d.ts +189 -0
- package/dist/ci-respond.d.ts.map +1 -0
- package/dist/ci-respond.js +285 -0
- package/dist/cli/handlers/audit-log.d.ts +12 -0
- package/dist/cli/handlers/audit-log.d.ts.map +1 -0
- package/dist/cli/handlers/audit-log.js +81 -0
- package/dist/cli/handlers/build.d.ts +7 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +81 -0
- package/dist/cli/handlers/ci-check-job.d.ts +11 -0
- package/dist/cli/handlers/ci-check-job.d.ts.map +1 -0
- package/dist/cli/handlers/ci-check-job.js +27 -0
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +38 -9
- package/dist/cli/handlers/e2e-safe-run.d.ts +12 -0
- package/dist/cli/handlers/e2e-safe-run.d.ts.map +1 -0
- package/dist/cli/handlers/e2e-safe-run.js +23 -0
- package/dist/cli/handlers/pr.d.ts +5 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +259 -4
- package/dist/cli/handlers/run-wave.js +89 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +56 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +107 -0
- package/dist/cli/registry.d.ts +38 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/adoption.d.ts.map +1 -1
- package/dist/components/adoption.js +1 -2
- package/dist/components/capability.d.ts +37 -0
- package/dist/components/capability.d.ts.map +1 -1
- package/dist/components/capability.js +25 -0
- package/dist/components/check-hooks.d.ts +4 -1
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-steps.d.ts +74 -0
- package/dist/components/check-steps.d.ts.map +1 -0
- package/dist/components/check-steps.js +102 -0
- package/dist/components/ci-services.d.ts.map +1 -1
- package/dist/components/ci-services.js +1 -2
- package/dist/components/driver.d.ts +12 -0
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/driver.js +35 -1
- package/dist/components/groups.d.ts.map +1 -1
- package/dist/components/groups.js +4 -3
- package/dist/components/pr-env-ledger.d.ts.map +1 -1
- package/dist/components/pr-env-ledger.js +1 -2
- package/dist/components/pr-environment.d.ts +1 -1
- package/dist/components/pr-environment.d.ts.map +1 -1
- package/dist/components/pr-environment.js +1 -1
- package/dist/components/pr-pipeline.d.ts +129 -3
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +153 -17
- package/dist/components/pr-run.d.ts +8 -0
- package/dist/components/pr-run.d.ts.map +1 -1
- package/dist/components/pr-run.js +9 -4
- package/dist/components/product-pipeline.d.ts +35 -2
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +24 -5
- package/dist/components/wave-plan.d.ts +8 -0
- package/dist/components/wave-plan.d.ts.map +1 -1
- package/dist/components/wave-plan.js +18 -2
- package/dist/e2e-harness/bucket.d.ts +21 -0
- package/dist/e2e-harness/bucket.d.ts.map +1 -0
- package/dist/e2e-harness/bucket.js +61 -0
- package/dist/e2e-harness/claim.d.ts +70 -0
- package/dist/e2e-harness/claim.d.ts.map +1 -0
- package/dist/e2e-harness/claim.js +98 -0
- package/dist/e2e-harness/driver.d.ts +64 -0
- package/dist/e2e-harness/driver.d.ts.map +1 -0
- package/dist/e2e-harness/driver.js +243 -0
- package/dist/e2e-harness/forgejo.d.ts +77 -0
- package/dist/e2e-harness/forgejo.d.ts.map +1 -0
- package/dist/e2e-harness/forgejo.js +205 -0
- package/dist/e2e-harness/git.d.ts +32 -0
- package/dist/e2e-harness/git.d.ts.map +1 -0
- package/dist/e2e-harness/git.js +67 -0
- package/dist/e2e-harness/index.d.ts +22 -0
- package/dist/e2e-harness/index.d.ts.map +1 -0
- package/dist/e2e-harness/index.js +48 -0
- package/dist/e2e-harness/jobs.d.ts +8 -0
- package/dist/e2e-harness/jobs.d.ts.map +1 -0
- package/dist/e2e-harness/jobs.js +34 -0
- package/dist/e2e-harness/pins.d.ts +45 -0
- package/dist/e2e-harness/pins.d.ts.map +1 -0
- package/dist/e2e-harness/pins.js +44 -0
- package/dist/e2e-harness/ports.d.ts +113 -0
- package/dist/e2e-harness/ports.d.ts.map +1 -0
- package/dist/e2e-harness/ports.js +4 -0
- package/dist/e2e-harness/reports.d.ts +45 -0
- package/dist/e2e-harness/reports.d.ts.map +1 -0
- package/dist/e2e-harness/reports.js +57 -0
- package/dist/e2e-harness/safe-run-cli.d.ts +17 -0
- package/dist/e2e-harness/safe-run-cli.d.ts.map +1 -0
- package/dist/e2e-harness/safe-run-cli.js +43 -0
- package/dist/e2e-harness/safe-run.d.ts +61 -0
- package/dist/e2e-harness/safe-run.d.ts.map +1 -0
- package/dist/e2e-harness/safe-run.js +172 -0
- package/dist/e2e-harness/scenario.d.ts +11 -0
- package/dist/e2e-harness/scenario.d.ts.map +1 -0
- package/dist/e2e-harness/scenario.js +89 -0
- package/dist/e2e-harness/schemas/demo-cycle.schema.json +282 -0
- package/dist/e2e-harness/schemas/demo-step.schema.json +245 -0
- package/dist/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
- package/dist/e2e-harness/schemas/e2e-claims.schema.json +18 -0
- package/dist/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
- package/dist/e2e-harness/schemas/index.d.ts +191 -0
- package/dist/e2e-harness/schemas/index.d.ts.map +1 -0
- package/dist/e2e-harness/schemas/index.js +62 -0
- package/dist/e2e-harness/stack.d.ts +124 -0
- package/dist/e2e-harness/stack.d.ts.map +1 -0
- package/dist/e2e-harness/stack.js +207 -0
- package/dist/e2e-harness/steps.d.ts +11 -0
- package/dist/e2e-harness/steps.d.ts.map +1 -0
- package/dist/e2e-harness/steps.js +22 -0
- package/dist/e2e-harness.d.ts +3 -0
- package/dist/e2e-harness.d.ts.map +1 -0
- package/dist/e2e-harness.js +2 -0
- package/dist/exit-codes.d.ts +7 -1
- package/dist/exit-codes.d.ts.map +1 -1
- package/dist/exit-codes.js +7 -1
- package/dist/lexicon.d.ts +46 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.js +2 -3
- package/dist/lifecycle/gated-request.d.ts.map +1 -1
- package/dist/lifecycle/gated-request.js +1 -2
- package/dist/lifecycle/query.d.ts.map +1 -1
- package/dist/lifecycle/query.js +4 -5
- package/dist/lifecycle/release-catalog.d.ts.map +1 -1
- package/dist/lifecycle/release-catalog.js +1 -1
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.js +1 -2
- package/dist/lifecycle/release-status.d.ts +20 -0
- package/dist/lifecycle/release-status.d.ts.map +1 -1
- package/dist/lifecycle/release-status.js +1 -22
- package/dist/lifecycle/wave-plans.d.ts +23 -7
- package/dist/lifecycle/wave-plans.d.ts.map +1 -1
- package/dist/lifecycle/wave-plans.js +9 -2
- package/dist/op/approval-status.d.ts +103 -0
- package/dist/op/approval-status.d.ts.map +1 -0
- package/dist/op/approval-status.js +197 -0
- package/dist/op/index.d.ts +1 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -1
- package/dist/op/op-waves-capability-spec.d.ts +8 -0
- package/dist/op/op-waves-capability-spec.d.ts.map +1 -1
- package/dist/op/op-waves-capability-spec.js +21 -0
- package/dist/op/op-waves-release.d.ts.map +1 -1
- package/dist/op/op-waves-release.js +1 -2
- package/dist/op/op-waves-run.d.ts +7 -2
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +96 -4
- package/dist/op/op-waves-stand-down.d.ts.map +1 -1
- package/dist/op/op-waves-stand-down.js +1 -2
- package/dist/op/op-waves.d.ts +35 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +46 -6
- package/dist/op/runtime.d.ts +4 -0
- package/dist/op/runtime.d.ts.map +1 -1
- package/dist/op/runtime.js +2 -3
- package/dist/otlp.d.ts.map +1 -1
- package/dist/otlp.js +1 -2
- package/dist/parallelism.d.ts +17 -0
- package/dist/parallelism.d.ts.map +1 -0
- package/dist/parallelism.js +33 -0
- package/dist/policy-source.d.ts.map +1 -1
- package/dist/policy-source.js +1 -2
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +56 -39
- package/dist/pr-loop.d.ts +9 -0
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +22 -3
- package/dist/pr-merge.d.ts +64 -0
- package/dist/pr-merge.d.ts.map +1 -0
- package/dist/pr-merge.js +78 -0
- package/dist/pr-post.d.ts +70 -1
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +116 -5
- package/dist/pr-report-url.d.ts.map +1 -1
- package/dist/pr-report-url.js +1 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/run-event.d.ts.map +1 -1
- package/dist/run-event.js +1 -2
- package/dist/scheduled-op-cloud.d.ts +32 -0
- package/dist/scheduled-op-cloud.d.ts.map +1 -0
- package/dist/scheduled-op-cloud.js +69 -0
- package/dist/wave-runtime.mjs +340 -327
- package/dist/workspace/ci-lock-grain.d.ts +5 -0
- package/dist/workspace/ci-lock-grain.d.ts.map +1 -1
- package/dist/workspace/ci-lock-grain.js +1 -7
- package/dist/workspace/ci-run.d.ts.map +1 -1
- package/dist/workspace/ci-run.js +5 -1
- package/dist/workspace/pr-report.schema.json +5 -0
- package/package.json +1 -1
- package/src/ci-agent.ts +1 -2
- package/src/ci-audit/__fixtures__/cloudtrail-lookup-bucket.json +37 -0
- package/src/ci-audit/__fixtures__/cloudtrail-writes-window.json +59 -0
- package/src/ci-audit/attribution.ts +260 -0
- package/src/ci-audit/audit-log.ts +220 -0
- package/src/ci-audit/ci-audit.test.ts +175 -0
- package/src/ci-audit/index.ts +15 -0
- package/src/ci-audit/unrecorded.ts +140 -0
- package/src/ci-audit.ts +2 -0
- package/src/ci-control.ts +3 -4
- package/src/ci-estate.ts +1 -2
- package/src/ci-identity-database.test.ts +2 -3
- package/src/ci-identity-targets.test.ts +1 -3
- package/src/ci-identity.ts +2 -3
- package/src/ci-job-guard.test.ts +154 -0
- package/src/ci-job-guard.ts +319 -0
- package/src/ci-jobs.ts +8 -0
- package/src/ci-product-comment-targets.test.ts +45 -0
- package/src/ci-product-words.ts +35 -6
- package/src/ci-product.ts +55 -3
- package/src/ci-respond-run.ts +291 -0
- package/src/ci-respond.test.ts +264 -0
- package/src/ci-respond.ts +412 -0
- package/src/cli/handlers/audit-log.ts +74 -0
- package/src/cli/handlers/build-pr-loop-flags.test.ts +98 -0
- package/src/cli/handlers/build.ts +69 -0
- package/src/cli/handlers/ci-check-job.test.ts +114 -0
- package/src/cli/handlers/ci-check-job.ts +33 -0
- package/src/cli/handlers/ci-check.ts +38 -8
- package/src/cli/handlers/e2e-safe-run.ts +27 -0
- package/src/cli/handlers/pr-plan-comment-targets.test.ts +166 -0
- package/src/cli/handlers/pr-plan-flags.test.ts +161 -0
- package/src/cli/handlers/pr.ts +228 -4
- package/src/cli/handlers/run-wave.ts +79 -1
- package/src/cli/main.test.ts +1 -1
- package/src/cli/main.ts +56 -2
- package/src/cli/parse-args.ts +77 -0
- package/src/cli/registry.ts +38 -0
- package/src/components/adoption.ts +1 -2
- package/src/components/capability.ts +50 -0
- package/src/components/check-hooks.ts +4 -1
- package/src/components/check-steps.test.ts +70 -0
- package/src/components/check-steps.ts +158 -0
- package/src/components/ci-services.ts +1 -2
- package/src/components/driver.ts +35 -1
- package/src/components/groups.ts +4 -2
- package/src/components/plan-flags.test.ts +46 -0
- package/src/components/pr-comment-preview-targets.test.ts +34 -0
- package/src/components/pr-env-ledger.ts +1 -2
- package/src/components/pr-env-run-bundle.test.ts +0 -20
- package/src/components/pr-environment.ts +1 -1
- package/src/components/pr-pipeline-runners.test.ts +80 -0
- package/src/components/pr-pipeline.ts +232 -17
- package/src/components/pr-run.ts +17 -6
- package/src/components/pr-stale-job.test.ts +34 -0
- package/src/components/product-pipeline.ts +50 -8
- package/src/components/wave-plan.ts +18 -2
- package/src/e2e-harness/__project__/chant.config.ts +4 -0
- package/src/e2e-harness/__project__/src/compose.ts +33 -0
- package/src/e2e-harness/bucket.ts +69 -0
- package/src/e2e-harness/claim.test.ts +150 -0
- package/src/e2e-harness/claim.ts +140 -0
- package/src/e2e-harness/driver.test.ts +304 -0
- package/src/e2e-harness/driver.ts +294 -0
- package/src/e2e-harness/forgejo.ts +267 -0
- package/src/e2e-harness/git.ts +96 -0
- package/src/e2e-harness/index.ts +50 -0
- package/src/e2e-harness/jobs.ts +35 -0
- package/src/e2e-harness/pins.ts +52 -0
- package/src/e2e-harness/ports.ts +130 -0
- package/src/e2e-harness/reports.ts +79 -0
- package/src/e2e-harness/safe-run-cli.test.ts +102 -0
- package/src/e2e-harness/safe-run-cli.ts +54 -0
- package/src/e2e-harness/safe-run.ts +198 -0
- package/src/e2e-harness/scenario.ts +89 -0
- package/src/e2e-harness/schemas/README.md +62 -0
- package/src/e2e-harness/schemas/demo-cycle.schema.json +282 -0
- package/src/e2e-harness/schemas/demo-step.schema.json +245 -0
- package/src/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
- package/src/e2e-harness/schemas/e2e-claims.schema.json +18 -0
- package/src/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
- package/src/e2e-harness/schemas/index.ts +220 -0
- package/src/e2e-harness/schemas.test.ts +145 -0
- package/src/e2e-harness/stack.test.ts +124 -0
- package/src/e2e-harness/stack.ts +306 -0
- package/src/e2e-harness/steps.ts +30 -0
- package/src/e2e-harness.ts +2 -0
- package/src/exit-codes.test.ts +3 -2
- package/src/exit-codes.ts +7 -1
- package/src/gate-decision-bundle.test.ts +0 -2
- package/src/lexicon.ts +48 -0
- package/src/lifecycle/control-entries-ledger.test.ts +2 -3
- package/src/lifecycle/gate-ledger.ts +2 -3
- package/src/lifecycle/gated-request.ts +1 -2
- package/src/lifecycle/query.ts +4 -5
- package/src/lifecycle/release-catalog.test.ts +3 -4
- package/src/lifecycle/release-catalog.ts +1 -1
- package/src/lifecycle/release-ledger.ts +1 -2
- package/src/lifecycle/release-status.test.ts +3 -4
- package/src/lifecycle/release-status.ts +1 -2
- package/src/lifecycle/wave-plans.ts +33 -5
- package/src/op/approval-status.test.ts +134 -0
- package/src/op/approval-status.ts +235 -0
- package/src/op/gate-review.test.ts +2 -1
- package/src/op/index.ts +2 -0
- package/src/op/op-waves-after-plan.test.ts +12 -0
- package/src/op/op-waves-capability-spec.ts +20 -0
- package/src/op/op-waves-parallelism.test.ts +89 -0
- package/src/op/op-waves-pull-request.test.ts +78 -1
- package/src/op/op-waves-release.ts +1 -2
- package/src/op/op-waves-run.ts +94 -4
- package/src/op/op-waves-stand-down.ts +1 -2
- package/src/op/op-waves.ts +63 -6
- package/src/op/runtime.ts +6 -3
- package/src/otlp.ts +1 -2
- package/src/parallelism.test.ts +38 -0
- package/src/parallelism.ts +33 -0
- package/src/policy-source.ts +1 -2
- package/src/pr-forge-bundle.test.ts +1 -1
- package/src/pr-forge.ts +54 -35
- package/src/pr-loop-bundle.test.ts +1 -1
- package/src/pr-loop-narrowed.test.ts +63 -0
- package/src/pr-loop.ts +30 -3
- package/src/pr-merge.test.ts +100 -0
- package/src/pr-merge.ts +105 -0
- package/src/pr-post-stale.test.ts +163 -0
- package/src/pr-post.ts +159 -5
- package/src/pr-report-url.ts +1 -2
- package/src/product-subpaths-plain-node.e2e.test.ts +1 -0
- package/src/release-floors.ts +1 -1
- package/src/run-event.ts +1 -2
- package/src/scheduled-op-cloud.ts +68 -0
- package/src/stage-hooks-bundle.test.ts +0 -2
- package/src/workspace/ci-lock-grain.ts +1 -2
- package/src/workspace/ci-run.ts +5 -1
- package/src/workspace/pr-report.schema.json +5 -0
package/src/pr-forge.ts
CHANGED
|
@@ -675,6 +675,11 @@ export class ForgeApiError extends Error {
|
|
|
675
675
|
}
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
+
/** The forge answered 404. */
|
|
679
|
+
const notFound = (err: unknown): boolean => err instanceof ForgeApiError && err.status === 404;
|
|
680
|
+
|
|
681
|
+
const byNumber = (a: { number: number }, b: { number: number }): number => a.number - b.number;
|
|
682
|
+
|
|
678
683
|
const DEFAULT_HOST: Record<ForgeKind, string | null> = { github: "github.com", gitlab: "gitlab.com", forgejo: null };
|
|
679
684
|
|
|
680
685
|
/** `<forge>:<login>` on the forge's default host, `<forge>@<host>:<login>` elsewhere, lower-cased (#3163's form). */
|
|
@@ -900,6 +905,22 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
|
|
|
900
905
|
const url = str(v.html_url);
|
|
901
906
|
return { number, title: str(v.title) ?? "", body: str(v.body) ?? "", head: head ?? "", ...(base ? { base } : {}), ...(url ? { url } : {}) };
|
|
902
907
|
};
|
|
908
|
+
/**
|
|
909
|
+
* The open pull requests; GitHub takes `filter` server-side, Forgejo's list
|
|
910
|
+
* takes none and is matched by the caller. Forgejo answers the list with
|
|
911
|
+
* 404 while it still counts the repository as empty (just after the first
|
|
912
|
+
* push). That is no pull request; a repository that is really missing 404s
|
|
913
|
+
* on its own read too.
|
|
914
|
+
*/
|
|
915
|
+
const openPulls = async (filter: string): Promise<unknown[]> => {
|
|
916
|
+
try {
|
|
917
|
+
return await api.list(`${repo}/pulls?state=open${kind === "github" ? filter : ""}`, pageParams, pageSize);
|
|
918
|
+
} catch (err) {
|
|
919
|
+
if (kind !== "forgejo" || !notFound(err)) throw err;
|
|
920
|
+
await api.call("GET", repo);
|
|
921
|
+
return [];
|
|
922
|
+
}
|
|
923
|
+
};
|
|
903
924
|
/** A pull request whose head branch lives in this repository, not a fork. */
|
|
904
925
|
const fromHere = (v: unknown, head: string): boolean => {
|
|
905
926
|
if (!isObject(v) || !isObject(v.head) || v.head.ref !== head) return false;
|
|
@@ -950,7 +971,7 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
|
|
|
950
971
|
try {
|
|
951
972
|
b = await api.call("GET", `${repo}/branches/${branch.split("/").map(encodeURIComponent).join("/")}`);
|
|
952
973
|
} catch (err) {
|
|
953
|
-
if (err
|
|
974
|
+
if (notFound(err)) return undefined;
|
|
954
975
|
throw err;
|
|
955
976
|
}
|
|
956
977
|
// GitHub names the commit `sha`, Forgejo `id`.
|
|
@@ -1084,7 +1105,7 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
|
|
|
1084
1105
|
const got = await api.call("GET", `${repo}/pulls/${pr}`);
|
|
1085
1106
|
return isObject(got) && got.state === "open" && got.merged !== true;
|
|
1086
1107
|
} catch (err) {
|
|
1087
|
-
if (err
|
|
1108
|
+
if (notFound(err)) return false;
|
|
1088
1109
|
throw err;
|
|
1089
1110
|
}
|
|
1090
1111
|
},
|
|
@@ -1094,7 +1115,7 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
|
|
|
1094
1115
|
const pr = await api.call("GET", `${repo}/commits/${sha}/pull`);
|
|
1095
1116
|
return isObject(pr) && typeof pr.number === "number" ? pr.number : null;
|
|
1096
1117
|
} catch (err) {
|
|
1097
|
-
if (err
|
|
1118
|
+
if (notFound(err)) return null;
|
|
1098
1119
|
throw err;
|
|
1099
1120
|
}
|
|
1100
1121
|
}
|
|
@@ -1121,33 +1142,12 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
|
|
|
1121
1142
|
// GitHub filters by `owner:branch` server-side; Forgejo's list takes no
|
|
1122
1143
|
// head filter, so every open page is read and matched here.
|
|
1123
1144
|
const owner = opts.repo.split("/")[0];
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
try {
|
|
1127
|
-
listed = await api.list(`${repo}/pulls${query}`, pageParams, pageSize);
|
|
1128
|
-
} catch (err) {
|
|
1129
|
-
// Forgejo answers the list with 404 while it still counts the repository
|
|
1130
|
-
// as empty (just after the first push). That is no pull request; a
|
|
1131
|
-
// repository that is really missing 404s on its own read too.
|
|
1132
|
-
if (kind !== "forgejo" || !(err instanceof ForgeApiError) || err.status !== 404) throw err;
|
|
1133
|
-
await api.call("GET", repo);
|
|
1134
|
-
return undefined;
|
|
1135
|
-
}
|
|
1136
|
-
const open = listed.filter((p) => fromHere(p, head));
|
|
1137
|
-
return open.map(pull).filter((p): p is PullRequest => p !== undefined).sort((a, b) => a.number - b.number)[0];
|
|
1145
|
+
const open = (await openPulls(`&head=${encodeURIComponent(`${owner}:${head}`)}`)).filter((p) => fromHere(p, head));
|
|
1146
|
+
return open.map(pull).filter((p): p is PullRequest => p !== undefined).sort(byNumber)[0];
|
|
1138
1147
|
},
|
|
1139
1148
|
async openPullRequests(base) {
|
|
1140
1149
|
// GitHub filters by base server-side; Forgejo's list is matched here.
|
|
1141
|
-
const
|
|
1142
|
-
let listed: unknown[];
|
|
1143
|
-
try {
|
|
1144
|
-
listed = await api.list(`${repo}/pulls${query}`, pageParams, pageSize);
|
|
1145
|
-
} catch (err) {
|
|
1146
|
-
// Forgejo answers 404 while it counts the repository as empty, as findPullRequest notes.
|
|
1147
|
-
if (kind !== "forgejo" || !(err instanceof ForgeApiError) || err.status !== 404) throw err;
|
|
1148
|
-
await api.call("GET", repo);
|
|
1149
|
-
return [];
|
|
1150
|
-
}
|
|
1150
|
+
const listed = await openPulls(`&base=${encodeURIComponent(base)}`);
|
|
1151
1151
|
const out: OpenPullRequest[] = [];
|
|
1152
1152
|
for (const v of listed) {
|
|
1153
1153
|
if (!isObject(v) || !isObject(v.head) || !isObject(v.base)) continue;
|
|
@@ -1160,7 +1160,7 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
|
|
|
1160
1160
|
const author = isObject(v.user) ? str(v.user.login) : undefined;
|
|
1161
1161
|
out.push({ number, head, headSha, base: into, ...(baseSha ? { baseSha } : {}), ...(author ? { author } : {}), fork: !fromHere(v, head) });
|
|
1162
1162
|
}
|
|
1163
|
-
return out.sort(
|
|
1163
|
+
return out.sort(byNumber);
|
|
1164
1164
|
},
|
|
1165
1165
|
branchHead: branchTip,
|
|
1166
1166
|
async pullRequestHead(pr) {
|
|
@@ -1168,7 +1168,7 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
|
|
|
1168
1168
|
try {
|
|
1169
1169
|
got = await api.call("GET", `${repo}/pulls/${pr}`);
|
|
1170
1170
|
} catch (err) {
|
|
1171
|
-
if (err
|
|
1171
|
+
if (notFound(err)) return undefined;
|
|
1172
1172
|
throw err;
|
|
1173
1173
|
}
|
|
1174
1174
|
if (!isObject(got) || !isObject(got.head)) return undefined;
|
|
@@ -1336,6 +1336,8 @@ export function gitlabForge(opts: GitlabForgeOptions): PrForge {
|
|
|
1336
1336
|
return { id, body: str(v.description) ?? "", ...(created ? { created } : {}), ...(str(v.title) !== undefined ? { title: str(v.title) } : {}), ...(author ? { author } : {}), ...(url ? { url } : {}) };
|
|
1337
1337
|
};
|
|
1338
1338
|
const notes = `${project}/merge_requests`;
|
|
1339
|
+
/** The open merge requests from (`source`) or into (`target`) `branch`. */
|
|
1340
|
+
const openMrs = (end: "source" | "target", branch: string): Promise<unknown[]> => api.list(`${notes}?state=opened&${end}_branch=${encodeURIComponent(branch)}`, pageParams, 100);
|
|
1339
1341
|
const mergeRequest = (v: unknown): PullRequest | undefined => {
|
|
1340
1342
|
if (!isObject(v)) return undefined;
|
|
1341
1343
|
const number = num(v.iid);
|
|
@@ -1457,7 +1459,7 @@ export function gitlabForge(opts: GitlabForgeOptions): PrForge {
|
|
|
1457
1459
|
try {
|
|
1458
1460
|
member = await api.call("GET", `${project}/members/all/${id}`);
|
|
1459
1461
|
} catch (err) {
|
|
1460
|
-
if (err
|
|
1462
|
+
if (notFound(err)) return `${login} is not a member`;
|
|
1461
1463
|
return `could not read ${login}'s access (${err instanceof Error ? err.message : String(err)})`;
|
|
1462
1464
|
}
|
|
1463
1465
|
const level = isObject(member) ? (num(member.access_level) ?? 0) : 0;
|
|
@@ -1510,7 +1512,7 @@ export function gitlabForge(opts: GitlabForgeOptions): PrForge {
|
|
|
1510
1512
|
const got = await api.call("GET", `${notes}/${mr}`);
|
|
1511
1513
|
return isObject(got) && got.state === "opened";
|
|
1512
1514
|
} catch (err) {
|
|
1513
|
-
if (err
|
|
1515
|
+
if (notFound(err)) return false;
|
|
1514
1516
|
throw err;
|
|
1515
1517
|
}
|
|
1516
1518
|
},
|
|
@@ -1528,13 +1530,13 @@ export function gitlabForge(opts: GitlabForgeOptions): PrForge {
|
|
|
1528
1530
|
return mergeRequest(made) ?? { number: 0, title, body: spec.body, head: spec.head, base };
|
|
1529
1531
|
},
|
|
1530
1532
|
async findPullRequest(head) {
|
|
1531
|
-
const open = await
|
|
1533
|
+
const open = await openMrs("source", head);
|
|
1532
1534
|
return open
|
|
1533
1535
|
// A fork's merge request into this project has another source project.
|
|
1534
1536
|
.filter((m) => isObject(m) && m.source_branch === head && (m.source_project_id === undefined || m.source_project_id === m.project_id))
|
|
1535
1537
|
.map(mergeRequest)
|
|
1536
1538
|
.filter((m): m is PullRequest => m !== undefined)
|
|
1537
|
-
.sort(
|
|
1539
|
+
.sort(byNumber)[0];
|
|
1538
1540
|
},
|
|
1539
1541
|
async scheduledRuns(q) {
|
|
1540
1542
|
// The variable the gitlab lexicon's generated Op file selects a scheduled job by.
|
|
@@ -1549,9 +1551,26 @@ export function gitlabForge(opts: GitlabForgeOptions): PrForge {
|
|
|
1549
1551
|
const last = newestTime(pipelines.map((p) => (isObject(p) ? str(p.created_at) : undefined)));
|
|
1550
1552
|
return { ...(last ? { last } : {}), ...(ours.length === 0 ? { noSchedule: true } : {}) };
|
|
1551
1553
|
},
|
|
1554
|
+
// #4628: the open merge requests into `base`, for the stale marking a push to it runs.
|
|
1555
|
+
async openPullRequests(base) {
|
|
1556
|
+
const out: OpenPullRequest[] = [];
|
|
1557
|
+
for (const m of await openMrs("target", base)) {
|
|
1558
|
+
if (!isObject(m)) continue;
|
|
1559
|
+
const number = num(m.iid);
|
|
1560
|
+
const head = str(m.source_branch);
|
|
1561
|
+
const headSha = str(m.sha);
|
|
1562
|
+
if (number === undefined || !head || !headSha || str(m.target_branch) !== base) continue;
|
|
1563
|
+
const refs = isObject(m.diff_refs) ? m.diff_refs : undefined;
|
|
1564
|
+
const baseSha = refs ? str(refs.base_sha) : undefined;
|
|
1565
|
+
const author = isObject(m.author) ? str(m.author.username) : undefined;
|
|
1566
|
+
const fork = num(m.source_project_id) !== undefined && num(m.source_project_id) !== num(m.target_project_id);
|
|
1567
|
+
out.push({ number, head, headSha, base, ...(baseSha ? { baseSha } : {}), ...(author ? { author } : {}), fork });
|
|
1568
|
+
}
|
|
1569
|
+
return out.sort(byNumber);
|
|
1570
|
+
},
|
|
1552
1571
|
async mergeRequestJobs(branch, job) {
|
|
1553
1572
|
const out: MergeRequestJob[] = [];
|
|
1554
|
-
const open = await
|
|
1573
|
+
const open = await openMrs("target", branch);
|
|
1555
1574
|
for (const m of open) {
|
|
1556
1575
|
if (!isObject(m)) continue;
|
|
1557
1576
|
const iid = num(m.iid);
|
|
@@ -1579,7 +1598,7 @@ export function gitlabForge(opts: GitlabForgeOptions): PrForge {
|
|
|
1579
1598
|
try {
|
|
1580
1599
|
got = await api.call("GET", `${notes}/${mr}`);
|
|
1581
1600
|
} catch (err) {
|
|
1582
|
-
if (err
|
|
1601
|
+
if (notFound(err)) return undefined;
|
|
1583
1602
|
throw err;
|
|
1584
1603
|
}
|
|
1585
1604
|
if (!isObject(got)) return undefined;
|
|
@@ -45,7 +45,7 @@ describe("the pull-request loop bundle", () => {
|
|
|
45
45
|
"packages/core/src/pr-migrations.ts",
|
|
46
46
|
// The Pulumi URN rule (#4548, the may-appear rows): no imports.
|
|
47
47
|
"packages/core/src/pulumi-urn.ts",
|
|
48
|
-
// The next-release floor constant (#4480): no imports.
|
|
48
|
+
// The next-release floor constant (#4480, #4626's narrowed floor): no imports.
|
|
49
49
|
"packages/core/src/release-floors.ts",
|
|
50
50
|
]);
|
|
51
51
|
// About 89 KB today, after the hooks line (#4288), the blocked set (#4291), the scheduled-run reads (#4289) the requires checks (#4301) and the migration notes (#4407), about 97 KB; with the group lines (#4446), about 100 KB.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A narrowed plan in the note and the status (#4626): each narrowed
|
|
3
|
+
* member's row lists its addresses, a line says the plan on merge is of
|
|
4
|
+
* each member whole, and the status counts the narrowed members, in the
|
|
5
|
+
* product's words. Written for the ci-products post-merge pass.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import { composeChangeSet } from "./change-set";
|
|
9
|
+
import { memberCounts, PR_REPORT_SCHEMA_ID, prStatusDescription, renderPrNote, type PrReport } from "./pr-loop";
|
|
10
|
+
import { assertProductWords } from "./ci-product-words";
|
|
11
|
+
import { PLYWOOD } from "./__fixtures__/product-words";
|
|
12
|
+
|
|
13
|
+
const hex = (n: number) => n.toString(16).padStart(64, "0");
|
|
14
|
+
const URN = "urn:pulumi:dev::shop::aws:s3/bucket:Bucket::site";
|
|
15
|
+
const doc = composeChangeSet([
|
|
16
|
+
{
|
|
17
|
+
member: { member: "shop-dev", lexicon: "pulumi", planner: "pulumi", status: "planned", planDigest: `jcs1-sha256:${hex(1)}`, holes: [] },
|
|
18
|
+
entries: [{ member: "shop-dev", lexicon: "pulumi", planner: "pulumi", address: URN, type: "aws:s3/bucket:Bucket", action: "create", attributes: [] }],
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
const report: PrReport = {
|
|
22
|
+
$schema: PR_REPORT_SCHEMA_ID,
|
|
23
|
+
contract: 1,
|
|
24
|
+
stage: "plan",
|
|
25
|
+
pr: 12,
|
|
26
|
+
env: "dev",
|
|
27
|
+
base: "1".repeat(40),
|
|
28
|
+
head: "2".repeat(40),
|
|
29
|
+
op: "pulumi-up",
|
|
30
|
+
gate: "up",
|
|
31
|
+
digest: doc.digest,
|
|
32
|
+
status: "planned",
|
|
33
|
+
approval: { status: "pending" },
|
|
34
|
+
selection: { changed: ["shop"], dependents: [], unclaimed: [], indeterminate: [], waves: [["shop"]] },
|
|
35
|
+
members: [{ member: "shop-dev", component: "shop", planDigest: `jcs1-sha256:${hex(1)}`, status: "planned", counts: memberCounts(doc, "shop-dev") }],
|
|
36
|
+
changeSet: doc,
|
|
37
|
+
};
|
|
38
|
+
const plywood = assertProductWords(PLYWOOD);
|
|
39
|
+
|
|
40
|
+
describe("a narrowed plan (#4626)", () => {
|
|
41
|
+
const narrowed: PrReport = { ...report, narrowed: { shop: [URN] } };
|
|
42
|
+
|
|
43
|
+
test("the member's row lists the addresses", () => {
|
|
44
|
+
const note = renderPrNote(narrowed, { words: plywood });
|
|
45
|
+
const row = note.split("\n").find((l) => l.startsWith("| `shop-dev`"))!;
|
|
46
|
+
expect(row).toContain(`narrowed to \`${URN}\``);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("a line says so in the product's words, and that the update on merge plans each stack whole", () => {
|
|
50
|
+
const note = renderPrNote(narrowed, { words: plywood });
|
|
51
|
+
expect(note).toContain(`This preview was narrowed with \`--target\`: \`shop\` to \`${URN}\`. The approval binds the narrowed plan. On merge each stack is previewed whole.`);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("the status counts the narrowed members", () => {
|
|
55
|
+
expect(prStatusDescription(narrowed, plywood)).toMatch(/^1 stack \(1 narrowed with --target\): /);
|
|
56
|
+
expect(prStatusDescription(narrowed, plywood).length).toBeLessThanOrEqual(140);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("a plan that was not narrowed says nothing of it", () => {
|
|
60
|
+
expect(renderPrNote(report, { words: plywood })).not.toContain("narrowed");
|
|
61
|
+
expect(prStatusDescription(report, plywood)).not.toContain("narrowed");
|
|
62
|
+
});
|
|
63
|
+
});
|
package/src/pr-loop.ts
CHANGED
|
@@ -102,10 +102,13 @@ export const PR_REPORT_NOT_STARTED_FLOOR = "0.124.54";
|
|
|
102
102
|
export const PR_REPORT_GROUPS_FLOOR = "0.124.54";
|
|
103
103
|
|
|
104
104
|
/** The first chant whose report can carry `lockTargets` (#4552). */
|
|
105
|
-
export const PR_REPORT_LOCK_TARGETS_FLOOR =
|
|
105
|
+
export const PR_REPORT_LOCK_TARGETS_FLOOR = "0.124.55";
|
|
106
|
+
|
|
107
|
+
/** The first chant whose report carries {@link PrReport.narrowed} (#4626). */
|
|
108
|
+
export const PR_REPORT_NARROWED_FLOOR = NEXT_RELEASE;
|
|
106
109
|
|
|
107
110
|
/** The first chant whose report carries {@link PrReport.crossStackEdges} (#4617). */
|
|
108
|
-
export const PR_REPORT_CROSS_STACK_FLOOR =
|
|
111
|
+
export const PR_REPORT_CROSS_STACK_FLOOR = "0.124.55";
|
|
109
112
|
|
|
110
113
|
/** The gate a pull request's apply waits on, unless the pipeline names another. */
|
|
111
114
|
export const PR_APPLY_GATE = "pr-apply";
|
|
@@ -593,6 +596,13 @@ export interface PrReport {
|
|
|
593
596
|
* {@link PR_REPORT_LOCK_TARGETS_FLOOR}.
|
|
594
597
|
*/
|
|
595
598
|
lockTargets?: string[];
|
|
599
|
+
/**
|
|
600
|
+
* Plan stage (#4626): the addresses each component's plan was narrowed to
|
|
601
|
+
* with `pr-plan --target`, from the command line or the comment, by
|
|
602
|
+
* component. The note and the status say so. Absent when nothing was
|
|
603
|
+
* narrowed. Added within contract 1 by chant {@link PR_REPORT_NARROWED_FLOOR}.
|
|
604
|
+
*/
|
|
605
|
+
narrowed?: Record<string, string[]>;
|
|
596
606
|
/**
|
|
597
607
|
* The stacks outside the workspace a member reads (#4617, a Pulumi
|
|
598
608
|
* `StackReference` no step here applies, #4547), each marked stale,
|
|
@@ -1109,6 +1119,8 @@ export function renderPrNote(report: PrReport, options: { limit?: number; approv
|
|
|
1109
1119
|
(m.groupOutcome === "partial" ? ", applied in part" : m.groupOutcome === "no-changes" ? ", no changes" : "") +
|
|
1110
1120
|
(m.inputsMoved?.length ? `, inputs from ${m.inputsMoved.join(", ")} moved` : "") +
|
|
1111
1121
|
(placeholders.length > 0 ? `, previewed with placeholders for ${placeholders.map(code).join(", ")}` : "") +
|
|
1122
|
+
// #4626: a member whose plan was narrowed says to what.
|
|
1123
|
+
(report.narrowed?.[m.component] ? `, narrowed to ${report.narrowed[m.component]!.map(code).join(", ")}` : "") +
|
|
1112
1124
|
(holes.length > 0 ? `; ${holes.length > 2 ? `${holes[0]}; and ${holes.length - 1} more, listed under Holes` : holes.join("; ")}` : "");
|
|
1113
1125
|
// A member whose plan has holes and no entries says nothing about what
|
|
1114
1126
|
// it changes, so its counts are unknown, not zero (#4084).
|
|
@@ -1120,6 +1132,7 @@ export function renderPrNote(report: PrReport, options: { limit?: number; approv
|
|
|
1120
1132
|
out.push("", `A ${noun} whose inputs moved ${words.verbs.apply[1]} the plan it was approved with. The next run plans it against the new values.`);
|
|
1121
1133
|
}
|
|
1122
1134
|
}
|
|
1135
|
+
out.push(...narrowedLines(report, words));
|
|
1123
1136
|
out.push(...mayAppearLines(report, options.applyWord ?? words.stages.apply));
|
|
1124
1137
|
const blocked = blockedLine(report.members);
|
|
1125
1138
|
if (blocked) out.push("", blocked);
|
|
@@ -1220,6 +1233,18 @@ function memberDetailSections(report: PrReport, room: number, noun: string): str
|
|
|
1220
1233
|
return out.length > 0 ? out.join("\n") + "\n" : "";
|
|
1221
1234
|
}
|
|
1222
1235
|
|
|
1236
|
+
/**
|
|
1237
|
+
* The note's line for a narrowed plan (#4626): which of the plan's
|
|
1238
|
+
* components were narrowed and to how many addresses, and that the plan on
|
|
1239
|
+
* merge is of each whole, in the product's words.
|
|
1240
|
+
*/
|
|
1241
|
+
function narrowedLines(report: PrReport, words: CiProductWords): string[] {
|
|
1242
|
+
const narrowed = Object.entries(report.narrowed ?? {}).filter(([, a]) => a.length > 0);
|
|
1243
|
+
if (narrowed.length === 0) return [];
|
|
1244
|
+
const each = narrowed.map(([c, a]) => `${code(c)} to ${a.map(code).join(", ")}`).join("; ");
|
|
1245
|
+
return ["", `This ${words.verbs.plan[0]} was narrowed with \`--target\`: ${each}. The approval binds the narrowed plan. On merge each ${words.noun[0]} is ${words.verbs.plan[1]} whole.`];
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1223
1248
|
/** A commit status's description, at most 140 characters (GitHub's limit). */
|
|
1224
1249
|
export function prStatusDescription(report: PrReport, words: CiProductWords = activeProductWords()): string {
|
|
1225
1250
|
const n = report.members.length;
|
|
@@ -1236,7 +1261,9 @@ export function prStatusDescription(report: PrReport, words: CiProductWords = ac
|
|
|
1236
1261
|
break;
|
|
1237
1262
|
case "planned": {
|
|
1238
1263
|
const unknown = report.members.filter((m) => memberHoleReasons(report, m.member).length > 0).length;
|
|
1239
|
-
|
|
1264
|
+
// #4626: a narrowed plan says so in its status.
|
|
1265
|
+
const narrowed = Object.values(report.narrowed ?? {}).filter((a) => a.length > 0).length;
|
|
1266
|
+
text = `${many(n)}${narrowed > 0 ? ` (${narrowed} narrowed with --target)` : ""}: ${sum.change} to change, ${sum.destroy} to destroy or replace${unknown > 0 ? `, ${unknown} with holes` : ""}${digest}`;
|
|
1240
1267
|
break;
|
|
1241
1268
|
}
|
|
1242
1269
|
case "plan-failed":
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4636: `pr-apply --before-merge --merge auto` merges the pull request once
|
|
3
|
+
* its update applied and the records are pushed, with the head checked
|
|
4
|
+
* again, on fake GitHub, GitLab and Forgejo forges. A refusal is posted and
|
|
5
|
+
* never applies again.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, test } from "vitest";
|
|
9
|
+
import { parseArgs } from "./cli/parse-args";
|
|
10
|
+
import { prLoopJobs } from "./components/pr-pipeline";
|
|
11
|
+
import { ciLoopOptions } from "./workspace/ci-run";
|
|
12
|
+
import { mergeAfterApply, mergeTokenEnv, prMergeMarker } from "./pr-merge";
|
|
13
|
+
import type { MergeOptions, MergeResult, PullRequestHead } from "./pr-forge";
|
|
14
|
+
|
|
15
|
+
const HEAD = "a".repeat(40);
|
|
16
|
+
|
|
17
|
+
function fakeForge(kind: "github" | "gitlab" | "forgejo", o: { head?: PullRequestHead; merge?: MergeResult | Error } = {}) {
|
|
18
|
+
const merges: Array<{ pr: number; opts: MergeOptions }> = [];
|
|
19
|
+
const comments: Array<{ pr: number; marker: string; body: string }> = [];
|
|
20
|
+
const forge = {
|
|
21
|
+
kind,
|
|
22
|
+
async pullRequestHead() {
|
|
23
|
+
return o.head ?? { sha: HEAD, branch: "feature", open: true, sameRepo: true };
|
|
24
|
+
},
|
|
25
|
+
async mergePullRequest(pr: number, opts: MergeOptions) {
|
|
26
|
+
merges.push({ pr, opts });
|
|
27
|
+
if (o.merge instanceof Error) throw o.merge;
|
|
28
|
+
return o.merge ?? { merged: true, sha: "b".repeat(40) };
|
|
29
|
+
},
|
|
30
|
+
async upsertComment(pr: number, marker: string, body: string) {
|
|
31
|
+
comments.push({ pr, marker, body });
|
|
32
|
+
return { action: "created" as const, id: 1 };
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
return { forge, merges, comments };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const pushed = { pushed: true };
|
|
39
|
+
|
|
40
|
+
describe("the merge after an update before merge (#4636)", () => {
|
|
41
|
+
for (const kind of ["github", "gitlab", "forgejo"] as const) {
|
|
42
|
+
test(`merges only the head that applied, once the records are pushed (${kind})`, async () => {
|
|
43
|
+
const { forge, merges, comments } = fakeForge(kind);
|
|
44
|
+
expect(await mergeAfterApply({ forge, pr: 7, head: HEAD, method: "squash", recorded: pushed })).toEqual({ merged: true, sha: "b".repeat(40) });
|
|
45
|
+
expect(merges).toEqual([{ pr: 7, opts: { sha: HEAD, method: "squash" } }]);
|
|
46
|
+
expect(comments).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test(`a refused merge posts the reason and is never retried (${kind})`, async () => {
|
|
50
|
+
const { forge, merges, comments } = fakeForge(kind, { merge: { merged: false, reason: 'Required status check "ci" is expected' } });
|
|
51
|
+
const r = await mergeAfterApply({ forge, pr: 7, head: HEAD, recorded: pushed });
|
|
52
|
+
expect(r).toMatchObject({ merged: false, posted: true, reason: expect.stringContaining("Required status check") });
|
|
53
|
+
expect(merges).toHaveLength(1);
|
|
54
|
+
expect(comments[0]).toMatchObject({ pr: 7, marker: prMergeMarker(7) });
|
|
55
|
+
expect(comments[0]!.body).toContain("stays applied and recorded; it is never applied again to merge");
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
test("a new push since the apply, a closed pull request, or records that did not land stop the merge before it is asked", async () => {
|
|
60
|
+
const moved = fakeForge("github", { head: { sha: "c".repeat(40), branch: "feature", open: true, sameRepo: true } });
|
|
61
|
+
expect(await mergeAfterApply({ forge: moved.forge, pr: 7, head: HEAD, recorded: pushed })).toMatchObject({ merged: false, reason: expect.stringContaining("not aaaaaaaaaaaa, the commit that applied") });
|
|
62
|
+
expect(moved.merges).toEqual([]);
|
|
63
|
+
const closed = fakeForge("forgejo", { head: { sha: HEAD, branch: "feature", open: false, sameRepo: true } });
|
|
64
|
+
expect((await mergeAfterApply({ forge: closed.forge, pr: 7, head: HEAD, recorded: pushed })).reason).toBe("it is no longer open");
|
|
65
|
+
const unpushed = fakeForge("gitlab");
|
|
66
|
+
const r = await mergeAfterApply({ forge: unpushed.forge, pr: 7, head: HEAD, recorded: { pushed: false, warning: "chant/lifecycle has no remote" } });
|
|
67
|
+
expect(r.reason).toContain("records are not on the ledger's remote (chant/lifecycle has no remote)");
|
|
68
|
+
expect(unpushed.merges).toEqual([]);
|
|
69
|
+
expect(unpushed.comments[0]!.body).toContain("Merge request !7 was not merged");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("a forge error is a refusal, posted", async () => {
|
|
73
|
+
const { forge, comments } = fakeForge("github", { merge: new Error("500 Internal Server Error") });
|
|
74
|
+
expect(await mergeAfterApply({ forge, pr: 7, head: HEAD, recorded: pushed })).toMatchObject({ merged: false, posted: true });
|
|
75
|
+
expect(comments).toHaveLength(1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("the merge client holds the named token and no other", () => {
|
|
79
|
+
const env = mergeTokenEnv("PLYWOOD_MERGE_TOKEN", { GITHUB_TOKEN: "job", CHANT_FORGE_TOKEN: "plan", PLYWOOD_MERGE_TOKEN: "merge", GITHUB_REPOSITORY: "acme/infra" });
|
|
80
|
+
expect(env).toEqual({ CHANT_FORGE_TOKEN: "merge", PLYWOOD_MERGE_TOKEN: "merge", GITHUB_REPOSITORY: "acme/infra" });
|
|
81
|
+
expect(mergeTokenEnv("PLYWOOD_MERGE_TOKEN", {})).toEqual({ error: expect.stringContaining("not set") });
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("the pipeline carries --merge auto (#4636)", () => {
|
|
86
|
+
test("the apply before merge job runs with the merge flags and maps the secret on GitHub", () => {
|
|
87
|
+
const [, apply] = prLoopJobs("github", "prod", { applyBeforeMerge: true, applyMerge: { tokenEnv: "PLYWOOD_MERGE_TOKEN", method: "squash" } });
|
|
88
|
+
expect(apply!.command).toContain("pr-apply --before-merge --merge auto --merge-token-env PLYWOOD_MERGE_TOKEN --merge-method squash");
|
|
89
|
+
expect(apply!.run.command).toContain("--apply-before-merge --merge auto --merge-token-env PLYWOOD_MERGE_TOKEN --merge-method squash");
|
|
90
|
+
expect(apply!.env.PLYWOOD_MERGE_TOKEN).toBe("${{ secrets.PLYWOOD_MERGE_TOKEN }}");
|
|
91
|
+
const [, gitlab] = prLoopJobs("gitlab", "prod", { applyBeforeMerge: true, applyMerge: { tokenEnv: "PLYWOOD_MERGE_TOKEN" } });
|
|
92
|
+
expect(gitlab!.env.PLYWOOD_MERGE_TOKEN).toBeUndefined();
|
|
93
|
+
expect(() => prLoopJobs("github", "prod", { applyMerge: { tokenEnv: "X" } })).toThrow(/apply-before-merge/);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("chant ci run apply passes the flags on to pr-apply", () => {
|
|
97
|
+
const args = parseArgs(["ci", "run", "apply", "--apply-before-merge", "--merge", "auto", "--merge-token-env", "PLYWOOD_MERGE_TOKEN"]);
|
|
98
|
+
expect(ciLoopOptions(args).applyMerge).toEqual({ tokenEnv: "PLYWOOD_MERGE_TOKEN" });
|
|
99
|
+
});
|
|
100
|
+
});
|
package/src/pr-merge.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto merge after an update before merge (#4636): `pr-apply --before-merge
|
|
3
|
+
* --merge auto --merge-token-env <VAR>` merges the pull request once every
|
|
4
|
+
* member applied and the apply's records are on the ledger's remote.
|
|
5
|
+
*
|
|
6
|
+
* The merge is a second step after the apply, and never a reason to apply
|
|
7
|
+
* again:
|
|
8
|
+
*
|
|
9
|
+
* - The records come first. The apply's release records and gate facts are
|
|
10
|
+
* pushed to `chant/lifecycle`; a push that did not land leaves the pull
|
|
11
|
+
* request open with the reason posted.
|
|
12
|
+
* - The head is checked again. The pull request must still be open at the
|
|
13
|
+
* commit that applied, and the forge's merge is asked to merge only that
|
|
14
|
+
* commit, so a push after the apply is never merged unapplied.
|
|
15
|
+
* - A refusal (branch protection, a new push, a conflict, a closed pull
|
|
16
|
+
* request) is posted on the pull request in one comment the next attempt
|
|
17
|
+
* edits, and the apply stays as it was recorded.
|
|
18
|
+
* - The merge's forge client holds the token `--merge-token-env` names and
|
|
19
|
+
* no other: never the plan job's token, nor the apply job's own. On GitLab
|
|
20
|
+
* the variable is a protected one.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { activeProductWords, type CiProductWords } from "./ci-product-words";
|
|
24
|
+
import type { MergeOptions, PrForge } from "./pr-forge";
|
|
25
|
+
|
|
26
|
+
/** How a pull request applied before merge gets merged. */
|
|
27
|
+
export type PrApplyMerge = "manual" | "auto";
|
|
28
|
+
|
|
29
|
+
export const PR_APPLY_MERGES: readonly PrApplyMerge[] = ["manual", "auto"];
|
|
30
|
+
|
|
31
|
+
export type PrMergeMethod = NonNullable<MergeOptions["method"]>;
|
|
32
|
+
|
|
33
|
+
export const PR_MERGE_METHODS: readonly PrMergeMethod[] = ["merge", "squash", "rebase"];
|
|
34
|
+
|
|
35
|
+
/** The marker of the comment a refused merge posts. */
|
|
36
|
+
export function prMergeMarker(pr: number): string {
|
|
37
|
+
return `<!-- chant:merge:${pr} -->`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What {@link mergeAfterApply} did. */
|
|
41
|
+
export interface MergeAfterApply {
|
|
42
|
+
merged: boolean;
|
|
43
|
+
/** The merge commit, when the forge says. */
|
|
44
|
+
sha?: string;
|
|
45
|
+
/** Why it was not merged. */
|
|
46
|
+
reason?: string;
|
|
47
|
+
/** The refusal was posted on the pull request. */
|
|
48
|
+
posted?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface MergeAfterApplyInput {
|
|
52
|
+
/** The client built from the merge token alone. */
|
|
53
|
+
forge: Pick<PrForge, "kind" | "mergePullRequest" | "pullRequestHead" | "upsertComment">;
|
|
54
|
+
pr: number;
|
|
55
|
+
/** The commit that applied. */
|
|
56
|
+
head: string;
|
|
57
|
+
method?: PrMergeMethod;
|
|
58
|
+
/** Whether the apply's records reached the ledger's remote, and why not. */
|
|
59
|
+
recorded: { pushed: boolean; warning?: string };
|
|
60
|
+
words?: CiProductWords;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const short = (sha: string): string => sha.slice(0, 12);
|
|
64
|
+
|
|
65
|
+
/** Merge the pull request after its update applied. Never throws; a refusal is posted and returned. */
|
|
66
|
+
export async function mergeAfterApply(i: MergeAfterApplyInput): Promise<MergeAfterApply> {
|
|
67
|
+
const words = i.words ?? activeProductWords();
|
|
68
|
+
const what = i.forge.kind === "gitlab" ? `Merge request !${i.pr}` : `Pull request ${i.pr}`;
|
|
69
|
+
const refuse = async (reason: string): Promise<MergeAfterApply> => {
|
|
70
|
+
const body = `${prMergeMarker(i.pr)}\n${what} was not merged: ${reason}. The ${words.verbs.apply[0]} of ${short(i.head)} stays applied and recorded; it is never applied again to merge. Merge it by hand once the reason is gone, or ${words.verbs.apply[0]} again after a new push.\n`;
|
|
71
|
+
try {
|
|
72
|
+
await i.forge.upsertComment(i.pr, prMergeMarker(i.pr), body);
|
|
73
|
+
return { merged: false, reason, posted: true };
|
|
74
|
+
} catch {
|
|
75
|
+
return { merged: false, reason, posted: false };
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
if (!i.recorded.pushed) return refuse(`the ${words.verbs.apply[0]}'s records are not on the ledger's remote${i.recorded.warning ? ` (${i.recorded.warning})` : ""}`);
|
|
79
|
+
try {
|
|
80
|
+
if (i.forge.pullRequestHead) {
|
|
81
|
+
const now = await i.forge.pullRequestHead(i.pr);
|
|
82
|
+
if (!now) return refuse("the forge could not say its head");
|
|
83
|
+
if (!now.open) return refuse("it is no longer open");
|
|
84
|
+
if (now.sha !== i.head) return refuse(`its head is ${short(now.sha)} now, not ${short(i.head)}, the commit that applied`);
|
|
85
|
+
}
|
|
86
|
+
const merged = await i.forge.mergePullRequest(i.pr, { sha: i.head, ...(i.method ? { method: i.method } : {}) });
|
|
87
|
+
if (!merged.merged) return refuse(merged.reason ?? "the forge refused the merge");
|
|
88
|
+
return { merged: true, ...(merged.sha ? { sha: merged.sha } : {}) };
|
|
89
|
+
} catch (err) {
|
|
90
|
+
return refuse(`the forge answered ${err instanceof Error ? err.message : String(err)}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The environment a merge client reads its token from: the job's, with the
|
|
96
|
+
* named variable as the only token and every other forge token left out.
|
|
97
|
+
*/
|
|
98
|
+
export function mergeTokenEnv(tokenEnv: string, env: Record<string, string | undefined> = process.env): Record<string, string | undefined> | { error: string } {
|
|
99
|
+
const token = env[tokenEnv]?.trim();
|
|
100
|
+
if (!token) return { error: `--merge-token-env names ${tokenEnv}, which is not set in this job` };
|
|
101
|
+
const out: Record<string, string | undefined> = { ...env };
|
|
102
|
+
for (const name of ["CHANT_FORGE_TOKEN", "GITHUB_TOKEN", "GH_TOKEN", "GITLAB_TOKEN", "CI_JOB_TOKEN", "FORGEJO_TOKEN", "CHANT_GITHUB_TOKEN", "CHANT_GITLAB_TOKEN", "CHANT_FORGEJO_TOKEN"]) delete out[name];
|
|
103
|
+
out.CHANT_FORGE_TOKEN = token;
|
|
104
|
+
return out;
|
|
105
|
+
}
|