@leitwerk-dev/forgejo-repo-change 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/src/params.ts ADDED
@@ -0,0 +1,114 @@
1
+ import {
2
+ createRepositoryChangeParamsCodec,
3
+ normalizeRepositoryChangeParamsInput,
4
+ type RepositoryChangeLaunchParams,
5
+ repositoryChangeParamsRecord,
6
+ } from "@leitwerk-dev/coding/repository-change-launch";
7
+ import { trimString } from "@leitwerk-dev/domain";
8
+
9
+ /** @public */
10
+ interface ForgejoRepoChangeCommonParams {
11
+ /** @internal */
12
+ forgejoProfile: string;
13
+ /** @internal */
14
+ woodpeckerProfile: string;
15
+ /** @internal */
16
+ sshCredentialRef: string;
17
+ /** @internal */
18
+ owner: string;
19
+ /** @internal */
20
+ repo: string;
21
+ }
22
+
23
+ /** @public */
24
+ export interface ForgejoIssueOriginParams {
25
+ /** @internal */
26
+ origin: "issue";
27
+ /** @internal */
28
+ issueNumber: number;
29
+ /** @internal */
30
+ issueUrl: string;
31
+ /** @internal */
32
+ triggerLabel: string;
33
+ /** @internal */
34
+ doneLabel: string;
35
+ }
36
+
37
+ /** @public */
38
+ export interface ForgejoUiOriginParams {
39
+ /** @internal */
40
+ origin: "ui";
41
+ /** @internal */
42
+ issueNumber: null;
43
+ /** @internal */
44
+ issueUrl: null;
45
+ /** @internal */
46
+ triggerLabel: null;
47
+ /** @internal */
48
+ doneLabel: null;
49
+ }
50
+
51
+ /** @public */
52
+ export type ForgejoRepoChangeParams = RepositoryChangeLaunchParams<
53
+ ForgejoRepoChangeCommonParams & (ForgejoIssueOriginParams | ForgejoUiOriginParams)
54
+ >;
55
+
56
+ /** @internal */
57
+ export function isIssueOrigin(
58
+ params: ForgejoRepoChangeParams,
59
+ ): params is ForgejoRepoChangeParams & ForgejoIssueOriginParams {
60
+ return params.origin === "issue";
61
+ }
62
+
63
+ /** @internal */
64
+ export const forgejoRepoChangeParamsCodec =
65
+ createRepositoryChangeParamsCodec<ForgejoRepoChangeParams>({
66
+ displayName: "Forgejo Repo Change",
67
+ normalize(value) {
68
+ const shared = normalizeRepositoryChangeParamsInput(value, "Forgejo Repo Change");
69
+ const record = repositoryChangeParamsRecord(value, "Forgejo Repo Change");
70
+ const text = (name: string) => {
71
+ const value = trimString(record[name]);
72
+ if (!value) throw new Error(`Forgejo Repo Change requires ${name}`);
73
+ return value;
74
+ };
75
+
76
+ const common = {
77
+ ...shared,
78
+ forgejoProfile: text("forgejoProfile"),
79
+ woodpeckerProfile: text("woodpeckerProfile"),
80
+ sshCredentialRef: text("sshCredentialRef"),
81
+ owner: text("owner"),
82
+ repo: text("repo"),
83
+ };
84
+ const origin = trimString(record.origin);
85
+ if (origin === "ui") {
86
+ return {
87
+ ...common,
88
+ origin: "ui" as const,
89
+ issueNumber: null,
90
+ issueUrl: null,
91
+ triggerLabel: null,
92
+ doneLabel: null,
93
+ };
94
+ }
95
+ if (origin && origin !== "issue") {
96
+ throw new Error("Forgejo Repo Change requires a valid origin");
97
+ }
98
+
99
+ if (
100
+ typeof record.issueNumber !== "number" ||
101
+ !Number.isInteger(record.issueNumber) ||
102
+ record.issueNumber <= 0
103
+ )
104
+ throw new Error("Forgejo Repo Change requires issueNumber");
105
+ return {
106
+ ...common,
107
+ origin: "issue" as const,
108
+ issueNumber: record.issueNumber,
109
+ issueUrl: text("issueUrl"),
110
+ triggerLabel: text("triggerLabel"),
111
+ doneLabel: text("doneLabel"),
112
+ };
113
+ },
114
+ });