@leitwerk-dev/forgejo-repo-change 0.2.1 → 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/README.md +5 -18
- package/dist/index.js +163 -409
- package/dist/index.js.map +1 -1
- package/dist/launcher.d.ts.map +1 -1
- package/dist/params.d.ts.map +1 -1
- package/dist/process.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/launcher.ts +0 -1
- package/src/params.ts +0 -1
- package/src/process.ts +214 -581
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,
|
|
@@ -770,18 +765,15 @@ function createForgejoRepoChangeLauncher() {
|
|
|
770
765
|
|
|
771
766
|
// src/process.ts
|
|
772
767
|
import { createRepositoryChangeProcess } from "@leitwerk-dev/coding";
|
|
773
|
-
import {
|
|
768
|
+
import {
|
|
769
|
+
createRepositoryChangePublication,
|
|
770
|
+
publicationObject as object2,
|
|
771
|
+
readPublicationState
|
|
772
|
+
} from "@leitwerk-dev/coding/repository-change-publication";
|
|
774
773
|
import {
|
|
775
774
|
forgejoExternal,
|
|
776
775
|
forgejoIssueWatcherSource
|
|
777
776
|
} from "@leitwerk-dev/forgejo";
|
|
778
|
-
import { flow } from "@leitwerk-dev/process-sdk";
|
|
779
|
-
import {
|
|
780
|
-
conflictKey,
|
|
781
|
-
validateConflict
|
|
782
|
-
} from "@leitwerk-dev/repository-rebase";
|
|
783
|
-
import { publishRebase, startRebase } from "@leitwerk-dev/repository-rebase/git";
|
|
784
|
-
import { rebasePrompt } from "@leitwerk-dev/repository-rebase/prompt";
|
|
785
777
|
import { woodpeckerExternal } from "@leitwerk-dev/woodpecker";
|
|
786
778
|
var processId = "forgejo_repo_change_process";
|
|
787
779
|
var ids = {
|
|
@@ -790,61 +782,15 @@ var ids = {
|
|
|
790
782
|
ciRepair: "repair_woodpecker_pipeline",
|
|
791
783
|
operator: "ci_operator_action"
|
|
792
784
|
};
|
|
793
|
-
var
|
|
794
|
-
stage: "not_started",
|
|
795
|
-
issueLinked: false,
|
|
796
|
-
adjustment: null,
|
|
797
|
-
terminalPullRequest: null
|
|
798
|
-
};
|
|
799
|
-
var initialRemoteState = {
|
|
800
|
-
headSha: null,
|
|
801
|
-
prNumber: null,
|
|
802
|
-
prUrl: null,
|
|
803
|
-
conversationCursor: 0,
|
|
804
|
-
reviewCursor: 0,
|
|
805
|
-
inlineCursor: 0,
|
|
806
|
-
feedbackIds: [],
|
|
807
|
-
pipeline: null,
|
|
808
|
-
ciRecoveryCycles: 0,
|
|
809
|
-
delivery: initialDeliveryState
|
|
810
|
-
};
|
|
811
|
-
var object2 = (value) => asUnknownRecord(value) ?? {};
|
|
812
|
-
function remote(state) {
|
|
813
|
-
const stored = object2(object2(state.extensionState).forgejoRepoChange);
|
|
814
|
-
return {
|
|
815
|
-
...initialRemoteState,
|
|
816
|
-
...stored,
|
|
817
|
-
delivery: {
|
|
818
|
-
...initialDeliveryState,
|
|
819
|
-
...object2(stored.delivery)
|
|
820
|
-
}
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
function patchRemote(state, patch) {
|
|
824
|
-
const current = remote(state);
|
|
825
|
-
return {
|
|
826
|
-
...state,
|
|
827
|
-
extensionState: {
|
|
828
|
-
...state.extensionState,
|
|
829
|
-
forgejoRepoChange: {
|
|
830
|
-
...current,
|
|
831
|
-
...patch,
|
|
832
|
-
delivery: { ...current.delivery, ...patch.delivery }
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
}
|
|
785
|
+
var remote = (state) => readPublicationState(state, "forgejoRepoChange");
|
|
837
786
|
function requirePr(state) {
|
|
838
787
|
const value = remote(state);
|
|
839
|
-
|
|
840
|
-
if (!headSha || !prNumber || !prUrl) {
|
|
788
|
+
if (!value.headSha || !value.prNumber || !value.prUrl)
|
|
841
789
|
throw new Error("Pull request delivery state is incomplete");
|
|
842
|
-
}
|
|
843
|
-
return { ...value, headSha, prNumber, prUrl };
|
|
844
|
-
}
|
|
845
|
-
function feedbackKey(value) {
|
|
846
|
-
return `${value.kind}:${value.id}`;
|
|
790
|
+
return { ...value, headSha: value.headSha, prNumber: value.prNumber, prUrl: value.prUrl };
|
|
847
791
|
}
|
|
792
|
+
var feedbackKey = (value) => `${value.kind}:${value.id}`;
|
|
793
|
+
var callFor = (ctx) => (name, args) => ctx.callIntegrationTool(name, { projectKey: "repo", ...args });
|
|
848
794
|
function requireIssueOrigin(params) {
|
|
849
795
|
if (!isIssueOrigin(params)) throw new Error("Forgejo source issue metadata is unavailable");
|
|
850
796
|
return params;
|
|
@@ -858,57 +804,6 @@ function pinnedGitIdentity(ctx) {
|
|
|
858
804
|
}
|
|
859
805
|
return identity;
|
|
860
806
|
}
|
|
861
|
-
async function commitWorkBranch(ctx, commitMessage) {
|
|
862
|
-
const repo = ctx.repo.get("repo");
|
|
863
|
-
const gitIdentity = pinnedGitIdentity(ctx) ?? await ctx.callIntegrationTool("forgejo_resolve_git_identity", {
|
|
864
|
-
projectKey: "repo"
|
|
865
|
-
});
|
|
866
|
-
return commitAndPushWorkBranch({
|
|
867
|
-
repoPath: repo.fsPath,
|
|
868
|
-
workBranch: repo.workBranch,
|
|
869
|
-
commitMessage,
|
|
870
|
-
gitIdentity
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
function deliveryProgress(value, activeStepId) {
|
|
874
|
-
const delivery = value.delivery;
|
|
875
|
-
const step = (id, label, done) => ({
|
|
876
|
-
id,
|
|
877
|
-
label,
|
|
878
|
-
status: activeStepId === id ? "in_progress" : done ? "completed" : "incomplete"
|
|
879
|
-
});
|
|
880
|
-
const adjustmentHandled = delivery.adjustment === null && delivery.stage === "awaiting" && value.headSha !== null;
|
|
881
|
-
return {
|
|
882
|
-
title: "Delivery progress",
|
|
883
|
-
steps: [
|
|
884
|
-
step("publish_branch", "Publish work branch", value.headSha !== null),
|
|
885
|
-
step("open_pr", "Create or find pull request", value.prNumber !== null),
|
|
886
|
-
step("link_issue", "Link source issue when applicable", delivery.issueLinked),
|
|
887
|
-
step("publish_adjustment", "Publish an adjustment when applicable", adjustmentHandled),
|
|
888
|
-
step(
|
|
889
|
-
"reply_feedback",
|
|
890
|
-
"Acknowledge or reply to feedback when applicable",
|
|
891
|
-
value.feedbackIds.length === 0
|
|
892
|
-
),
|
|
893
|
-
step("await_evidence", "Await external evidence", delivery.stage === "awaiting"),
|
|
894
|
-
step(
|
|
895
|
-
"reconcile_terminal",
|
|
896
|
-
"Reconcile terminal pull request",
|
|
897
|
-
delivery.terminalPullRequest !== null
|
|
898
|
-
)
|
|
899
|
-
],
|
|
900
|
-
...value.prNumber && value.prUrl ? {
|
|
901
|
-
links: [
|
|
902
|
-
{
|
|
903
|
-
id: `forgejo-pr-${value.prNumber}`,
|
|
904
|
-
label: `Forgejo PR #${value.prNumber}`,
|
|
905
|
-
url: value.prUrl,
|
|
906
|
-
kind: "pull_request"
|
|
907
|
-
}
|
|
908
|
-
]
|
|
909
|
-
} : {}
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
807
|
var deliveryTools = [
|
|
913
808
|
"forgejo_get_pull_request",
|
|
914
809
|
"forgejo_add_pull_request_comment",
|
|
@@ -922,9 +817,6 @@ var deliveryTools = [
|
|
|
922
817
|
"forgejo_update_issue"
|
|
923
818
|
];
|
|
924
819
|
function createForgejoRepoChangeProcess(launcher, docker) {
|
|
925
|
-
const publication = flow.fragment(
|
|
926
|
-
"forgejo-publication"
|
|
927
|
-
);
|
|
928
820
|
const failedPipeline = woodpeckerExternal.pipeline(({ params, state }) => {
|
|
929
821
|
const current = requirePr(state);
|
|
930
822
|
return {
|
|
@@ -938,20 +830,123 @@ function createForgejoRepoChangeProcess(launcher, docker) {
|
|
|
938
830
|
pollInterval: "30s"
|
|
939
831
|
};
|
|
940
832
|
});
|
|
941
|
-
const
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
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);
|
|
955
950
|
if (isIssueOrigin(ctx.params)) {
|
|
956
951
|
const issue = await call("forgejo_get_issue", {
|
|
957
952
|
issueNumber: ctx.params.issueNumber
|
|
@@ -974,19 +969,9 @@ function createForgejoRepoChangeProcess(launcher, docker) {
|
|
|
974
969
|
writeKey: `forgejo:${ctx.process.id}:${pr.merged ? "merged" : "closed"}-pr-comment`
|
|
975
970
|
});
|
|
976
971
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
if (!current.headSha) {
|
|
981
|
-
ctx.reportProgress(deliveryProgress(current, "publish_branch"));
|
|
982
|
-
const published = await commitWorkBranch(
|
|
983
|
-
ctx,
|
|
984
|
-
ctx.state.finalization.generatedCommitMessage ?? ""
|
|
985
|
-
);
|
|
986
|
-
update({ headSha: published.headSha, pipeline: null });
|
|
987
|
-
}
|
|
988
|
-
if (!current.prNumber || !current.prUrl) {
|
|
989
|
-
ctx.reportProgress(deliveryProgress(current, "open_pr"));
|
|
972
|
+
},
|
|
973
|
+
async ensureRequest(ctx) {
|
|
974
|
+
const call = callFor(ctx);
|
|
990
975
|
const project = ctx.repo.get("repo");
|
|
991
976
|
const issueOrigin = isIssueOrigin(ctx.params);
|
|
992
977
|
const pr = await call("forgejo_ensure_pull_request", {
|
|
@@ -998,10 +983,10 @@ Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
|
|
|
998
983
|
base: project.baseBranch
|
|
999
984
|
});
|
|
1000
985
|
if (!pr) throw new Error("Forgejo pull request could not be created or found");
|
|
1001
|
-
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
ctx
|
|
986
|
+
return pr;
|
|
987
|
+
},
|
|
988
|
+
async linkIssue(ctx, current) {
|
|
989
|
+
const call = callFor(ctx);
|
|
1005
990
|
if (isIssueOrigin(ctx.params)) {
|
|
1006
991
|
await call("forgejo_add_issue_comment", {
|
|
1007
992
|
issueNumber: ctx.params.issueNumber,
|
|
@@ -1009,50 +994,21 @@ Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
|
|
|
1009
994
|
writeKey: `forgejo:${ctx.process.id}:source-pr-link:${current.prNumber}`
|
|
1010
995
|
});
|
|
1011
996
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1017
|
-
ctx.reportProgress(deliveryProgress(current, "publish_adjustment"));
|
|
1018
|
-
const published = adjustment.origin === "rebase" ? publishRebase(rebaseInput(ctx)) : await commitWorkBranch(
|
|
1019
|
-
ctx,
|
|
1020
|
-
adjustment.origin === "feedback" ? "fix: address Forgejo review feedback" : "fix: repair Woodpecker pipeline"
|
|
1021
|
-
);
|
|
1022
|
-
if (adjustment.origin === "rebase") {
|
|
1023
|
-
const refreshed = await call("forgejo_get_pull_request", {
|
|
1024
|
-
pullRequestNumber: current.prNumber
|
|
1025
|
-
});
|
|
1026
|
-
if (refreshed.head.sha !== published.headSha)
|
|
1027
|
-
throw new Error("Pull request head has not caught up with rebase publication");
|
|
1028
|
-
}
|
|
1029
|
-
update({ headSha: published.headSha, pipeline: null });
|
|
1030
|
-
}
|
|
1031
|
-
if (adjustment.origin === "rebase")
|
|
1032
|
-
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", {
|
|
1033
1002
|
pullRequestNumber: current.prNumber,
|
|
1034
|
-
|
|
1035
|
-
|
|
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}`
|
|
1036
1007
|
});
|
|
1037
|
-
if (adjustment.origin === "feedback") {
|
|
1038
|
-
ctx.reportProgress(deliveryProgress(current, "reply_feedback"));
|
|
1039
|
-
for (const feedback of current.feedbackIds) {
|
|
1040
|
-
await call("forgejo_reply_to_pull_request_feedback", {
|
|
1041
|
-
pullRequestNumber: current.prNumber,
|
|
1042
|
-
feedbackKind: feedback.kind,
|
|
1043
|
-
feedbackId: feedback.id,
|
|
1044
|
-
body: `Addressed in ${current.headSha?.slice(0, 8) ?? "the current revision"}.`,
|
|
1045
|
-
writeKey: `forgejo:${ctx.process.id}:feedback-reply:${feedbackKey(feedback)}:${current.headSha}`
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
1008
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
if (current.feedbackIds.length > 0) {
|
|
1055
|
-
ctx.reportProgress(deliveryProgress(current, "reply_feedback"));
|
|
1009
|
+
},
|
|
1010
|
+
async acknowledge(ctx, current) {
|
|
1011
|
+
const call = callFor(ctx);
|
|
1056
1012
|
for (const feedback of current.feedbackIds) {
|
|
1057
1013
|
if (feedback.kind === "review") continue;
|
|
1058
1014
|
await call("forgejo_add_pull_request_feedback_reaction", {
|
|
@@ -1062,222 +1018,25 @@ Leitwerk process: ${ctx.process.id}` : `Leitwerk process: ${ctx.process.id}`,
|
|
|
1062
1018
|
writeKey: `forgejo:${ctx.process.id}:feedback-eyes:${feedbackKey(feedback)}`
|
|
1063
1019
|
});
|
|
1064
1020
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
(
|
|
1079
|
-
|
|
1080
|
-
"aborted",
|
|
1081
|
-
(outcome) => outcome.description("Closed pull request was reconciled").object("nextState").lifecycleStatus("aborted").state(({ event }) => event.params.nextState)
|
|
1082
|
-
).externalAction(
|
|
1083
|
-
"forgejo_merge_conflict",
|
|
1084
|
-
forgejoExternal.pullRequestConflict(({ params, state }) => ({
|
|
1085
|
-
profile: params.forgejoProfile,
|
|
1086
|
-
owner: params.owner,
|
|
1087
|
-
repo: params.repo,
|
|
1088
|
-
prNumber: requirePr(state).prNumber,
|
|
1089
|
-
headSha: requirePr(state).headSha,
|
|
1090
|
-
lastConflictKey: remote(state).lastConflictKey,
|
|
1091
|
-
pollInterval: "30s"
|
|
1092
|
-
})),
|
|
1093
|
-
(external) => external.label("Rebase conflicting pull request").to(ids.feedback).effect(({ params, state, event }) => {
|
|
1094
|
-
const current = requirePr(state);
|
|
1095
|
-
const conflict = validateConflict(
|
|
1096
|
-
object2(event).conflict,
|
|
1097
|
-
{
|
|
1098
|
-
owner: params.owner,
|
|
1099
|
-
repo: params.repo,
|
|
1100
|
-
prNumber: current.prNumber,
|
|
1101
|
-
headSha: current.headSha,
|
|
1102
|
-
headBranch: params.workBranch,
|
|
1103
|
-
baseBranch: params.baseBranch
|
|
1104
|
-
},
|
|
1105
|
-
current.lastConflictKey
|
|
1106
|
-
);
|
|
1107
|
-
return {
|
|
1108
|
-
state: patchRemote(state, {
|
|
1109
|
-
lastConflictKey: conflictKey(conflict),
|
|
1110
|
-
conflict,
|
|
1111
|
-
repairReason: "rebase"
|
|
1112
|
-
})
|
|
1113
|
-
};
|
|
1114
|
-
})
|
|
1115
|
-
).externalAction(
|
|
1116
|
-
"forgejo_feedback",
|
|
1117
|
-
forgejoExternal.pullRequestFeedback(({ params, state }) => {
|
|
1118
|
-
const current = requirePr(state);
|
|
1119
|
-
return {
|
|
1120
|
-
profile: params.forgejoProfile,
|
|
1121
|
-
owner: params.owner,
|
|
1122
|
-
repo: params.repo,
|
|
1123
|
-
prNumber: current.prNumber,
|
|
1124
|
-
conversationCursor: current.conversationCursor,
|
|
1125
|
-
reviewCursor: current.reviewCursor,
|
|
1126
|
-
inlineCursor: current.inlineCursor,
|
|
1127
|
-
quietPeriodMs: 12e4,
|
|
1128
|
-
pollInterval: "30s"
|
|
1129
|
-
};
|
|
1130
|
-
}),
|
|
1131
|
-
(external) => external.label("Forgejo pull request feedback").to(ids.deliver).effect(({ state, event }) => {
|
|
1132
|
-
const value = object2(event);
|
|
1133
|
-
const cursors = object2(value.cursors);
|
|
1134
|
-
return {
|
|
1135
|
-
state: patchRemote(state, {
|
|
1136
|
-
repairReason: "feedback",
|
|
1137
|
-
conversationCursor: Number(
|
|
1138
|
-
cursors.conversationCursor ?? remote(state).conversationCursor
|
|
1139
|
-
),
|
|
1140
|
-
reviewCursor: Number(cursors.reviewCursor ?? remote(state).reviewCursor),
|
|
1141
|
-
inlineCursor: Number(cursors.inlineCursor ?? remote(state).inlineCursor),
|
|
1142
|
-
feedbackIds: Array.isArray(value.feedbackIds) ? value.feedbackIds : []
|
|
1143
|
-
})
|
|
1144
|
-
};
|
|
1145
|
-
})
|
|
1146
|
-
).externalAction(
|
|
1147
|
-
"woodpecker_failure_repair",
|
|
1148
|
-
failedPipeline,
|
|
1149
|
-
(external) => external.label("Repair failed Woodpecker pipeline").when(({ state }) => remote(state).ciRecoveryCycles < 3).to(ids.ciRepair).effect(({ state, event }) => ({
|
|
1150
|
-
state: patchRemote(state, {
|
|
1151
|
-
repairReason: "ci",
|
|
1152
|
-
pipeline: object2(event).pipeline,
|
|
1153
|
-
ciRecoveryCycles: remote(state).ciRecoveryCycles + 1
|
|
1154
|
-
})
|
|
1155
|
-
}))
|
|
1156
|
-
).externalAction(
|
|
1157
|
-
"woodpecker_failure_operator",
|
|
1158
|
-
failedPipeline,
|
|
1159
|
-
(external) => external.label("Escalate failed Woodpecker pipeline").when(({ state }) => remote(state).ciRecoveryCycles >= 3).to(ids.operator).effect(({ state, event }) => ({
|
|
1160
|
-
state: patchRemote(state, {
|
|
1161
|
-
repairReason: "ci",
|
|
1162
|
-
pipeline: object2(event).pipeline
|
|
1163
|
-
})
|
|
1164
|
-
}))
|
|
1165
|
-
);
|
|
1166
|
-
for (const [terminalOutcome, label] of [
|
|
1167
|
-
["merged", "Forgejo pull request merged"],
|
|
1168
|
-
["closed", "Forgejo pull request closed without merge"]
|
|
1169
|
-
]) {
|
|
1170
|
-
delivery.externalAction(
|
|
1171
|
-
`forgejo_pr_${terminalOutcome}`,
|
|
1172
|
-
forgejoExternal.pullRequestTerminal(({ params, state }) => ({
|
|
1173
|
-
profile: params.forgejoProfile,
|
|
1174
|
-
owner: params.owner,
|
|
1175
|
-
repo: params.repo,
|
|
1176
|
-
prNumber: requirePr(state).prNumber,
|
|
1177
|
-
terminalOutcome,
|
|
1178
|
-
pollInterval: "30s"
|
|
1179
|
-
})),
|
|
1180
|
-
(external) => external.label(label).to(ids.deliver).effect(({ state, event }) => ({
|
|
1181
|
-
state: patchRemote(state, {
|
|
1182
|
-
delivery: { terminalPullRequest: object2(event).pullRequest }
|
|
1183
|
-
})
|
|
1184
|
-
}))
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
publication.turn(
|
|
1188
|
-
delivery.externalAction(
|
|
1189
|
-
"source_cancelled",
|
|
1190
|
-
forgejoExternal.issueCancelled(({ params }) => {
|
|
1191
|
-
const issue = requireIssueOrigin(params);
|
|
1192
|
-
return {
|
|
1193
|
-
profile: issue.forgejoProfile,
|
|
1194
|
-
owner: issue.owner,
|
|
1195
|
-
repo: issue.repo,
|
|
1196
|
-
issueNumber: issue.issueNumber,
|
|
1197
|
-
triggerLabel: issue.triggerLabel,
|
|
1198
|
-
pollInterval: "30s"
|
|
1199
|
-
};
|
|
1200
|
-
}),
|
|
1201
|
-
(external) => external.label("Source issue cancelled").when(({ params }) => isIssueOrigin(params)).lifecycleStatus("aborted")
|
|
1202
|
-
)
|
|
1203
|
-
);
|
|
1204
|
-
function rebaseInput(ctx) {
|
|
1205
|
-
const project = ctx.repo.get("repo");
|
|
1206
|
-
const conflict = remote(ctx.state).conflict;
|
|
1207
|
-
if (!conflict) throw new Error("Missing conflict evidence");
|
|
1208
|
-
return { projectKey: "repo", path: project.fsPath, workBranch: project.workBranch, conflict };
|
|
1209
|
-
}
|
|
1210
|
-
function repairReason(state, kind) {
|
|
1211
|
-
return kind === "feedback" && remote(state).repairReason === "rebase" ? "rebase" : kind;
|
|
1212
|
-
}
|
|
1213
|
-
function revisionPrompt(kind) {
|
|
1214
|
-
return (ctx) => {
|
|
1215
|
-
const current = remote(ctx.state);
|
|
1216
|
-
if (repairReason(ctx.state, kind) === "rebase")
|
|
1217
|
-
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) {
|
|
1218
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.`;
|
|
1219
|
-
};
|
|
1220
|
-
}
|
|
1221
|
-
function revisionTurn(id, kind) {
|
|
1222
|
-
const turn = flow.llm(id).description(kind === "feedback" ? "Address Feedback" : "Fix CI").tools("read", "bash", "edit", "write").resolveIntegrationTools(
|
|
1223
|
-
(_params, state) => repairReason(state, kind) === "rebase" ? [] : kind === "feedback" ? ["forgejo_get_pull_request", "forgejo_list_pull_request_feedback"] : [
|
|
1224
|
-
"woodpecker_lookup_repository",
|
|
1225
|
-
"woodpecker_list_pipelines",
|
|
1226
|
-
"woodpecker_get_pipeline",
|
|
1227
|
-
"woodpecker_get_step_logs",
|
|
1228
|
-
"woodpecker_restart_pipeline"
|
|
1229
|
-
]
|
|
1230
|
-
).prepare(
|
|
1231
|
-
(ctx) => repairReason(ctx.state, kind) === "rebase" ? startRebase(rebaseInput(ctx)) : {}
|
|
1232
|
-
).freshPrimary().prompt(revisionPrompt(kind));
|
|
1233
|
-
for (const [name, description, publishRequired] of [
|
|
1234
|
-
["changes_ready", "Repository changes are ready to publish", true],
|
|
1235
|
-
["no_changes", "No repository change is required", false]
|
|
1236
|
-
]) {
|
|
1237
|
-
turn.outcomeTool(
|
|
1238
|
-
name,
|
|
1239
|
-
(tool) => tool.resultSummary().description(description).to(ids.deliver).state(
|
|
1240
|
-
({ ctx }) => patchRemote(ctx.state, {
|
|
1241
|
-
delivery: { adjustment: { origin: repairReason(ctx.state, kind), publishRequired } }
|
|
1242
|
-
})
|
|
1243
|
-
)
|
|
1244
|
-
);
|
|
1245
|
-
}
|
|
1246
|
-
return turn.outcomeTool(
|
|
1247
|
-
"cannot_repair",
|
|
1248
|
-
(tool) => tool.description("The adjustment requires operator action").to(ids.operator)
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
publication.turn(revisionTurn(ids.feedback, "feedback"));
|
|
1252
|
-
publication.turn(revisionTurn(ids.ciRepair, "ci"));
|
|
1253
|
-
publication.turn({
|
|
1254
|
-
id: ids.operator,
|
|
1255
|
-
definition: {
|
|
1256
|
-
kind: "human",
|
|
1257
|
-
description: "Repository repair needs operator action",
|
|
1258
|
-
operatorAttention: "required",
|
|
1259
|
-
actions: {
|
|
1260
|
-
retry_repair: {
|
|
1261
|
-
label: "Retry repair",
|
|
1262
|
-
acceptanceState: "accepted",
|
|
1263
|
-
branches: { feedback: { to: ids.feedback }, ci: { to: ids.ciRepair } },
|
|
1264
|
-
choose: ({ ctx }) => remote(ctx.state).repairReason === "rebase" || remote(ctx.state).repairReason === "feedback" ? "feedback" : "ci"
|
|
1265
|
-
},
|
|
1266
|
-
resume_waiting: {
|
|
1267
|
-
label: "Resume waiting",
|
|
1268
|
-
acceptanceState: "accepted",
|
|
1269
|
-
to: ids.deliver,
|
|
1270
|
-
effect: ({ ctx }) => ({
|
|
1271
|
-
state: patchRemote(ctx.state, {
|
|
1272
|
-
feedbackIds: [],
|
|
1273
|
-
delivery: { adjustment: null }
|
|
1274
|
-
})
|
|
1275
|
-
})
|
|
1276
|
-
},
|
|
1277
|
-
abort: { label: "Abort process", acceptanceState: "neutral", lifecycleStatus: "aborted" }
|
|
1278
|
-
}
|
|
1279
1037
|
}
|
|
1280
1038
|
});
|
|
1039
|
+
const publication = publicationConfig.fragment;
|
|
1281
1040
|
publication.watcher({
|
|
1282
1041
|
id: "use_leitwerk",
|
|
1283
1042
|
label: "Forgejo use-leitwerk issues",
|
|
@@ -1321,7 +1080,6 @@ ${body}` : ""}`
|
|
|
1321
1080
|
fields: [],
|
|
1322
1081
|
submitLabel: "Publish"
|
|
1323
1082
|
},
|
|
1324
|
-
finalizationDescription: "Publish feature branch",
|
|
1325
1083
|
repositoryCredentials: ({ params }) => [
|
|
1326
1084
|
{
|
|
1327
1085
|
projectKey: "repo",
|
|
@@ -1329,11 +1087,7 @@ ${body}` : ""}`
|
|
|
1329
1087
|
credentialRef: params.sshCredentialRef
|
|
1330
1088
|
}
|
|
1331
1089
|
],
|
|
1332
|
-
publication:
|
|
1333
|
-
entryTurnId: ids.deliver,
|
|
1334
|
-
fragment: publication,
|
|
1335
|
-
happyPath: [ids.deliver]
|
|
1336
|
-
}
|
|
1090
|
+
publication: publicationConfig
|
|
1337
1091
|
});
|
|
1338
1092
|
definition.process.runtime = { ...definition.process.runtime, docker };
|
|
1339
1093
|
return definition.process;
|