@blogic-cz/agent-tools 0.8.18 → 0.9.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/package.json +1 -1
- package/src/gh-tool/branch.ts +91 -0
- package/src/gh-tool/index.ts +16 -2
- package/src/gh-tool/types.ts +8 -0
package/package.json
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Command, Flag } from "effect/unstable/cli";
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
|
|
4
|
+
import { formatOption, logFormatted } from "#shared";
|
|
5
|
+
import type { BranchRenameResult } from "./types";
|
|
6
|
+
import { GitHubService } from "./service";
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Internal handlers
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
export const renameBranch = Effect.fn("branch.renameBranch")(function* (opts: {
|
|
13
|
+
oldName: string;
|
|
14
|
+
newName: string;
|
|
15
|
+
confirm: boolean;
|
|
16
|
+
repo: string | null;
|
|
17
|
+
}) {
|
|
18
|
+
const gh = yield* GitHubService;
|
|
19
|
+
|
|
20
|
+
if (!opts.confirm) {
|
|
21
|
+
const scope = opts.repo !== null ? ` in ${opts.repo}` : "";
|
|
22
|
+
|
|
23
|
+
const dryRun: BranchRenameResult = {
|
|
24
|
+
renamed: false,
|
|
25
|
+
oldName: opts.oldName,
|
|
26
|
+
newName: opts.newName,
|
|
27
|
+
dryRun: true,
|
|
28
|
+
message: `Dry run: would rename branch '${opts.oldName}' to '${opts.newName}'${scope}. Re-run with --confirm to execute.`,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return dryRun;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const repoInfo =
|
|
35
|
+
opts.repo !== null
|
|
36
|
+
? opts.repo
|
|
37
|
+
: yield* gh.getRepoInfo().pipe(Effect.map((r) => `${r.owner}/${r.name}`));
|
|
38
|
+
|
|
39
|
+
const args = [
|
|
40
|
+
"api",
|
|
41
|
+
`repos/${repoInfo}/branches/${encodeURIComponent(opts.oldName)}/rename`,
|
|
42
|
+
"-X",
|
|
43
|
+
"POST",
|
|
44
|
+
"-f",
|
|
45
|
+
`new_name=${opts.newName}`,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
yield* gh.runGh(args);
|
|
49
|
+
|
|
50
|
+
const result: BranchRenameResult = {
|
|
51
|
+
renamed: true,
|
|
52
|
+
oldName: opts.oldName,
|
|
53
|
+
newName: opts.newName,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return result;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// CLI Commands
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
export const branchRenameCommand = Command.make(
|
|
64
|
+
"rename",
|
|
65
|
+
{
|
|
66
|
+
confirm: Flag.boolean("confirm").pipe(
|
|
67
|
+
Flag.withDescription("Actually rename (without this flag, only shows dry-run)"),
|
|
68
|
+
Flag.withDefault(false),
|
|
69
|
+
),
|
|
70
|
+
format: formatOption,
|
|
71
|
+
newName: Flag.string("new-name").pipe(Flag.withDescription("New branch name")),
|
|
72
|
+
oldName: Flag.string("old-name").pipe(Flag.withDescription("Current branch name to rename")),
|
|
73
|
+
repo: Flag.string("repo").pipe(
|
|
74
|
+
Flag.withDescription("Target repository (owner/name). Defaults to current repo"),
|
|
75
|
+
Flag.optional,
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
({ confirm, format, newName, oldName, repo }) =>
|
|
79
|
+
Effect.gen(function* () {
|
|
80
|
+
const result = yield* renameBranch({
|
|
81
|
+
oldName,
|
|
82
|
+
newName,
|
|
83
|
+
confirm,
|
|
84
|
+
repo: Option.getOrNull(repo),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
yield* logFormatted(result, format);
|
|
88
|
+
}),
|
|
89
|
+
).pipe(
|
|
90
|
+
Command.withDescription("Rename a GitHub branch (dry-run by default, use --confirm to execute)"),
|
|
91
|
+
);
|
package/src/gh-tool/index.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
prReplyAndResolveCommand,
|
|
38
38
|
prReviewTriageCommand,
|
|
39
39
|
} from "./pr/index";
|
|
40
|
+
import { branchRenameCommand } from "./branch";
|
|
40
41
|
import {
|
|
41
42
|
releaseCreateCommand,
|
|
42
43
|
releaseDeleteCommand,
|
|
@@ -100,6 +101,11 @@ const issueCommand = Command.make("issue", {}).pipe(
|
|
|
100
101
|
]),
|
|
101
102
|
);
|
|
102
103
|
|
|
104
|
+
const branchCommand = Command.make("branch", {}).pipe(
|
|
105
|
+
Command.withDescription("Branch operations (rename)"),
|
|
106
|
+
Command.withSubcommands([branchRenameCommand]),
|
|
107
|
+
);
|
|
108
|
+
|
|
103
109
|
const repoCommand = Command.make("repo", {}).pipe(
|
|
104
110
|
Command.withDescription("Repository operations"),
|
|
105
111
|
Command.withSubcommands([repoInfoCommand, repoListCommand, repoSearchCodeCommand]),
|
|
@@ -162,9 +168,17 @@ WORKFLOW FOR AI AGENTS:
|
|
|
162
168
|
18. Use 'workflow watch --run N' to watch until completion
|
|
163
169
|
19. Use 'release status' to inspect latest release + repository context
|
|
164
170
|
20. Use 'release create --tag vX.Y.Z --generate-notes' to publish a release
|
|
165
|
-
21. Use 'release edit/view/list/delete' to maintain existing releases
|
|
171
|
+
21. Use 'release edit/view/list/delete' to maintain existing releases
|
|
172
|
+
22. Use 'branch rename --old-name X --new-name Y --confirm' to rename a branch`,
|
|
166
173
|
),
|
|
167
|
-
Command.withSubcommands([
|
|
174
|
+
Command.withSubcommands([
|
|
175
|
+
prCommand,
|
|
176
|
+
issueCommand,
|
|
177
|
+
repoCommand,
|
|
178
|
+
branchCommand,
|
|
179
|
+
workflowCommand,
|
|
180
|
+
releaseCommand,
|
|
181
|
+
]),
|
|
168
182
|
);
|
|
169
183
|
|
|
170
184
|
const cli = Command.run(mainCommand, {
|
package/src/gh-tool/types.ts
CHANGED
|
@@ -159,6 +159,14 @@ export type PRStatusNone = {
|
|
|
159
159
|
|
|
160
160
|
export type PRStatusResult = PRStatusSingle | PRStatusMultiple | PRStatusNone;
|
|
161
161
|
|
|
162
|
+
export type BranchRenameResult = {
|
|
163
|
+
renamed: boolean;
|
|
164
|
+
oldName: string;
|
|
165
|
+
newName: string;
|
|
166
|
+
dryRun?: true;
|
|
167
|
+
message?: string;
|
|
168
|
+
};
|
|
169
|
+
|
|
162
170
|
export type CheckRunAnnotation = {
|
|
163
171
|
path: string;
|
|
164
172
|
start_line: number;
|