@leitwerk-dev/forgejo-repo-change 0.2.0 → 0.3.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 CHANGED
@@ -398,9 +398,6 @@ var copiedUnknownRecordSchema = pipe(
398
398
  function isUnknownRecord(value) {
399
399
  return typeof value === "object" && value !== null && !Array.isArray(value);
400
400
  }
401
- function asUnknownRecord(value) {
402
- return isUnknownRecord(value) ? value : null;
403
- }
404
401
 
405
402
  // src/launcher.ts
406
403
  import {
@@ -417,7 +414,6 @@ function isIssueOrigin(params) {
417
414
  return params.origin === "issue";
418
415
  }
419
416
  var forgejoRepoChangeParamsCodec = createRepositoryChangeParamsCodec({
420
- displayName: "Forgejo Repo Change",
421
417
  normalize(value) {
422
418
  const shared = normalizeRepositoryChangeParamsInput(value, "Forgejo Repo Change");
423
419
  const record3 = repositoryChangeParamsRecord(value, "Forgejo Repo Change");
@@ -512,7 +508,6 @@ function resolveProfileBinding(bindings, profile) {
512
508
  var forgejoRepoChangeUiLauncherId = "forgejo_repo_change_process.ui_launcher";
513
509
  function forgejoRepoChangeParams(repository, input) {
514
510
  return {
515
- launchKind: "requested_change",
516
511
  repoLocator: repository.ssh_url,
517
512
  baseBranch: repository.default_branch,
518
513
  workBranch: input.workBranch,
@@ -559,7 +554,7 @@ function forgejoRepoChangeLaunchConfig(params, title, gitIdentity) {
559
554
  }
560
555
  function createForgejoRepoChangeLauncher() {
561
556
  let dependencies = null;
562
- function configureForgejoRepoChangeLauncher2(value) {
557
+ function configureForgejoRepoChangeLauncher(value) {
563
558
  dependencies = value;
564
559
  }
565
560
  function requireDependencies() {
@@ -589,7 +584,7 @@ function createForgejoRepoChangeLauncher() {
589
584
  }
590
585
  };
591
586
  }
592
- function forgejoRepositoryPreparationChecks2(_input, { params }) {
587
+ function forgejoRepositoryPreparationChecks(_input, { params }) {
593
588
  return [
594
589
  {
595
590
  id: "repository_visibility",
@@ -629,7 +624,7 @@ function createForgejoRepoChangeLauncher() {
629
624
  throw new Error(`Git SSH profile '${binding.sshCredentialRef}' is not available`);
630
625
  return binding;
631
626
  }
632
- async function resolveForgejoGitIdentity2(profile) {
627
+ async function resolveForgejoGitIdentity(profile) {
633
628
  if (!profile) throw new Error("A Forgejo profile is required to resolve Git identity");
634
629
  return requireDependencies().forgejo.client(profile).resolveGitIdentity(profile);
635
630
  }
@@ -639,7 +634,7 @@ function createForgejoRepoChangeLauncher() {
639
634
  if (!forgejo.profiles().includes(profile)) return [];
640
635
  return forgejo.client(profile).listRepositories();
641
636
  }
642
- const forgejoRepoChangeUiLauncher2 = {
637
+ const forgejoRepoChangeUiLauncher = {
643
638
  id: forgejoRepoChangeUiLauncherId,
644
639
  label: "Forgejo Repo Change",
645
640
  description: "Plan, implement, review, and publish a Forgejo change without a source issue",
@@ -696,7 +691,7 @@ function createForgejoRepoChangeLauncher() {
696
691
  }))
697
692
  };
698
693
  },
699
- preparationChecks: forgejoRepositoryPreparationChecks2,
694
+ preparationChecks: forgejoRepositoryPreparationChecks,
700
695
  resolveRelaunchInput(previousInput) {
701
696
  return {
702
697
  forgejoProfile: trimString(previousInput.forgejoProfile),
@@ -736,7 +731,7 @@ function createForgejoRepoChangeLauncher() {
736
731
  } catch (error) {
737
732
  return invalid("forgejoProfile", error.message);
738
733
  }
739
- const gitIdentity = await resolveForgejoGitIdentity2(profile);
734
+ const gitIdentity = await resolveForgejoGitIdentity(profile);
740
735
  const workBranch = buildAutoWorkBranchFromSeed(
741
736
  prompt,
742
737
  `${repository.ssh_url}:${repository.default_branch}`
@@ -755,28 +750,30 @@ function createForgejoRepoChangeLauncher() {
755
750
  }
756
751
  };
757
752
  return {
758
- configure: configureForgejoRepoChangeLauncher2,
759
- preparationChecks: forgejoRepositoryPreparationChecks2,
753
+ /** @internal */
754
+ configure: configureForgejoRepoChangeLauncher,
755
+ /** @internal */
756
+ preparationChecks: forgejoRepositoryPreparationChecks,
757
+ /** @internal */
760
758
  resolveProfiles,
761
- resolveGitIdentity: resolveForgejoGitIdentity2,
762
- launcher: forgejoRepoChangeUiLauncher2
759
+ /** @internal */
760
+ resolveGitIdentity: resolveForgejoGitIdentity,
761
+ /** @internal */
762
+ launcher: forgejoRepoChangeUiLauncher
763
763
  };
764
764
  }
765
765
 
766
766
  // src/process.ts
767
767
  import { createRepositoryChangeProcess } from "@leitwerk-dev/coding";
768
- import { commitAndPushWorkBranch } from "@leitwerk-dev/coding/finalization-git";
768
+ import {
769
+ createRepositoryChangePublication,
770
+ publicationObject as object2,
771
+ readPublicationState
772
+ } from "@leitwerk-dev/coding/repository-change-publication";
769
773
  import {
770
774
  forgejoExternal,
771
775
  forgejoIssueWatcherSource
772
776
  } from "@leitwerk-dev/forgejo";
773
- import { flow } from "@leitwerk-dev/process-sdk";
774
- import {
775
- conflictKey,
776
- validateConflict
777
- } from "@leitwerk-dev/repository-rebase";
778
- import { publishRebase, startRebase } from "@leitwerk-dev/repository-rebase/git";
779
- import { rebasePrompt } from "@leitwerk-dev/repository-rebase/prompt";
780
777
  import { woodpeckerExternal } from "@leitwerk-dev/woodpecker";
781
778
  var processId = "forgejo_repo_change_process";
782
779
  var ids = {
@@ -785,61 +782,15 @@ var ids = {
785
782
  ciRepair: "repair_woodpecker_pipeline",
786
783
  operator: "ci_operator_action"
787
784
  };
788
- var initialDeliveryState = {
789
- stage: "not_started",
790
- issueLinked: false,
791
- adjustment: null,
792
- terminalPullRequest: null
793
- };
794
- var initialRemoteState = {
795
- headSha: null,
796
- prNumber: null,
797
- prUrl: null,
798
- conversationCursor: 0,
799
- reviewCursor: 0,
800
- inlineCursor: 0,
801
- feedbackIds: [],
802
- pipeline: null,
803
- ciRecoveryCycles: 0,
804
- delivery: initialDeliveryState
805
- };
806
- var object2 = (value) => asUnknownRecord(value) ?? {};
807
- function remote(state) {
808
- const stored = object2(object2(state.extensionState).forgejoRepoChange);
809
- return {
810
- ...initialRemoteState,
811
- ...stored,
812
- delivery: {
813
- ...initialDeliveryState,
814
- ...object2(stored.delivery)
815
- }
816
- };
817
- }
818
- function patchRemote(state, patch) {
819
- const current = remote(state);
820
- return {
821
- ...state,
822
- extensionState: {
823
- ...state.extensionState,
824
- forgejoRepoChange: {
825
- ...current,
826
- ...patch,
827
- delivery: { ...current.delivery, ...patch.delivery }
828
- }
829
- }
830
- };
831
- }
785
+ var remote = (state) => readPublicationState(state, "forgejoRepoChange");
832
786
  function requirePr(state) {
833
787
  const value = remote(state);
834
- const { headSha, prNumber, prUrl } = value;
835
- if (!headSha || !prNumber || !prUrl) {
788
+ if (!value.headSha || !value.prNumber || !value.prUrl)
836
789
  throw new Error("Pull request delivery state is incomplete");
837
- }
838
- return { ...value, headSha, prNumber, prUrl };
839
- }
840
- function feedbackKey(value) {
841
- return `${value.kind}:${value.id}`;
790
+ return { ...value, headSha: value.headSha, prNumber: value.prNumber, prUrl: value.prUrl };
842
791
  }
792
+ var feedbackKey = (value) => `${value.kind}:${value.id}`;
793
+ var callFor = (ctx) => (name, args) => ctx.callIntegrationTool(name, { projectKey: "repo", ...args });
843
794
  function requireIssueOrigin(params) {
844
795
  if (!isIssueOrigin(params)) throw new Error("Forgejo source issue metadata is unavailable");
845
796
  return params;
@@ -853,57 +804,6 @@ function pinnedGitIdentity(ctx) {
853
804
  }
854
805
  return identity;
855
806
  }
856
- async function commitWorkBranch(ctx, commitMessage) {
857
- const repo = ctx.repo.get("repo");
858
- const gitIdentity = pinnedGitIdentity(ctx) ?? await ctx.callIntegrationTool("forgejo_resolve_git_identity", {
859
- projectKey: "repo"
860
- });
861
- return commitAndPushWorkBranch({
862
- repoPath: repo.fsPath,
863
- workBranch: repo.workBranch,
864
- commitMessage,
865
- gitIdentity
866
- });
867
- }
868
- function deliveryProgress(value, activeStepId) {
869
- const delivery = value.delivery;
870
- const step = (id, label, done) => ({
871
- id,
872
- label,
873
- status: activeStepId === id ? "in_progress" : done ? "completed" : "incomplete"
874
- });
875
- const adjustmentHandled = delivery.adjustment === null && delivery.stage === "awaiting" && value.headSha !== null;
876
- return {
877
- title: "Delivery progress",
878
- steps: [
879
- step("publish_branch", "Publish work branch", value.headSha !== null),
880
- step("open_pr", "Create or find pull request", value.prNumber !== null),
881
- step("link_issue", "Link source issue when applicable", delivery.issueLinked),
882
- step("publish_adjustment", "Publish an adjustment when applicable", adjustmentHandled),
883
- step(
884
- "reply_feedback",
885
- "Acknowledge or reply to feedback when applicable",
886
- value.feedbackIds.length === 0
887
- ),
888
- step("await_evidence", "Await external evidence", delivery.stage === "awaiting"),
889
- step(
890
- "reconcile_terminal",
891
- "Reconcile terminal pull request",
892
- delivery.terminalPullRequest !== null
893
- )
894
- ],
895
- ...value.prNumber && value.prUrl ? {
896
- links: [
897
- {
898
- id: `forgejo-pr-${value.prNumber}`,
899
- label: `Forgejo PR #${value.prNumber}`,
900
- url: value.prUrl,
901
- kind: "pull_request"
902
- }
903
- ]
904
- } : {}
905
- };
906
- }
907
807
  var deliveryTools = [
908
808
  "forgejo_get_pull_request",
909
809
  "forgejo_add_pull_request_comment",
@@ -917,9 +817,6 @@ var deliveryTools = [
917
817
  "forgejo_update_issue"
918
818
  ];
919
819
  function createForgejoRepoChangeProcess(launcher, docker) {
920
- const publication = flow.fragment(
921
- "forgejo-publication"
922
- );
923
820
  const failedPipeline = woodpeckerExternal.pipeline(({ params, state }) => {
924
821
  const current = requirePr(state);
925
822
  return {
@@ -933,20 +830,123 @@ function createForgejoRepoChangeProcess(launcher, docker) {
933
830
  pollInterval: "30s"
934
831
  };
935
832
  });
936
- const delivery = flow.automatic(ids.deliver).description("Deliver").integrationTools(...deliveryTools).run(async (ctx) => {
937
- const call = (name, args) => ctx.callIntegrationTool(name, { projectKey: "repo", ...args });
938
- let current = remote(ctx.state);
939
- const update = (patch) => {
940
- current = { ...current, ...patch, delivery: { ...current.delivery, ...patch.delivery } };
941
- };
942
- const result = (outcome) => ({
943
- outcome,
944
- params: { nextState: patchRemote(ctx.state, current) }
945
- });
946
- ctx.reportProgress(deliveryProgress(current));
947
- if (current.delivery.terminalPullRequest) {
948
- ctx.reportProgress(deliveryProgress(current, "reconcile_terminal"));
949
- const pr = current.delivery.terminalPullRequest;
833
+ const sources = [
834
+ {
835
+ id: "forgejo_merge_conflict",
836
+ kind: "conflict",
837
+ label: "Rebase conflicting pull request",
838
+ source: forgejoExternal.pullRequestConflict(({ params, state }) => ({
839
+ profile: params.forgejoProfile,
840
+ owner: params.owner,
841
+ repo: params.repo,
842
+ prNumber: requirePr(state).prNumber,
843
+ headSha: requirePr(state).headSha,
844
+ lastConflictKey: remote(state).lastConflictKey,
845
+ pollInterval: "30s"
846
+ })),
847
+ read: ({ event }) => ({
848
+ kind: "conflict",
849
+ conflict: object2(event).conflict
850
+ })
851
+ },
852
+ {
853
+ id: "forgejo_feedback",
854
+ kind: "feedback",
855
+ label: "Forgejo pull request feedback",
856
+ source: forgejoExternal.pullRequestFeedback(({ params, state }) => ({
857
+ profile: params.forgejoProfile,
858
+ owner: params.owner,
859
+ repo: params.repo,
860
+ prNumber: requirePr(state).prNumber,
861
+ conversationCursor: remote(state).conversationCursor,
862
+ reviewCursor: remote(state).reviewCursor,
863
+ inlineCursor: remote(state).inlineCursor,
864
+ quietPeriodMs: 12e4,
865
+ pollInterval: "30s"
866
+ })),
867
+ read: ({ state, event }) => {
868
+ const value = object2(event);
869
+ const cursors = object2(value.cursors);
870
+ const current = remote(state);
871
+ return {
872
+ kind: "feedback",
873
+ conversationCursor: Number(cursors.conversationCursor ?? current.conversationCursor),
874
+ reviewCursor: Number(cursors.reviewCursor ?? current.reviewCursor),
875
+ inlineCursor: Number(cursors.inlineCursor ?? current.inlineCursor),
876
+ feedbackIds: value.feedbackIds ?? []
877
+ };
878
+ }
879
+ },
880
+ {
881
+ id: "woodpecker_failure_repair",
882
+ operatorId: "woodpecker_failure_operator",
883
+ kind: "failure",
884
+ label: "Repair failed Woodpecker pipeline",
885
+ source: failedPipeline,
886
+ read: ({ event }) => ({
887
+ kind: "failure",
888
+ pipeline: object2(event).pipeline
889
+ })
890
+ },
891
+ ...["merged", "closed"].map((terminalOutcome) => ({
892
+ id: `forgejo_pr_${terminalOutcome}`,
893
+ kind: "terminal",
894
+ label: `Forgejo pull request ${terminalOutcome}`,
895
+ source: forgejoExternal.pullRequestTerminal(
896
+ ({ params, state }) => ({
897
+ profile: params.forgejoProfile,
898
+ owner: params.owner,
899
+ repo: params.repo,
900
+ prNumber: requirePr(state).prNumber,
901
+ terminalOutcome,
902
+ pollInterval: "30s"
903
+ })
904
+ ),
905
+ read: ({ event }) => ({
906
+ kind: "terminal",
907
+ request: object2(event).pullRequest
908
+ })
909
+ })),
910
+ {
911
+ id: "source_cancelled",
912
+ kind: "cancelled",
913
+ label: "Source issue cancelled",
914
+ enabled: isIssueOrigin,
915
+ source: forgejoExternal.issueCancelled(({ params }) => {
916
+ const issue = requireIssueOrigin(params);
917
+ return {
918
+ profile: issue.forgejoProfile,
919
+ owner: issue.owner,
920
+ repo: issue.repo,
921
+ issueNumber: issue.issueNumber,
922
+ triggerLabel: issue.triggerLabel,
923
+ pollInterval: "30s"
924
+ };
925
+ }),
926
+ read: () => ({ kind: "cancelled" })
927
+ }
928
+ ];
929
+ const publicationConfig = createRepositoryChangePublication({
930
+ namespace: "forgejoRepoChange",
931
+ label: "Forgejo PR",
932
+ ids,
933
+ sources,
934
+ tools: {
935
+ delivery: deliveryTools,
936
+ feedback: ["forgejo_get_pull_request", "forgejo_list_pull_request_feedback"],
937
+ ci: [
938
+ "woodpecker_lookup_repository",
939
+ "woodpecker_list_pipelines",
940
+ "woodpecker_get_pipeline",
941
+ "woodpecker_get_step_logs",
942
+ "woodpecker_restart_pipeline"
943
+ ]
944
+ },
945
+ async identity(ctx) {
946
+ return pinnedGitIdentity(ctx) ?? await callFor(ctx)("forgejo_resolve_git_identity", {});
947
+ },
948
+ async reconcileTerminal(ctx, _current, pr) {
949
+ const call = callFor(ctx);
950
950
  if (isIssueOrigin(ctx.params)) {
951
951
  const issue = await call("forgejo_get_issue", {
952
952
  issueNumber: ctx.params.issueNumber
@@ -969,19 +969,9 @@ function createForgejoRepoChangeProcess(launcher, docker) {
969
969
  writeKey: `forgejo:${ctx.process.id}:${pr.merged ? "merged" : "closed"}-pr-comment`
970
970
  });
971
971
  }
972
- ctx.reportProgress(deliveryProgress(current));
973
- return result(pr.merged ? "completed" : "aborted");
974
- }
975
- if (!current.headSha) {
976
- ctx.reportProgress(deliveryProgress(current, "publish_branch"));
977
- const published = await commitWorkBranch(
978
- ctx,
979
- ctx.state.finalization.generatedCommitMessage ?? ""
980
- );
981
- update({ headSha: published.headSha, pipeline: null });
982
- }
983
- if (!current.prNumber || !current.prUrl) {
984
- ctx.reportProgress(deliveryProgress(current, "open_pr"));
972
+ },
973
+ async ensureRequest(ctx) {
974
+ const call = callFor(ctx);
985
975
  const project = ctx.repo.get("repo");
986
976
  const issueOrigin = isIssueOrigin(ctx.params);
987
977
  const pr = await call("forgejo_ensure_pull_request", {
@@ -993,10 +983,10 @@ Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
993
983
  base: project.baseBranch
994
984
  });
995
985
  if (!pr) throw new Error("Forgejo pull request could not be created or found");
996
- update({ prNumber: pr.number, prUrl: pr.html_url });
997
- }
998
- if (!current.delivery.issueLinked) {
999
- ctx.reportProgress(deliveryProgress(current, "link_issue"));
986
+ return pr;
987
+ },
988
+ async linkIssue(ctx, current) {
989
+ const call = callFor(ctx);
1000
990
  if (isIssueOrigin(ctx.params)) {
1001
991
  await call("forgejo_add_issue_comment", {
1002
992
  issueNumber: ctx.params.issueNumber,
@@ -1004,50 +994,21 @@ Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
1004
994
  writeKey: `forgejo:${ctx.process.id}:source-pr-link:${current.prNumber}`
1005
995
  });
1006
996
  }
1007
- update({ delivery: { issueLinked: true } });
1008
- }
1009
- if (current.delivery.adjustment) {
1010
- const adjustment = current.delivery.adjustment;
1011
- if (adjustment.publishRequired || adjustment.origin === "rebase") {
1012
- ctx.reportProgress(deliveryProgress(current, "publish_adjustment"));
1013
- const published = adjustment.origin === "rebase" ? publishRebase(rebaseInput(ctx)) : await commitWorkBranch(
1014
- ctx,
1015
- adjustment.origin === "feedback" ? "fix: address Forgejo review feedback" : "fix: repair Woodpecker pipeline"
1016
- );
1017
- if (adjustment.origin === "rebase") {
1018
- const refreshed = await call("forgejo_get_pull_request", {
1019
- pullRequestNumber: current.prNumber
1020
- });
1021
- if (refreshed.head.sha !== published.headSha)
1022
- throw new Error("Pull request head has not caught up with rebase publication");
1023
- }
1024
- update({ headSha: published.headSha, pipeline: null });
1025
- }
1026
- if (adjustment.origin === "rebase")
1027
- await call("forgejo_add_pull_request_comment", {
997
+ },
998
+ async reply(ctx, current) {
999
+ const call = callFor(ctx);
1000
+ for (const feedback of current.feedbackIds) {
1001
+ await call("forgejo_reply_to_pull_request_feedback", {
1028
1002
  pullRequestNumber: current.prNumber,
1029
- body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
1030
- writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`
1003
+ feedbackKind: feedback.kind,
1004
+ feedbackId: feedback.id,
1005
+ body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
1006
+ writeKey: `forgejo:${ctx.process.id}:feedback-reply:${feedbackKey(feedback)}:${current.headSha}`
1031
1007
  });
1032
- if (adjustment.origin === "feedback") {
1033
- ctx.reportProgress(deliveryProgress(current, "reply_feedback"));
1034
- for (const feedback of current.feedbackIds) {
1035
- await call("forgejo_reply_to_pull_request_feedback", {
1036
- pullRequestNumber: current.prNumber,
1037
- feedbackKind: feedback.kind,
1038
- feedbackId: feedback.id,
1039
- body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
1040
- writeKey: `forgejo:${ctx.process.id}:feedback-reply:${feedbackKey(feedback)}:${current.headSha}`
1041
- });
1042
- }
1043
1008
  }
1044
- update({
1045
- ...adjustment.origin === "feedback" ? { feedbackIds: [] } : {},
1046
- delivery: { adjustment: null }
1047
- });
1048
- }
1049
- if (current.feedbackIds.length > 0) {
1050
- ctx.reportProgress(deliveryProgress(current, "reply_feedback"));
1009
+ },
1010
+ async acknowledge(ctx, current) {
1011
+ const call = callFor(ctx);
1051
1012
  for (const feedback of current.feedbackIds) {
1052
1013
  if (feedback.kind === "review") continue;
1053
1014
  await call("forgejo_add_pull_request_feedback_reaction", {
@@ -1057,222 +1018,25 @@ Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
1057
1018
  writeKey: `forgejo:${ctx.process.id}:feedback-eyes:${feedbackKey(feedback)}`
1058
1019
  });
1059
1020
  }
1060
- return result("feedback_ready");
1061
- }
1062
- update({ delivery: { stage: "awaiting" } });
1063
- ctx.reportProgress(deliveryProgress(current, "await_evidence"));
1064
- return result("awaiting");
1065
- }).outcome(
1066
- "awaiting",
1067
- (outcome) => outcome.description("Delivery is waiting for external evidence").object("nextState").wait().state(({ event }) => event.params.nextState)
1068
- ).outcome(
1069
- "feedback_ready",
1070
- (outcome) => outcome.description("Pull request feedback is acknowledged and ready for revision").object("nextState").to(ids.feedback).state(({ event }) => event.params.nextState)
1071
- ).outcome(
1072
- "completed",
1073
- (outcome) => outcome.description("Merged pull request was reconciled").object("nextState").complete().state(({ event }) => event.params.nextState)
1074
- ).outcome(
1075
- "aborted",
1076
- (outcome) => outcome.description("Closed pull request was reconciled").object("nextState").lifecycleStatus("aborted").state(({ event }) => event.params.nextState)
1077
- ).externalAction(
1078
- "forgejo_merge_conflict",
1079
- forgejoExternal.pullRequestConflict(({ params, state }) => ({
1080
- profile: params.forgejoProfile,
1081
- owner: params.owner,
1082
- repo: params.repo,
1083
- prNumber: requirePr(state).prNumber,
1084
- headSha: requirePr(state).headSha,
1085
- lastConflictKey: remote(state).lastConflictKey,
1086
- pollInterval: "30s"
1087
- })),
1088
- (external) => external.label("Rebase conflicting pull request").to(ids.feedback).effect(({ params, state, event }) => {
1089
- const current = requirePr(state);
1090
- const conflict = validateConflict(
1091
- object2(event).conflict,
1092
- {
1093
- owner: params.owner,
1094
- repo: params.repo,
1095
- prNumber: current.prNumber,
1096
- headSha: current.headSha,
1097
- headBranch: params.workBranch,
1098
- baseBranch: params.baseBranch
1099
- },
1100
- current.lastConflictKey
1101
- );
1102
- return {
1103
- state: patchRemote(state, {
1104
- lastConflictKey: conflictKey(conflict),
1105
- conflict,
1106
- repairReason: "rebase"
1107
- })
1108
- };
1109
- })
1110
- ).externalAction(
1111
- "forgejo_feedback",
1112
- forgejoExternal.pullRequestFeedback(({ params, state }) => {
1113
- const current = requirePr(state);
1114
- return {
1115
- profile: params.forgejoProfile,
1116
- owner: params.owner,
1117
- repo: params.repo,
1118
- prNumber: current.prNumber,
1119
- conversationCursor: current.conversationCursor,
1120
- reviewCursor: current.reviewCursor,
1121
- inlineCursor: current.inlineCursor,
1122
- quietPeriodMs: 12e4,
1123
- pollInterval: "30s"
1124
- };
1125
- }),
1126
- (external) => external.label("Forgejo pull request feedback").to(ids.deliver).effect(({ state, event }) => {
1127
- const value = object2(event);
1128
- const cursors = object2(value.cursors);
1129
- return {
1130
- state: patchRemote(state, {
1131
- repairReason: "feedback",
1132
- conversationCursor: Number(
1133
- cursors.conversationCursor ?? remote(state).conversationCursor
1134
- ),
1135
- reviewCursor: Number(cursors.reviewCursor ?? remote(state).reviewCursor),
1136
- inlineCursor: Number(cursors.inlineCursor ?? remote(state).inlineCursor),
1137
- feedbackIds: Array.isArray(value.feedbackIds) ? value.feedbackIds : []
1138
- })
1139
- };
1140
- })
1141
- ).externalAction(
1142
- "woodpecker_failure_repair",
1143
- failedPipeline,
1144
- (external) => external.label("Repair failed Woodpecker pipeline").when(({ state }) => remote(state).ciRecoveryCycles < 3).to(ids.ciRepair).effect(({ state, event }) => ({
1145
- state: patchRemote(state, {
1146
- repairReason: "ci",
1147
- pipeline: object2(event).pipeline,
1148
- ciRecoveryCycles: remote(state).ciRecoveryCycles + 1
1149
- })
1150
- }))
1151
- ).externalAction(
1152
- "woodpecker_failure_operator",
1153
- failedPipeline,
1154
- (external) => external.label("Escalate failed Woodpecker pipeline").when(({ state }) => remote(state).ciRecoveryCycles >= 3).to(ids.operator).effect(({ state, event }) => ({
1155
- state: patchRemote(state, {
1156
- repairReason: "ci",
1157
- pipeline: object2(event).pipeline
1158
- })
1159
- }))
1160
- );
1161
- for (const [terminalOutcome, label] of [
1162
- ["merged", "Forgejo pull request merged"],
1163
- ["closed", "Forgejo pull request closed without merge"]
1164
- ]) {
1165
- delivery.externalAction(
1166
- `forgejo_pr_${terminalOutcome}`,
1167
- forgejoExternal.pullRequestTerminal(({ params, state }) => ({
1168
- profile: params.forgejoProfile,
1169
- owner: params.owner,
1170
- repo: params.repo,
1171
- prNumber: requirePr(state).prNumber,
1172
- terminalOutcome,
1173
- pollInterval: "30s"
1174
- })),
1175
- (external) => external.label(label).to(ids.deliver).effect(({ state, event }) => ({
1176
- state: patchRemote(state, {
1177
- delivery: { terminalPullRequest: object2(event).pullRequest }
1178
- })
1179
- }))
1180
- );
1181
- }
1182
- publication.turn(
1183
- delivery.externalAction(
1184
- "source_cancelled",
1185
- forgejoExternal.issueCancelled(({ params }) => {
1186
- const issue = requireIssueOrigin(params);
1187
- return {
1188
- profile: issue.forgejoProfile,
1189
- owner: issue.owner,
1190
- repo: issue.repo,
1191
- issueNumber: issue.issueNumber,
1192
- triggerLabel: issue.triggerLabel,
1193
- pollInterval: "30s"
1194
- };
1195
- }),
1196
- (external) => external.label("Source issue cancelled").when(({ params }) => isIssueOrigin(params)).lifecycleStatus("aborted")
1197
- )
1198
- );
1199
- function rebaseInput(ctx) {
1200
- const project = ctx.repo.get("repo");
1201
- const conflict = remote(ctx.state).conflict;
1202
- if (!conflict) throw new Error("Missing conflict evidence");
1203
- return { projectKey: "repo", path: project.fsPath, workBranch: project.workBranch, conflict };
1204
- }
1205
- function repairReason(state, kind) {
1206
- return kind === "feedback" && remote(state).repairReason === "rebase" ? "rebase" : kind;
1207
- }
1208
- function revisionPrompt(kind) {
1209
- return (ctx) => {
1210
- const current = remote(ctx.state);
1211
- if (repairReason(ctx.state, kind) === "rebase")
1212
- return `${rebasePrompt} Evidence: ${JSON.stringify(current.conflict)}. Call changes_ready or no_changes when verified complete, cannot_repair when blocked.`;
1021
+ },
1022
+ async head(ctx, current) {
1023
+ return (await callFor(ctx)("forgejo_get_pull_request", {
1024
+ pullRequestNumber: current.prNumber
1025
+ })).head.sha;
1026
+ },
1027
+ async afterRebase(ctx, current) {
1028
+ await callFor(ctx)("forgejo_add_pull_request_comment", {
1029
+ pullRequestNumber: current.prNumber,
1030
+ body: `Merge conflict repair completed at ${current.headSha}; base ${current.conflict?.baseSha}.`,
1031
+ writeKey: `rebase:${ctx.process.id}:${current.lastConflictKey}:${current.headSha}`
1032
+ });
1033
+ },
1034
+ commitMessage: (kind) => kind === "feedback" ? "fix: address Forgejo review feedback" : "fix: repair Woodpecker pipeline",
1035
+ prompt(kind, current) {
1213
1036
  return kind === "feedback" ? `Address the unseen Forgejo pull-request feedback batch for PR #${current.prNumber}. Feedback identifiers: ${JSON.stringify(current.feedbackIds)}. Inspect the current checkout and use Forgejo tools to read the full feedback. Do not rely on an earlier plan or conversation. Make only justified repository changes. Call changes_ready if files need publishing, no_changes after an explicit diagnosis that no repository change is needed, or cannot_repair when operator action is required.` : `Diagnose Woodpecker pipeline #${current.pipeline?.number ?? "unknown"} (${current.pipeline?.status ?? "unknown"}) for the current checkout. Use Woodpecker tools to inspect pipeline metadata and bounded failed-step logs before changing anything. Fix repository causes. Call changes_ready for repository changes, no_changes only after an explicit provider restart or a justified diagnosis that no repository change is needed, or cannot_repair when operator action is required.`;
1214
- };
1215
- }
1216
- function revisionTurn(id, kind) {
1217
- const turn = flow.llm(id).description(kind === "feedback" ? "Address Feedback" : "Fix CI").tools("read", "bash", "edit", "write").resolveIntegrationTools(
1218
- (_params, state) => repairReason(state, kind) === "rebase" ? [] : kind === "feedback" ? ["forgejo_get_pull_request", "forgejo_list_pull_request_feedback"] : [
1219
- "woodpecker_lookup_repository",
1220
- "woodpecker_list_pipelines",
1221
- "woodpecker_get_pipeline",
1222
- "woodpecker_get_step_logs",
1223
- "woodpecker_restart_pipeline"
1224
- ]
1225
- ).prepare(
1226
- (ctx) => repairReason(ctx.state, kind) === "rebase" ? startRebase(rebaseInput(ctx)) : {}
1227
- ).freshPrimary().prompt(revisionPrompt(kind));
1228
- for (const [name, description, publishRequired] of [
1229
- ["changes_ready", "Repository changes are ready to publish", true],
1230
- ["no_changes", "No repository change is required", false]
1231
- ]) {
1232
- turn.outcomeTool(
1233
- name,
1234
- (tool) => tool.resultSummary().description(description).to(ids.deliver).state(
1235
- ({ ctx }) => patchRemote(ctx.state, {
1236
- delivery: { adjustment: { origin: repairReason(ctx.state, kind), publishRequired } }
1237
- })
1238
- )
1239
- );
1240
- }
1241
- return turn.outcomeTool(
1242
- "cannot_repair",
1243
- (tool) => tool.description("The adjustment requires operator action").to(ids.operator)
1244
- );
1245
- }
1246
- publication.turn(revisionTurn(ids.feedback, "feedback"));
1247
- publication.turn(revisionTurn(ids.ciRepair, "ci"));
1248
- publication.turn({
1249
- id: ids.operator,
1250
- definition: {
1251
- kind: "human",
1252
- description: "Repository repair needs operator action",
1253
- operatorAttention: "required",
1254
- actions: {
1255
- retry_repair: {
1256
- label: "Retry repair",
1257
- acceptanceState: "accepted",
1258
- branches: { feedback: { to: ids.feedback }, ci: { to: ids.ciRepair } },
1259
- choose: ({ ctx }) => remote(ctx.state).repairReason === "rebase" || remote(ctx.state).repairReason === "feedback" ? "feedback" : "ci"
1260
- },
1261
- resume_waiting: {
1262
- label: "Resume waiting",
1263
- acceptanceState: "accepted",
1264
- to: ids.deliver,
1265
- effect: ({ ctx }) => ({
1266
- state: patchRemote(ctx.state, {
1267
- feedbackIds: [],
1268
- delivery: { adjustment: null }
1269
- })
1270
- })
1271
- },
1272
- abort: { label: "Abort process", acceptanceState: "neutral", lifecycleStatus: "aborted" }
1273
- }
1274
1037
  }
1275
1038
  });
1039
+ const publication = publicationConfig.fragment;
1276
1040
  publication.watcher({
1277
1041
  id: "use_leitwerk",
1278
1042
  label: "Forgejo use-leitwerk issues",
@@ -1316,7 +1080,6 @@ ${body}` : ""}`
1316
1080
  fields: [],
1317
1081
  submitLabel: "Publish"
1318
1082
  },
1319
- finalizationDescription: "Publish feature branch",
1320
1083
  repositoryCredentials: ({ params }) => [
1321
1084
  {
1322
1085
  projectKey: "repo",
@@ -1324,11 +1087,7 @@ ${body}` : ""}`
1324
1087
  credentialRef: params.sshCredentialRef
1325
1088
  }
1326
1089
  ],
1327
- publication: {
1328
- entryTurnId: ids.deliver,
1329
- fragment: publication,
1330
- happyPath: [ids.deliver]
1331
- }
1090
+ publication: publicationConfig
1332
1091
  });
1333
1092
  definition.process.runtime = { ...definition.process.runtime, docker };
1334
1093
  return definition.process;
@@ -1336,8 +1095,11 @@ ${body}` : ""}`
1336
1095
 
1337
1096
  // src/index.ts
1338
1097
  var manifest = {
1098
+ /** @internal */
1339
1099
  id: "forgejo-repo-change",
1100
+ /** @internal */
1340
1101
  version: "0.1.9",
1102
+ /** @internal */
1341
1103
  requires: ["forgejo", "woodpecker", "coding", "git-ssh"]
1342
1104
  };
1343
1105
  function createForgejoRepoChange(options) {
@@ -1364,39 +1126,21 @@ function createForgejoRepoChange(options) {
1364
1126
  api.onStop(() => launcher.configure(null));
1365
1127
  }
1366
1128
  };
1367
- return { extension, process, launcher };
1129
+ return {
1130
+ /** @public */
1131
+ extension,
1132
+ /** @public */
1133
+ process,
1134
+ /** @internal */
1135
+ launcher
1136
+ };
1368
1137
  }
1369
- var {
1370
- extension: defaultExtension,
1371
- process: forgejoRepoChangeProcess,
1372
- launcher: defaultForgejoRepoChangeLauncher
1373
- } = createForgejoRepoChange({ docker: true });
1374
- var {
1375
- configure: configureForgejoRepoChangeLauncher,
1376
- preparationChecks: forgejoRepositoryPreparationChecks,
1377
- resolveGitIdentity: resolveForgejoGitIdentity,
1378
- launcher: forgejoRepoChangeUiLauncher
1379
- } = defaultForgejoRepoChangeLauncher;
1138
+ var { extension: defaultExtension } = createForgejoRepoChange({ docker: true });
1380
1139
  var index_default = defaultExtension;
1381
1140
  export {
1382
- configureForgejoRepoChangeLauncher,
1383
1141
  createForgejoRepoChange,
1384
- createForgejoRepoChangeLauncher,
1385
- createForgejoRepoChangeProcess,
1386
1142
  index_default as default,
1387
- defaultExtension,
1388
- defaultForgejoRepoChangeLauncher,
1389
1143
  forgejoRepoChangeLaunchConfig,
1390
- forgejoRepoChangeParams,
1391
- forgejoRepoChangeParamsCodec,
1392
- forgejoRepoChangeProcess,
1393
- forgejoRepoChangeUiLauncher,
1394
- forgejoRepoChangeUiLauncherId,
1395
- forgejoRepositoryPreparationChecks,
1396
- isIssueOrigin,
1397
- manifest,
1398
- parseProfileBindings,
1399
- resolveForgejoGitIdentity,
1400
- resolveProfileBinding
1144
+ forgejoRepoChangeParams
1401
1145
  };
1402
1146
  //# sourceMappingURL=index.js.map