@leitwerk-dev/woodpecker 0.0.0-bootstrap.0 → 0.2.1
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 +83 -1
- package/dist/LICENSE +13 -0
- package/dist/binding.d.ts +4 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/capability.d.ts +11 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/chunk-L6GKOYHO.js +13 -0
- package/dist/chunk-L6GKOYHO.js.map +1 -0
- package/dist/client.d.ts +66 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/external.d.ts +35 -0
- package/dist/external.d.ts.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +359 -0
- package/dist/index.js.map +1 -0
- package/dist/logs.d.ts +3 -0
- package/dist/logs.d.ts.map +1 -0
- package/dist/provider.d.ts +11 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/testing.d.ts +96 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +117 -0
- package/dist/testing.js.map +1 -0
- package/dist/tools.d.ts +4 -0
- package/dist/tools.d.ts.map +1 -0
- package/package.json +53 -14
- package/src/binding.ts +6 -0
- package/src/capability.ts +14 -0
- package/src/client.ts +178 -0
- package/src/external.ts +45 -0
- package/src/index.ts +52 -0
- package/src/logs.ts +8 -0
- package/src/provider.ts +121 -0
- package/src/testing.ts +172 -0
- package/src/tools.ts +109 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { coreHostCapabilities, type LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { type WoodpeckerIntegration, woodpeckerIntegration } from "./capability.js";
|
|
3
|
+
import { parseWoodpeckerProfiles, WoodpeckerClient } from "./client.js";
|
|
4
|
+
import { createWoodpeckerProvider } from "./provider.js";
|
|
5
|
+
import { registerWoodpeckerTools } from "./tools.js";
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
const manifest = {
|
|
9
|
+
/** @internal */
|
|
10
|
+
id: "woodpecker",
|
|
11
|
+
/** @internal */
|
|
12
|
+
version: "0.1.9",
|
|
13
|
+
} as const;
|
|
14
|
+
/** @public */
|
|
15
|
+
const extension: LeitwerkExtensionModule = {
|
|
16
|
+
manifest,
|
|
17
|
+
setupServer(api, config) {
|
|
18
|
+
const profiles = parseWoodpeckerProfiles(config);
|
|
19
|
+
const integration: WoodpeckerIntegration = {
|
|
20
|
+
client(profile) {
|
|
21
|
+
const value = profiles.get(profile);
|
|
22
|
+
if (!value) throw new Error(`Unknown Woodpecker profile '${profile}'`);
|
|
23
|
+
return new WoodpeckerClient(value);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
setupWoodpeckerIntegration(api, integration);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type { WoodpeckerIntegration } from "./capability.js";
|
|
31
|
+
export { woodpeckerIntegration } from "./capability.js";
|
|
32
|
+
export type { WoodpeckerPipeline } from "./client.js";
|
|
33
|
+
export { WOODPECKER_PIPELINE_KIND, woodpeckerExternal } from "./external.js";
|
|
34
|
+
export default extension;
|
|
35
|
+
|
|
36
|
+
/** Register shared tools and polling with an explicit integration. @public */
|
|
37
|
+
export function setupWoodpeckerIntegration(
|
|
38
|
+
api: Parameters<NonNullable<LeitwerkExtensionModule["setupServer"]>>[0],
|
|
39
|
+
integration: WoodpeckerIntegration,
|
|
40
|
+
options: {
|
|
41
|
+
/** @public */
|
|
42
|
+
now?: () => number;
|
|
43
|
+
} = {},
|
|
44
|
+
) {
|
|
45
|
+
api.provide(woodpeckerIntegration, integration);
|
|
46
|
+
const deps = api.get(coreHostCapabilities.serverSetup);
|
|
47
|
+
if (!deps || Array.isArray(deps)) return;
|
|
48
|
+
registerWoodpeckerTools(api, integration);
|
|
49
|
+
return createWoodpeckerProvider(deps, integration, options);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export * from "./binding.js";
|
package/src/logs.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Keep a bounded tail without splitting a UTF-8 character. */
|
|
2
|
+
export function boundedLogTail(lines: string[], tailLines: number, maxBytes: number): string {
|
|
3
|
+
const encoded = Buffer.from(lines.slice(-Math.min(Math.max(tailLines, 1), 2_000)).join("\n"));
|
|
4
|
+
const cap = Math.min(Math.max(maxBytes, 1), 1_048_576);
|
|
5
|
+
let start = Math.max(0, encoded.length - cap);
|
|
6
|
+
while (start < encoded.length && (encoded[start] & 0xc0) === 0x80) start++;
|
|
7
|
+
return encoded.subarray(start).toString("utf8");
|
|
8
|
+
}
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
2
|
+
import {
|
|
3
|
+
type CoreServerSetupDeps,
|
|
4
|
+
createExternalSourcePollReporter,
|
|
5
|
+
} from "@leitwerk-dev/process-sdk";
|
|
6
|
+
import { createPollSchedule, emptyPollResult } from "@leitwerk-dev/watcher-utils";
|
|
7
|
+
import type { WoodpeckerClientLike, WoodpeckerIntegration } from "./capability.js";
|
|
8
|
+
import { WOODPECKER_PIPELINE_KIND, type WoodpeckerPipelineSourceConfig } from "./external.js";
|
|
9
|
+
|
|
10
|
+
function parse(value: unknown): WoodpeckerPipelineSourceConfig | null {
|
|
11
|
+
const config = asUnknownRecord(value) ?? {};
|
|
12
|
+
if (
|
|
13
|
+
["profile", "owner", "repo", "branch", "headSha"].some(
|
|
14
|
+
(key) => typeof config[key] !== "string" || !(config[key] as string).trim(),
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
return null;
|
|
18
|
+
return {
|
|
19
|
+
profile: config.profile as string,
|
|
20
|
+
owner: config.owner as string,
|
|
21
|
+
repo: config.repo as string,
|
|
22
|
+
branch: config.branch as string,
|
|
23
|
+
headSha: config.headSha as string,
|
|
24
|
+
afterPipelineNumber:
|
|
25
|
+
typeof config.afterPipelineNumber === "number" ? config.afterPipelineNumber : 0,
|
|
26
|
+
disabled: config.disabled === true,
|
|
27
|
+
pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
|
|
28
|
+
statuses: Array.isArray(config.statuses)
|
|
29
|
+
? config.statuses.filter((value): value is string => typeof value === "string")
|
|
30
|
+
: undefined,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const terminal = new Set([
|
|
34
|
+
"success",
|
|
35
|
+
"failure",
|
|
36
|
+
"error",
|
|
37
|
+
"killed",
|
|
38
|
+
"canceled",
|
|
39
|
+
"cancelled",
|
|
40
|
+
"declined",
|
|
41
|
+
"blocked",
|
|
42
|
+
]);
|
|
43
|
+
const supportedEvents = new Set(["push", "pull_request", "pull_request_closed"]);
|
|
44
|
+
|
|
45
|
+
function matchesBranch(event: string, pipelineBranch: string, sourceBranch: string): boolean {
|
|
46
|
+
// Woodpecker reports the PR target branch in `branch`. The commit uniquely
|
|
47
|
+
// identifies the watched source head, so branch filtering only applies to pushes.
|
|
48
|
+
return event !== "push" || pipelineBranch === sourceBranch;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createWoodpeckerProvider(
|
|
52
|
+
deps: CoreServerSetupDeps,
|
|
53
|
+
integration: WoodpeckerIntegration,
|
|
54
|
+
options: { now?: () => number } = {},
|
|
55
|
+
) {
|
|
56
|
+
const due = createPollSchedule(options.now);
|
|
57
|
+
return deps.polling.create({
|
|
58
|
+
id: "woodpecker",
|
|
59
|
+
pollInterval: () => "5s",
|
|
60
|
+
isEnabled: () => true,
|
|
61
|
+
defaultIntervalMs: 5_000,
|
|
62
|
+
async pollOnce() {
|
|
63
|
+
const result = emptyPollResult();
|
|
64
|
+
const report = createExternalSourcePollReporter(deps.externalSources, result);
|
|
65
|
+
await report.poll(WOODPECKER_PIPELINE_KIND, async (armed) => {
|
|
66
|
+
const config = parse(armed.resolved);
|
|
67
|
+
if (!config) {
|
|
68
|
+
result.errors.push(`${armed.id}:invalid_config`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (config.disabled) return;
|
|
72
|
+
const key = `${armed.instanceId}:${armed.id}`;
|
|
73
|
+
if (!due(key, config.pollInterval)) return;
|
|
74
|
+
const client = integration.client(config.profile);
|
|
75
|
+
const repo = await client.lookupRepository(`${config.owner}/${config.repo}`);
|
|
76
|
+
const pipeline = await findLatestPipeline(client, repo.id, config);
|
|
77
|
+
if (
|
|
78
|
+
!pipeline ||
|
|
79
|
+
!terminal.has(pipeline.status) ||
|
|
80
|
+
(config.statuses && !config.statuses.includes(pipeline.status))
|
|
81
|
+
)
|
|
82
|
+
return;
|
|
83
|
+
await report.fire(
|
|
84
|
+
armed,
|
|
85
|
+
{ repositoryId: repo.id, pipeline },
|
|
86
|
+
`${pipeline.number}:${pipeline.status}`,
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The bounded lookup reports incomplete history instead of waiting silently. */
|
|
95
|
+
export async function findLatestPipeline(
|
|
96
|
+
client: WoodpeckerClientLike,
|
|
97
|
+
repoId: number,
|
|
98
|
+
config: WoodpeckerPipelineSourceConfig,
|
|
99
|
+
) {
|
|
100
|
+
for (let page = 1; page <= 10; page++) {
|
|
101
|
+
const pipelines = (await client.listPipelines(repoId, undefined, { page, perPage: 100 })).sort(
|
|
102
|
+
(a, b) => b.number - a.number,
|
|
103
|
+
);
|
|
104
|
+
const match = pipelines.find(
|
|
105
|
+
(candidate) =>
|
|
106
|
+
candidate.number > (config.afterPipelineNumber ?? 0) &&
|
|
107
|
+
candidate.commit === config.headSha &&
|
|
108
|
+
supportedEvents.has(candidate.event) &&
|
|
109
|
+
matchesBranch(candidate.event, candidate.branch, config.branch),
|
|
110
|
+
);
|
|
111
|
+
if (match) return match;
|
|
112
|
+
if (
|
|
113
|
+
pipelines.length < 100 ||
|
|
114
|
+
pipelines.some((candidate) => candidate.number <= (config.afterPipelineNumber ?? 0))
|
|
115
|
+
)
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
throw new Error(
|
|
119
|
+
"Woodpecker pipeline lookup window exhausted (1000 pipelines); inspect the repository and update the watched pipeline floor before retrying",
|
|
120
|
+
);
|
|
121
|
+
}
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { LocalProviderStore } from "@leitwerk-dev/test-support/local-git";
|
|
2
|
+
import type { WoodpeckerClientLike } from "./capability.js";
|
|
3
|
+
import type { WoodpeckerPipeline, WoodpeckerRepository } from "./client.js";
|
|
4
|
+
import { boundedLogTail } from "./logs.js";
|
|
5
|
+
|
|
6
|
+
/** @public */
|
|
7
|
+
interface LocalWoodpeckerRepository {
|
|
8
|
+
/** @public */
|
|
9
|
+
repository: WoodpeckerRepository;
|
|
10
|
+
/** @public */
|
|
11
|
+
pipelines: Array<
|
|
12
|
+
WoodpeckerPipeline & {
|
|
13
|
+
/** @internal */
|
|
14
|
+
logs: string;
|
|
15
|
+
/** @internal */
|
|
16
|
+
controlKey?: string;
|
|
17
|
+
}
|
|
18
|
+
>;
|
|
19
|
+
}
|
|
20
|
+
/** @public */
|
|
21
|
+
export interface LocalWoodpeckerState {
|
|
22
|
+
/** @public */
|
|
23
|
+
version: 1;
|
|
24
|
+
/** @public */
|
|
25
|
+
sequence: number;
|
|
26
|
+
/** @public */
|
|
27
|
+
repositories: LocalWoodpeckerRepository[];
|
|
28
|
+
}
|
|
29
|
+
/** @public */
|
|
30
|
+
interface LocalWoodpeckerOptions {
|
|
31
|
+
/** @public */
|
|
32
|
+
root: string;
|
|
33
|
+
/** @public */
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
/** @public */
|
|
36
|
+
now?: () => number;
|
|
37
|
+
/** @public */
|
|
38
|
+
nextId?: () => number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Local CI state is independent of the repository's Git host. @public */
|
|
42
|
+
export class LocalWoodpeckerAdapter extends LocalProviderStore<
|
|
43
|
+
LocalWoodpeckerState,
|
|
44
|
+
LocalWoodpeckerOptions
|
|
45
|
+
> {
|
|
46
|
+
/** @public */
|
|
47
|
+
constructor(options: LocalWoodpeckerOptions) {
|
|
48
|
+
super(options, "woodpecker.json", {
|
|
49
|
+
version: 1,
|
|
50
|
+
sequence: 0,
|
|
51
|
+
repositories: [],
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** @public */
|
|
55
|
+
seed(fullName: string, id?: number) {
|
|
56
|
+
const existing = this.state.repositories.find((r) => r.repository.full_name === fullName);
|
|
57
|
+
if (existing) return existing;
|
|
58
|
+
const repo = { repository: { id: id ?? this.id(), full_name: fullName }, pipelines: [] };
|
|
59
|
+
this.state.sequence = Math.max(this.state.sequence, repo.repository.id);
|
|
60
|
+
this.state.repositories.push(repo);
|
|
61
|
+
this.save();
|
|
62
|
+
return repo;
|
|
63
|
+
}
|
|
64
|
+
/** @public */
|
|
65
|
+
publish(
|
|
66
|
+
repo: LocalWoodpeckerRepository,
|
|
67
|
+
input: {
|
|
68
|
+
/** @public */
|
|
69
|
+
branch: string;
|
|
70
|
+
/** @public */
|
|
71
|
+
commit: string;
|
|
72
|
+
/** @public */
|
|
73
|
+
status: string;
|
|
74
|
+
/** @public */
|
|
75
|
+
logs: string;
|
|
76
|
+
/** @internal */
|
|
77
|
+
event?: string;
|
|
78
|
+
/** @internal */
|
|
79
|
+
controlKey?: string;
|
|
80
|
+
},
|
|
81
|
+
) {
|
|
82
|
+
if (
|
|
83
|
+
![
|
|
84
|
+
"pending",
|
|
85
|
+
"running",
|
|
86
|
+
"success",
|
|
87
|
+
"failure",
|
|
88
|
+
"error",
|
|
89
|
+
"killed",
|
|
90
|
+
"canceled",
|
|
91
|
+
"cancelled",
|
|
92
|
+
"declined",
|
|
93
|
+
"blocked",
|
|
94
|
+
].includes(input.status)
|
|
95
|
+
)
|
|
96
|
+
throw new Error("Invalid pipeline status");
|
|
97
|
+
const number = this.id();
|
|
98
|
+
const pipeline = {
|
|
99
|
+
...input,
|
|
100
|
+
/** @internal */
|
|
101
|
+
id: number,
|
|
102
|
+
/** @public */
|
|
103
|
+
number,
|
|
104
|
+
/** @internal */
|
|
105
|
+
event: input.event ?? "push",
|
|
106
|
+
/** @internal */
|
|
107
|
+
created_at: Math.floor((this.options.now?.() ?? Date.now()) / 1000),
|
|
108
|
+
/** @internal */
|
|
109
|
+
workflows: [
|
|
110
|
+
{
|
|
111
|
+
/** @internal */
|
|
112
|
+
id: 1,
|
|
113
|
+
/** @internal */
|
|
114
|
+
name: "local",
|
|
115
|
+
/** @internal */
|
|
116
|
+
steps: [
|
|
117
|
+
{
|
|
118
|
+
/** @internal */
|
|
119
|
+
id: 1,
|
|
120
|
+
/** @internal */
|
|
121
|
+
name: "validation",
|
|
122
|
+
/** @internal */
|
|
123
|
+
state: input.status,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
repo.pipelines.push(pipeline);
|
|
130
|
+
this.save();
|
|
131
|
+
return pipeline;
|
|
132
|
+
}
|
|
133
|
+
/** @public */
|
|
134
|
+
client(): WoodpeckerClientLike {
|
|
135
|
+
const repo = (id: number) => {
|
|
136
|
+
const value = this.state.repositories.find((r) => r.repository.id === id);
|
|
137
|
+
if (!value) throw new Error("Unknown local CI repository");
|
|
138
|
+
return value;
|
|
139
|
+
};
|
|
140
|
+
const pipeline = (id: number, number: number) => {
|
|
141
|
+
const value = repo(id).pipelines.find((p) => p.number === number);
|
|
142
|
+
if (!value) throw new Error("Unknown local pipeline");
|
|
143
|
+
return value;
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
profile: { baseUrl: this.options.baseUrl, token: "" },
|
|
147
|
+
lookupRepository: async (name) => {
|
|
148
|
+
const value = this.state.repositories.find((r) => r.repository.full_name === name);
|
|
149
|
+
if (!value) throw new Error("Unknown local CI repository");
|
|
150
|
+
return structuredClone(value.repository);
|
|
151
|
+
},
|
|
152
|
+
listPipelines: async (id, _signal, { page = 1, perPage = 100 } = { page: 1 }) =>
|
|
153
|
+
structuredClone(
|
|
154
|
+
[...repo(id).pipelines]
|
|
155
|
+
.sort((a, b) => b.number - a.number)
|
|
156
|
+
.slice((page - 1) * perPage, page * perPage),
|
|
157
|
+
),
|
|
158
|
+
getPipeline: async (id, number) => structuredClone(pipeline(id, number)),
|
|
159
|
+
getStepLogs: async (id, number, _step, tail = 400, bytes = 262144) => {
|
|
160
|
+
const original = pipeline(id, number).logs;
|
|
161
|
+
const logs = boundedLogTail(original.split("\n"), tail, bytes);
|
|
162
|
+
return { logs, truncated: logs !== original };
|
|
163
|
+
},
|
|
164
|
+
restartPipeline: async (id, number) => {
|
|
165
|
+
const value = pipeline(id, number);
|
|
166
|
+
value.status = "pending";
|
|
167
|
+
this.save();
|
|
168
|
+
return structuredClone(value);
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
package/src/tools.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type IntegrationToolExecutionContext,
|
|
3
|
+
numberArg,
|
|
4
|
+
projectParameters,
|
|
5
|
+
type ServerExtensionAPI,
|
|
6
|
+
stringArg,
|
|
7
|
+
} from "@leitwerk-dev/process-sdk";
|
|
8
|
+
import { resolveWoodpeckerProjectBinding } from "./binding.js";
|
|
9
|
+
import type { WoodpeckerIntegration } from "./capability.js";
|
|
10
|
+
|
|
11
|
+
function target(ctx: IntegrationToolExecutionContext) {
|
|
12
|
+
const binding = resolveWoodpeckerProjectBinding(ctx);
|
|
13
|
+
return { fullName: `${binding.owner}/${binding.repo}`, profile: binding.profile };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function registerWoodpeckerTools(
|
|
17
|
+
api: ServerExtensionAPI,
|
|
18
|
+
integration: WoodpeckerIntegration,
|
|
19
|
+
) {
|
|
20
|
+
const schema = projectParameters();
|
|
21
|
+
api.tool<Record<string, unknown>>({
|
|
22
|
+
name: "woodpecker_lookup_repository",
|
|
23
|
+
description: "Resolve the current process repository in Woodpecker",
|
|
24
|
+
parameters: schema,
|
|
25
|
+
async execute(ctx) {
|
|
26
|
+
const t = target(ctx);
|
|
27
|
+
return integration.client(t.profile).lookupRepository(t.fullName, ctx.signal);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
api.tool<Record<string, unknown>>({
|
|
31
|
+
name: "woodpecker_list_pipelines",
|
|
32
|
+
description: "List recent Woodpecker pipelines for the current process repository",
|
|
33
|
+
parameters: schema,
|
|
34
|
+
async execute(ctx) {
|
|
35
|
+
const t = target(ctx);
|
|
36
|
+
const client = integration.client(t.profile);
|
|
37
|
+
const repo = await client.lookupRepository(t.fullName, ctx.signal);
|
|
38
|
+
return client.listPipelines(repo.id, ctx.signal);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
for (const name of ["woodpecker_get_pipeline", "woodpecker_restart_pipeline"] as const) {
|
|
42
|
+
api.tool<Record<string, unknown>>({
|
|
43
|
+
name,
|
|
44
|
+
description: name.endsWith("restart_pipeline")
|
|
45
|
+
? "Restart a diagnosed Woodpecker pipeline"
|
|
46
|
+
: "Read a Woodpecker pipeline",
|
|
47
|
+
parameters: projectParameters({
|
|
48
|
+
pipelineNumber: { type: "integer" },
|
|
49
|
+
...(name === "woodpecker_restart_pipeline"
|
|
50
|
+
? {
|
|
51
|
+
diagnosis: {
|
|
52
|
+
type: "string",
|
|
53
|
+
description:
|
|
54
|
+
"Why this is an infrastructure or flaky failure rather than a repository defect",
|
|
55
|
+
},
|
|
56
|
+
logEvidence: {
|
|
57
|
+
type: "string",
|
|
58
|
+
description: "Concrete bounded-log evidence supporting a restart",
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
: {}),
|
|
62
|
+
}),
|
|
63
|
+
async execute(ctx, args) {
|
|
64
|
+
const t = target(ctx);
|
|
65
|
+
const client = integration.client(t.profile);
|
|
66
|
+
const repo = await client.lookupRepository(t.fullName, ctx.signal);
|
|
67
|
+
const number = numberArg(args, "pipelineNumber");
|
|
68
|
+
if (name === "woodpecker_get_pipeline")
|
|
69
|
+
return client.getPipeline(repo.id, number, ctx.signal);
|
|
70
|
+
const diagnosis = stringArg(args, "diagnosis");
|
|
71
|
+
const logEvidence = stringArg(args, "logEvidence");
|
|
72
|
+
await ctx.externalWrites.logOnly(
|
|
73
|
+
{ writeType: "woodpecker.restart", dedupKey: ctx.idempotencyKey },
|
|
74
|
+
async () => {
|
|
75
|
+
await client.restartPipeline(repo.id, number, ctx.signal);
|
|
76
|
+
return { repoId: repo.id, number, diagnosis, logEvidence };
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
return { ok: true };
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
api.tool<Record<string, unknown>>({
|
|
84
|
+
name: "woodpecker_get_step_logs",
|
|
85
|
+
description: "Read bounded logs for a Woodpecker pipeline step",
|
|
86
|
+
parameters: projectParameters(
|
|
87
|
+
{
|
|
88
|
+
pipelineNumber: { type: "integer" },
|
|
89
|
+
stepId: { type: "integer" },
|
|
90
|
+
tailLines: { type: "integer" },
|
|
91
|
+
maxBytes: { type: "integer" },
|
|
92
|
+
},
|
|
93
|
+
["pipelineNumber", "stepId"],
|
|
94
|
+
),
|
|
95
|
+
async execute(ctx, args) {
|
|
96
|
+
const t = target(ctx);
|
|
97
|
+
const client = integration.client(t.profile);
|
|
98
|
+
const repo = await client.lookupRepository(t.fullName, ctx.signal);
|
|
99
|
+
return client.getStepLogs(
|
|
100
|
+
repo.id,
|
|
101
|
+
numberArg(args, "pipelineNumber"),
|
|
102
|
+
numberArg(args, "stepId"),
|
|
103
|
+
typeof args.tailLines === "number" ? args.tailLines : 400,
|
|
104
|
+
typeof args.maxBytes === "number" ? args.maxBytes : 262_144,
|
|
105
|
+
ctx.signal,
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|