@fuzdev/fuz_gitops 0.57.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.
Files changed (190) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -0
  3. package/dist/ModulesDetail.svelte +180 -0
  4. package/dist/ModulesDetail.svelte.d.ts +10 -0
  5. package/dist/ModulesDetail.svelte.d.ts.map +1 -0
  6. package/dist/ModulesNav.svelte +43 -0
  7. package/dist/ModulesNav.svelte.d.ts +11 -0
  8. package/dist/ModulesNav.svelte.d.ts.map +1 -0
  9. package/dist/ModulesPage.svelte +50 -0
  10. package/dist/ModulesPage.svelte.d.ts +9 -0
  11. package/dist/ModulesPage.svelte.d.ts.map +1 -0
  12. package/dist/PageFooter.svelte +15 -0
  13. package/dist/PageFooter.svelte.d.ts +19 -0
  14. package/dist/PageFooter.svelte.d.ts.map +1 -0
  15. package/dist/PageHeader.svelte +35 -0
  16. package/dist/PageHeader.svelte.d.ts +19 -0
  17. package/dist/PageHeader.svelte.d.ts.map +1 -0
  18. package/dist/PullRequestsDetail.svelte +53 -0
  19. package/dist/PullRequestsDetail.svelte.d.ts +10 -0
  20. package/dist/PullRequestsDetail.svelte.d.ts.map +1 -0
  21. package/dist/PullRequestsPage.svelte +47 -0
  22. package/dist/PullRequestsPage.svelte.d.ts +11 -0
  23. package/dist/PullRequestsPage.svelte.d.ts.map +1 -0
  24. package/dist/ReposTable.svelte +189 -0
  25. package/dist/ReposTable.svelte.d.ts +9 -0
  26. package/dist/ReposTable.svelte.d.ts.map +1 -0
  27. package/dist/ReposTree.svelte +88 -0
  28. package/dist/ReposTree.svelte.d.ts +11 -0
  29. package/dist/ReposTree.svelte.d.ts.map +1 -0
  30. package/dist/ReposTreeNav.svelte +55 -0
  31. package/dist/ReposTreeNav.svelte.d.ts +11 -0
  32. package/dist/ReposTreeNav.svelte.d.ts.map +1 -0
  33. package/dist/TablePage.svelte +46 -0
  34. package/dist/TablePage.svelte.d.ts +9 -0
  35. package/dist/TablePage.svelte.d.ts.map +1 -0
  36. package/dist/TreeItemPage.svelte +75 -0
  37. package/dist/TreeItemPage.svelte.d.ts +10 -0
  38. package/dist/TreeItemPage.svelte.d.ts.map +1 -0
  39. package/dist/TreePage.svelte +64 -0
  40. package/dist/TreePage.svelte.d.ts +9 -0
  41. package/dist/TreePage.svelte.d.ts.map +1 -0
  42. package/dist/changeset_generator.d.ts +38 -0
  43. package/dist/changeset_generator.d.ts.map +1 -0
  44. package/dist/changeset_generator.js +110 -0
  45. package/dist/changeset_reader.d.ts +75 -0
  46. package/dist/changeset_reader.d.ts.map +1 -0
  47. package/dist/changeset_reader.js +167 -0
  48. package/dist/constants.d.ts +9 -0
  49. package/dist/constants.d.ts.map +1 -0
  50. package/dist/constants.js +8 -0
  51. package/dist/dependency_graph.d.ts +120 -0
  52. package/dist/dependency_graph.d.ts.map +1 -0
  53. package/dist/dependency_graph.js +341 -0
  54. package/dist/dependency_updater.d.ts +46 -0
  55. package/dist/dependency_updater.d.ts.map +1 -0
  56. package/dist/dependency_updater.js +213 -0
  57. package/dist/fetch_repo_data.d.ts +19 -0
  58. package/dist/fetch_repo_data.d.ts.map +1 -0
  59. package/dist/fetch_repo_data.js +49 -0
  60. package/dist/fs_fetch_value_cache.d.ts +24 -0
  61. package/dist/fs_fetch_value_cache.d.ts.map +1 -0
  62. package/dist/fs_fetch_value_cache.js +61 -0
  63. package/dist/git_operations.d.ts +54 -0
  64. package/dist/git_operations.d.ts.map +1 -0
  65. package/dist/git_operations.js +144 -0
  66. package/dist/github.d.ts +91 -0
  67. package/dist/github.d.ts.map +1 -0
  68. package/dist/github.js +94 -0
  69. package/dist/github_helpers.d.ts +10 -0
  70. package/dist/github_helpers.d.ts.map +1 -0
  71. package/dist/github_helpers.js +13 -0
  72. package/dist/gitops_analyze.task.d.ts +17 -0
  73. package/dist/gitops_analyze.task.d.ts.map +1 -0
  74. package/dist/gitops_analyze.task.js +188 -0
  75. package/dist/gitops_config.d.ts +56 -0
  76. package/dist/gitops_config.d.ts.map +1 -0
  77. package/dist/gitops_config.js +63 -0
  78. package/dist/gitops_plan.task.d.ts +28 -0
  79. package/dist/gitops_plan.task.d.ts.map +1 -0
  80. package/dist/gitops_plan.task.js +217 -0
  81. package/dist/gitops_publish.task.d.ts +29 -0
  82. package/dist/gitops_publish.task.d.ts.map +1 -0
  83. package/dist/gitops_publish.task.js +178 -0
  84. package/dist/gitops_sync.task.d.ts +18 -0
  85. package/dist/gitops_sync.task.d.ts.map +1 -0
  86. package/dist/gitops_sync.task.js +95 -0
  87. package/dist/gitops_task_helpers.d.ts +63 -0
  88. package/dist/gitops_task_helpers.d.ts.map +1 -0
  89. package/dist/gitops_task_helpers.js +84 -0
  90. package/dist/gitops_validate.task.d.ts +12 -0
  91. package/dist/gitops_validate.task.d.ts.map +1 -0
  92. package/dist/gitops_validate.task.js +210 -0
  93. package/dist/graph_validation.d.ts +39 -0
  94. package/dist/graph_validation.d.ts.map +1 -0
  95. package/dist/graph_validation.js +79 -0
  96. package/dist/local_repo.d.ts +84 -0
  97. package/dist/local_repo.d.ts.map +1 -0
  98. package/dist/local_repo.js +213 -0
  99. package/dist/log_helpers.d.ts +43 -0
  100. package/dist/log_helpers.d.ts.map +1 -0
  101. package/dist/log_helpers.js +98 -0
  102. package/dist/multi_repo_publisher.d.ts +34 -0
  103. package/dist/multi_repo_publisher.d.ts.map +1 -0
  104. package/dist/multi_repo_publisher.js +364 -0
  105. package/dist/npm_install_helpers.d.ts +23 -0
  106. package/dist/npm_install_helpers.d.ts.map +1 -0
  107. package/dist/npm_install_helpers.js +60 -0
  108. package/dist/npm_registry.d.ts +46 -0
  109. package/dist/npm_registry.d.ts.map +1 -0
  110. package/dist/npm_registry.js +96 -0
  111. package/dist/operations.d.ts +409 -0
  112. package/dist/operations.d.ts.map +1 -0
  113. package/dist/operations.js +34 -0
  114. package/dist/operations_defaults.d.ts +19 -0
  115. package/dist/operations_defaults.d.ts.map +1 -0
  116. package/dist/operations_defaults.js +279 -0
  117. package/dist/output_helpers.d.ts +27 -0
  118. package/dist/output_helpers.d.ts.map +1 -0
  119. package/dist/output_helpers.js +39 -0
  120. package/dist/paths.d.ts +11 -0
  121. package/dist/paths.d.ts.map +1 -0
  122. package/dist/paths.js +10 -0
  123. package/dist/preflight_checks.d.ts +47 -0
  124. package/dist/preflight_checks.d.ts.map +1 -0
  125. package/dist/preflight_checks.js +181 -0
  126. package/dist/publishing_plan.d.ts +100 -0
  127. package/dist/publishing_plan.d.ts.map +1 -0
  128. package/dist/publishing_plan.js +353 -0
  129. package/dist/publishing_plan_helpers.d.ts +30 -0
  130. package/dist/publishing_plan_helpers.d.ts.map +1 -0
  131. package/dist/publishing_plan_helpers.js +112 -0
  132. package/dist/publishing_plan_logging.d.ts +18 -0
  133. package/dist/publishing_plan_logging.d.ts.map +1 -0
  134. package/dist/publishing_plan_logging.js +342 -0
  135. package/dist/repo.svelte.d.ts +52 -0
  136. package/dist/repo.svelte.d.ts.map +1 -0
  137. package/dist/repo.svelte.js +70 -0
  138. package/dist/repo_ops.d.ts +57 -0
  139. package/dist/repo_ops.d.ts.map +1 -0
  140. package/dist/repo_ops.js +167 -0
  141. package/dist/resolved_gitops_config.d.ts +9 -0
  142. package/dist/resolved_gitops_config.d.ts.map +1 -0
  143. package/dist/resolved_gitops_config.js +12 -0
  144. package/dist/semver.d.ts +24 -0
  145. package/dist/semver.d.ts.map +1 -0
  146. package/dist/semver.js +140 -0
  147. package/dist/serialization_types.d.ts +57 -0
  148. package/dist/serialization_types.d.ts.map +1 -0
  149. package/dist/serialization_types.js +40 -0
  150. package/dist/version_utils.d.ts +48 -0
  151. package/dist/version_utils.d.ts.map +1 -0
  152. package/dist/version_utils.js +125 -0
  153. package/package.json +107 -0
  154. package/src/lib/changeset_generator.ts +162 -0
  155. package/src/lib/changeset_reader.ts +218 -0
  156. package/src/lib/constants.ts +8 -0
  157. package/src/lib/dependency_graph.ts +423 -0
  158. package/src/lib/dependency_updater.ts +297 -0
  159. package/src/lib/fetch_repo_data.ts +64 -0
  160. package/src/lib/fs_fetch_value_cache.ts +75 -0
  161. package/src/lib/git_operations.ts +208 -0
  162. package/src/lib/github.ts +128 -0
  163. package/src/lib/github_helpers.ts +31 -0
  164. package/src/lib/gitops_analyze.task.ts +261 -0
  165. package/src/lib/gitops_config.ts +123 -0
  166. package/src/lib/gitops_plan.task.ts +272 -0
  167. package/src/lib/gitops_publish.task.ts +227 -0
  168. package/src/lib/gitops_sync.task.ts +109 -0
  169. package/src/lib/gitops_task_helpers.ts +126 -0
  170. package/src/lib/gitops_validate.task.ts +248 -0
  171. package/src/lib/graph_validation.ts +109 -0
  172. package/src/lib/local_repo.ts +359 -0
  173. package/src/lib/log_helpers.ts +147 -0
  174. package/src/lib/multi_repo_publisher.ts +464 -0
  175. package/src/lib/npm_install_helpers.ts +85 -0
  176. package/src/lib/npm_registry.ts +143 -0
  177. package/src/lib/operations.ts +334 -0
  178. package/src/lib/operations_defaults.ts +335 -0
  179. package/src/lib/output_helpers.ts +64 -0
  180. package/src/lib/paths.ts +11 -0
  181. package/src/lib/preflight_checks.ts +269 -0
  182. package/src/lib/publishing_plan.ts +531 -0
  183. package/src/lib/publishing_plan_helpers.ts +145 -0
  184. package/src/lib/publishing_plan_logging.ts +470 -0
  185. package/src/lib/repo.svelte.ts +95 -0
  186. package/src/lib/repo_ops.ts +213 -0
  187. package/src/lib/resolved_gitops_config.ts +27 -0
  188. package/src/lib/semver.ts +166 -0
  189. package/src/lib/serialization_types.ts +90 -0
  190. package/src/lib/version_utils.ts +150 -0
@@ -0,0 +1,24 @@
1
+ import { type FetchValueCache } from '@fuzdev/fuz_util/fetch.js';
2
+ export interface FetchCache {
3
+ name: string;
4
+ data: FetchValueCache;
5
+ /**
6
+ * @returns true if anything changed, false if no-op
7
+ */
8
+ save: () => Promise<boolean>;
9
+ }
10
+ /**
11
+ * Creates file-system backed cache for belt's fetch.js API responses.
12
+ *
13
+ * Cache invalidation strategy: If cache file can't be read or parsed, entire
14
+ * cache is cleared (delete file) and starts fresh. This handles format changes.
15
+ *
16
+ * Uses `structuredClone` to track changes - only writes to disk if data modified.
17
+ * Formatted with Prettier before writing for version control friendliness.
18
+ *
19
+ * @param name cache filename (without .json extension)
20
+ * @param dir cache directory (defaults to `.gro/build/fetch/`)
21
+ * @returns cache object with Map-based data and save() method
22
+ */
23
+ export declare const create_fs_fetch_value_cache: (name: string, dir?: string) => Promise<FetchCache>;
24
+ //# sourceMappingURL=fs_fetch_value_cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs_fetch_value_cache.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/fs_fetch_value_cache.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqC,KAAK,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAKnG,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,eAAe,CAAC;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7B;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,2BAA2B,GACvC,MAAM,MAAM,EACZ,YAAgC,KAC9B,OAAO,CAAC,UAAU,CA2BpB,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
2
+ import { dirname, join } from 'node:path';
3
+ import { paths } from '@ryanatkn/gro/paths.js';
4
+ import { format_file } from '@ryanatkn/gro/format_file.js';
5
+ import { deserialize_cache, serialize_cache } from '@fuzdev/fuz_util/fetch.js';
6
+ import { existsSync } from 'node:fs';
7
+ /**
8
+ * Creates file-system backed cache for belt's fetch.js API responses.
9
+ *
10
+ * Cache invalidation strategy: If cache file can't be read or parsed, entire
11
+ * cache is cleared (delete file) and starts fresh. This handles format changes.
12
+ *
13
+ * Uses `structuredClone` to track changes - only writes to disk if data modified.
14
+ * Formatted with Prettier before writing for version control friendliness.
15
+ *
16
+ * @param name cache filename (without .json extension)
17
+ * @param dir cache directory (defaults to `.gro/build/fetch/`)
18
+ * @returns cache object with Map-based data and save() method
19
+ */
20
+ export const create_fs_fetch_value_cache = async (name, dir = join(paths.build, 'fetch')) => {
21
+ const data_path = join(dir, name + '.json');
22
+ let data;
23
+ if (existsSync(data_path)) {
24
+ try {
25
+ data = deserialize_cache(await readFile(data_path, 'utf8')); // TODO pass schema to parse so failures invalidate the cache
26
+ }
27
+ catch (_err) {
28
+ // something went wrong, maybe the data format changed, so clear the cache
29
+ data = new Map();
30
+ await rm(data_path);
31
+ }
32
+ }
33
+ else {
34
+ data = new Map();
35
+ }
36
+ const initial = structuredClone(data);
37
+ return {
38
+ name,
39
+ data,
40
+ save: async () => {
41
+ if (deep_equal_maps(initial, data)) {
42
+ return false; // no changes to save
43
+ }
44
+ await mkdir(dirname(data_path), { recursive: true });
45
+ await writeFile(data_path, await format_file(serialize_cache(data), { filepath: data_path }));
46
+ return true;
47
+ },
48
+ };
49
+ };
50
+ // TODO this is quick and dirty, but fine because it's only expected to be called during development
51
+ const deep_equal_maps = (a, b) => {
52
+ if (a.size !== b.size) {
53
+ return false;
54
+ }
55
+ for (const [key, value] of a) {
56
+ if (!b.has(key) || JSON.stringify(b.get(key)) !== JSON.stringify(value)) {
57
+ return false;
58
+ }
59
+ }
60
+ return true;
61
+ };
@@ -0,0 +1,54 @@
1
+ import type { SpawnOptions } from 'node:child_process';
2
+ import { type GitBranch, type GitOrigin } from '@fuzdev/fuz_util/git.js';
3
+ /**
4
+ * Adds files to git staging area and throws if anything goes wrong.
5
+ */
6
+ export declare const git_add: (files: string | Array<string>, options?: SpawnOptions) => Promise<void>;
7
+ /**
8
+ * Commits staged changes with a message and throws if anything goes wrong.
9
+ */
10
+ export declare const git_commit: (message: string, options?: SpawnOptions) => Promise<void>;
11
+ /**
12
+ * Adds files and commits in one operation and throws if anything goes wrong.
13
+ */
14
+ export declare const git_add_and_commit: (files: string | Array<string>, message: string, options?: SpawnOptions) => Promise<void>;
15
+ /**
16
+ * Creates a git tag and throws if anything goes wrong.
17
+ */
18
+ export declare const git_tag: (tag_name: string, message?: string, options?: SpawnOptions) => Promise<void>;
19
+ /**
20
+ * Pushes a tag to origin and throws if anything goes wrong.
21
+ */
22
+ export declare const git_push_tag: (tag_name: string, origin?: GitOrigin, options?: SpawnOptions) => Promise<void>;
23
+ export declare const git_has_changes: (options?: SpawnOptions) => Promise<boolean>;
24
+ /**
25
+ * Returns list of changed files compared to HEAD.
26
+ */
27
+ export declare const git_get_changed_files: (options?: SpawnOptions) => Promise<Array<string>>;
28
+ export declare const git_has_file_changed: (from_commit: string, to_commit: string, file_path: string, options?: SpawnOptions) => Promise<boolean>;
29
+ /**
30
+ * Stashes current changes and throws if anything goes wrong.
31
+ */
32
+ export declare const git_stash: (message?: string, options?: SpawnOptions) => Promise<void>;
33
+ /**
34
+ * Applies stashed changes and throws if anything goes wrong.
35
+ */
36
+ export declare const git_stash_pop: (options?: SpawnOptions) => Promise<void>;
37
+ /**
38
+ * Switches to a branch with safety checks and throws if workspace is not clean.
39
+ */
40
+ export declare const git_switch_branch: (branch: GitBranch, pull?: boolean, options?: SpawnOptions) => Promise<void>;
41
+ /**
42
+ * Wrapper for gro's git_current_branch_name that throws if null.
43
+ */
44
+ export declare const git_current_branch_name_required: (options?: SpawnOptions) => Promise<string>;
45
+ /**
46
+ * Wrapper for gro's git_current_commit_hash that throws if null.
47
+ */
48
+ export declare const git_current_commit_hash_required: (branch?: string, options?: SpawnOptions) => Promise<string>;
49
+ /**
50
+ * Wrapper for gro's git_check_clean_workspace that returns a boolean.
51
+ */
52
+ export declare const git_check_clean_workspace_as_boolean: (options?: SpawnOptions) => Promise<boolean>;
53
+ export declare const git_has_remote: (remote?: string, options?: SpawnOptions) => Promise<boolean>;
54
+ //# sourceMappingURL=git_operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git_operations.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/git_operations.ts"],"names":[],"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AC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAU,UAAU,YAAY,KAAG,OAAO,CAAC,IAAI,CAKxE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC7B,QAAQ,SAAS,EACjB,OAAM,OAAc,EACpB,UAAU,YAAY,KACpB,OAAO,CAAC,IAAI,CAoBd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC,GAAU,UAAU,YAAY,KAAG,OAAO,CAAC,MAAM,CAM7F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC,GAC5C,SAAS,MAAM,EACf,UAAU,YAAY,KACpB,OAAO,CAAC,MAAM,CAMhB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oCAAoC,GAChD,UAAU,YAAY,KACpB,OAAO,CAAC,OAAO,CAGjB,CAAC;AAEF,eAAO,MAAM,cAAc,GAC1B,SAAQ,MAAiB,EACzB,UAAU,YAAY,KACpB,OAAO,CAAC,OAAO,CAQjB,CAAC"}
@@ -0,0 +1,144 @@
1
+ import { spawn, spawn_out } from '@fuzdev/fuz_util/process.js';
2
+ import { git_check_clean_workspace as gro_git_check_clean_workspace, git_checkout as gro_git_checkout, git_pull as gro_git_pull, git_current_branch_name as gro_git_current_branch_name, git_current_commit_hash as gro_git_current_commit_hash, } from '@fuzdev/fuz_util/git.js';
3
+ /**
4
+ * Adds files to git staging area and throws if anything goes wrong.
5
+ */
6
+ export const git_add = async (files, options) => {
7
+ const file_list = Array.isArray(files) ? files : [files];
8
+ const result = await spawn('git', ['add', ...file_list], options);
9
+ if (!result.ok) {
10
+ throw Error(`git_add failed with code ${result.code}`);
11
+ }
12
+ };
13
+ /**
14
+ * Commits staged changes with a message and throws if anything goes wrong.
15
+ */
16
+ export const git_commit = async (message, options) => {
17
+ const result = await spawn('git', ['commit', '-m', message], options);
18
+ if (!result.ok) {
19
+ throw Error(`git_commit failed with code ${result.code}`);
20
+ }
21
+ };
22
+ /**
23
+ * Adds files and commits in one operation and throws if anything goes wrong.
24
+ */
25
+ export const git_add_and_commit = async (files, message, options) => {
26
+ await git_add(files, options);
27
+ await git_commit(message, options);
28
+ };
29
+ /**
30
+ * Creates a git tag and throws if anything goes wrong.
31
+ */
32
+ export const git_tag = async (tag_name, message, options) => {
33
+ const args = message ? ['tag', '-a', tag_name, '-m', message] : ['tag', tag_name];
34
+ const result = await spawn('git', args, options);
35
+ if (!result.ok) {
36
+ throw Error(`git_tag failed for tag '${tag_name}' with code ${result.code}`);
37
+ }
38
+ };
39
+ /**
40
+ * Pushes a tag to origin and throws if anything goes wrong.
41
+ */
42
+ export const git_push_tag = async (tag_name, origin = 'origin', options) => {
43
+ const result = await spawn('git', ['push', origin, tag_name], options);
44
+ if (!result.ok) {
45
+ throw Error(`git_push_tag failed for tag '${tag_name}' with code ${result.code}`);
46
+ }
47
+ };
48
+ export const git_has_changes = async (options) => {
49
+ const { stdout } = await spawn_out('git', ['status', '--porcelain'], options);
50
+ return stdout ? stdout.trim().length > 0 : false;
51
+ };
52
+ /**
53
+ * Returns list of changed files compared to HEAD.
54
+ */
55
+ export const git_get_changed_files = async (options) => {
56
+ const { stdout } = await spawn_out('git', ['diff', '--name-only', 'HEAD'], options);
57
+ if (!stdout)
58
+ return [];
59
+ return stdout
60
+ .split('\n')
61
+ .map((f) => f.trim())
62
+ .filter(Boolean);
63
+ };
64
+ export const git_has_file_changed = async (from_commit, to_commit, file_path, options) => {
65
+ const { stdout } = await spawn_out('git', ['diff', '--name-only', from_commit, to_commit, '--', file_path], options);
66
+ return stdout ? stdout.trim().length > 0 : false;
67
+ };
68
+ /**
69
+ * Stashes current changes and throws if anything goes wrong.
70
+ */
71
+ export const git_stash = async (message, options) => {
72
+ const args = message ? ['stash', 'push', '-m', message] : ['stash', 'push'];
73
+ const result = await spawn('git', args, options);
74
+ if (!result.ok) {
75
+ throw Error(`git_stash failed with code ${result.code}`);
76
+ }
77
+ };
78
+ /**
79
+ * Applies stashed changes and throws if anything goes wrong.
80
+ */
81
+ export const git_stash_pop = async (options) => {
82
+ const result = await spawn('git', ['stash', 'pop'], options);
83
+ if (!result.ok) {
84
+ throw Error(`git_stash_pop failed with code ${result.code}`);
85
+ }
86
+ };
87
+ /**
88
+ * Switches to a branch with safety checks and throws if workspace is not clean.
89
+ */
90
+ export const git_switch_branch = async (branch, pull = true, options) => {
91
+ // Check if workspace is clean first
92
+ const error = await gro_git_check_clean_workspace(options);
93
+ if (error) {
94
+ throw Error(`Cannot switch branch: ${error}`);
95
+ }
96
+ // Checkout the branch
97
+ await gro_git_checkout(branch, options);
98
+ // Pull latest changes if requested
99
+ if (pull) {
100
+ await gro_git_pull(undefined, undefined, options);
101
+ }
102
+ // Verify workspace is still clean
103
+ const error_after = await gro_git_check_clean_workspace(options);
104
+ if (error_after) {
105
+ throw Error(`Workspace unclean after switching to ${branch}: ${error_after}`);
106
+ }
107
+ };
108
+ /**
109
+ * Wrapper for gro's git_current_branch_name that throws if null.
110
+ */
111
+ export const git_current_branch_name_required = async (options) => {
112
+ const branch = await gro_git_current_branch_name(options);
113
+ if (!branch) {
114
+ throw new Error('Failed to get current branch name');
115
+ }
116
+ return branch;
117
+ };
118
+ /**
119
+ * Wrapper for gro's git_current_commit_hash that throws if null.
120
+ */
121
+ export const git_current_commit_hash_required = async (branch, options) => {
122
+ const hash = await gro_git_current_commit_hash(branch, options);
123
+ if (!hash) {
124
+ throw new Error(`Failed to get commit hash for branch: ${branch || 'current'}`);
125
+ }
126
+ return hash;
127
+ };
128
+ /**
129
+ * Wrapper for gro's git_check_clean_workspace that returns a boolean.
130
+ */
131
+ export const git_check_clean_workspace_as_boolean = async (options) => {
132
+ const error = await gro_git_check_clean_workspace(options);
133
+ return error === null;
134
+ };
135
+ export const git_has_remote = async (remote = 'origin', options) => {
136
+ const { stdout } = await spawn_out('git', ['remote'], options);
137
+ if (!stdout)
138
+ return false;
139
+ const remotes = stdout
140
+ .split('\n')
141
+ .map((r) => r.trim())
142
+ .filter(Boolean);
143
+ return remotes.includes(remote);
144
+ };
@@ -0,0 +1,91 @@
1
+ import type { Logger } from '@fuzdev/fuz_util/log.js';
2
+ import { z } from 'zod';
3
+ import { type FetchValueCache } from '@fuzdev/fuz_util/fetch.js';
4
+ /**
5
+ * Minimal interface for GitHub API calls - works with both Pkg and Repo.
6
+ */
7
+ export interface GithubRepoInfo {
8
+ owner_name: string | null;
9
+ repo_name: string;
10
+ }
11
+ /**
12
+ * @see https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
13
+ */
14
+ export declare const GithubPullRequest: z.ZodObject<{
15
+ number: z.ZodNumber;
16
+ title: z.ZodString;
17
+ user: z.ZodObject<{
18
+ login: z.ZodString;
19
+ }, z.core.$strip>;
20
+ draft: z.ZodBoolean;
21
+ }, z.core.$strip>;
22
+ export type GithubPullRequest = z.infer<typeof GithubPullRequest>;
23
+ export declare const GithubPullRequests: z.ZodArray<z.ZodObject<{
24
+ number: z.ZodNumber;
25
+ title: z.ZodString;
26
+ user: z.ZodObject<{
27
+ login: z.ZodString;
28
+ }, z.core.$strip>;
29
+ draft: z.ZodBoolean;
30
+ }, z.core.$strip>>;
31
+ export type GithubPullRequests = z.infer<typeof GithubPullRequests>;
32
+ /**
33
+ * @see https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
34
+ */
35
+ export declare const fetch_github_pull_requests: (repo_info: GithubRepoInfo, options?: {
36
+ cache?: FetchValueCache;
37
+ log?: Logger;
38
+ token?: string;
39
+ api_version?: string;
40
+ }) => Promise<GithubPullRequests | null>;
41
+ /**
42
+ * @see https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
43
+ */
44
+ export declare const GithubCheckRunsItem: z.ZodObject<{
45
+ status: z.ZodEnum<{
46
+ queued: "queued";
47
+ in_progress: "in_progress";
48
+ completed: "completed";
49
+ }>;
50
+ conclusion: z.ZodNullable<z.ZodEnum<{
51
+ success: "success";
52
+ failure: "failure";
53
+ neutral: "neutral";
54
+ cancelled: "cancelled";
55
+ skipped: "skipped";
56
+ timed_out: "timed_out";
57
+ action_required: "action_required";
58
+ }>>;
59
+ }, z.core.$strip>;
60
+ export type GithubCheckRunsItem = z.infer<typeof GithubCheckRunsItem>;
61
+ export declare const GithubCheckRuns: z.ZodObject<{
62
+ total_count: z.ZodNumber;
63
+ check_runs: z.ZodArray<z.ZodObject<{
64
+ status: z.ZodEnum<{
65
+ queued: "queued";
66
+ in_progress: "in_progress";
67
+ completed: "completed";
68
+ }>;
69
+ conclusion: z.ZodNullable<z.ZodEnum<{
70
+ success: "success";
71
+ failure: "failure";
72
+ neutral: "neutral";
73
+ cancelled: "cancelled";
74
+ skipped: "skipped";
75
+ timed_out: "timed_out";
76
+ action_required: "action_required";
77
+ }>>;
78
+ }, z.core.$strip>>;
79
+ }, z.core.$strip>;
80
+ export type GithubCheckRuns = z.infer<typeof GithubCheckRuns>;
81
+ /**
82
+ * @see https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
83
+ */
84
+ export declare const fetch_github_check_runs: (repo_info: GithubRepoInfo, options?: {
85
+ cache?: FetchValueCache;
86
+ log?: Logger;
87
+ token?: string;
88
+ api_version?: string;
89
+ ref?: string;
90
+ }) => Promise<GithubCheckRunsItem | null>;
91
+ //# sourceMappingURL=github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/github.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAc,KAAK,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,eAA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.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
5
+ */
6
+ export const GithubPullRequest = z.object({
7
+ number: z.number(),
8
+ title: z.string(),
9
+ user: z.object({
10
+ login: z.string(),
11
+ }),
12
+ draft: z.boolean(),
13
+ });
14
+ export const GithubPullRequests = z.array(GithubPullRequest);
15
+ /**
16
+ * @see https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
17
+ */
18
+ export const fetch_github_pull_requests = async (repo_info, options = {}) => {
19
+ const { cache, log, token, api_version } = options;
20
+ if (!repo_info.owner_name)
21
+ throw Error('owner_name is required');
22
+ const headers = api_version ? new Headers({ 'x-github-api-version': api_version }) : undefined;
23
+ const url = `https://api.github.com/repos/${repo_info.owner_name}/${repo_info.repo_name}/pulls`;
24
+ const fetched = await fetch_value(url, {
25
+ request: { headers },
26
+ parse: GithubPullRequests.parse,
27
+ token,
28
+ cache,
29
+ log,
30
+ });
31
+ if (!fetched.ok) {
32
+ // TODO @many this is messy but I think it's the main case we need to worry about?
33
+ if (fetched.status === 401) {
34
+ throw Error('401 response fetching github pull requests - check your SECRET_GITHUB_API_TOKEN');
35
+ }
36
+ return null;
37
+ }
38
+ return fetched.value;
39
+ };
40
+ /**
41
+ * @see https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
42
+ */
43
+ export const GithubCheckRunsItem = z.object({
44
+ status: z.enum(['queued', 'in_progress', 'completed']),
45
+ conclusion: z
46
+ .enum(['success', 'failure', 'neutral', 'cancelled', 'skipped', 'timed_out', 'action_required'])
47
+ .nullable(),
48
+ });
49
+ export const GithubCheckRuns = z.object({
50
+ total_count: z.number(),
51
+ check_runs: z.array(GithubCheckRunsItem),
52
+ });
53
+ /**
54
+ * @see https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
55
+ */
56
+ export const fetch_github_check_runs = async (repo_info, options = {}) => {
57
+ const { cache, log, token, api_version, ref = 'main' } = options;
58
+ if (!repo_info.owner_name)
59
+ throw Error('owner_name is required');
60
+ const headers = api_version ? new Headers({ 'x-github-api-version': api_version }) : undefined;
61
+ const url = `https://api.github.com/repos/${repo_info.owner_name}/${repo_info.repo_name}/commits/${ref}/check-runs`;
62
+ const fetched = await fetch_value(url, {
63
+ request: { headers },
64
+ parse: (v) => reduce_check_runs(GithubCheckRuns.parse(v).check_runs),
65
+ token,
66
+ cache,
67
+ log,
68
+ });
69
+ if (!fetched.ok) {
70
+ // TODO @many this is messy but I think it's the main case we need to worry about?
71
+ if (fetched.status === 401) {
72
+ throw Error('401 response fetching github CI status - check your SECRET_GITHUB_API_TOKEN');
73
+ }
74
+ return null;
75
+ }
76
+ return fetched.value;
77
+ };
78
+ const reduce_check_runs = (check_runs) => {
79
+ if (!check_runs.length)
80
+ return null;
81
+ // TODO fix these types and remove the eslint disable, `GithubCheckRunsItem` should maybe have nullable properties?
82
+ let status;
83
+ let conclusion;
84
+ for (const check_run of check_runs) {
85
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
86
+ if (!status || status === 'completed') {
87
+ status = check_run.status;
88
+ }
89
+ if (!conclusion || conclusion === 'success') {
90
+ conclusion = check_run.conclusion;
91
+ }
92
+ }
93
+ return { status, conclusion };
94
+ };
@@ -0,0 +1,10 @@
1
+ import type { GithubPullRequest } from './github.js';
2
+ import type { Repo } from './repo.svelte.js';
3
+ export type FilterPullRequest = (pull_request: GithubPullRequest, repo: Repo) => boolean;
4
+ export interface PullRequestMeta {
5
+ repo: Repo;
6
+ pull_request: GithubPullRequest;
7
+ }
8
+ export declare const to_pull_requests: (repos: Array<Repo>, filter_pull_request?: FilterPullRequest) => Array<PullRequestMeta>;
9
+ export declare const to_pull_url: (repo_url: string, pull: GithubPullRequest) => string;
10
+ //# sourceMappingURL=github_helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/github_helpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,kBAAkB,CAAC;AAE3C,MAAM,MAAM,iBAAiB,GAAG,CAAC,YAAY,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;AAEzF,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,IAAI,CAAC;IACX,YAAY,EAAE,iBAAiB,CAAC;CAChC;AAED,eAAO,MAAM,gBAAgB,GAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,EAClB,sBAAsB,iBAAiB,KACrC,KAAK,CAAC,eAAe,CAYI,CAAC;AAE7B,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,EAAE,MAAM,iBAAiB,KAAG,MACtB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { ensure_end } from '@fuzdev/fuz_util/string.js';
2
+ export const to_pull_requests = (repos, filter_pull_request) => repos
3
+ .flatMap((repo) => {
4
+ if (!repo.pull_requests)
5
+ return null;
6
+ // TODO hacky, figure out the data structure
7
+ return repo.pull_requests.map((pull_request) => repo.package_json.homepage &&
8
+ (!filter_pull_request || filter_pull_request(pull_request, repo))
9
+ ? { repo, pull_request }
10
+ : null);
11
+ })
12
+ .filter((v) => v !== null);
13
+ export const to_pull_url = (repo_url, pull) => ensure_end(repo_url, '/') + 'pull/' + pull.number;
@@ -0,0 +1,17 @@
1
+ import type { Task } from '@ryanatkn/gro';
2
+ import { z } from 'zod';
3
+ /** @nodocs */
4
+ export declare const Args: z.ZodObject<{
5
+ path: z.ZodDefault<z.ZodString>;
6
+ dir: z.ZodOptional<z.ZodString>;
7
+ format: z.ZodDefault<z.ZodEnum<{
8
+ json: "json";
9
+ stdout: "stdout";
10
+ markdown: "markdown";
11
+ }>>;
12
+ outfile: z.ZodOptional<z.ZodString>;
13
+ }, z.core.$strict>;
14
+ export type Args = z.infer<typeof Args>;
15
+ /** @nodocs */
16
+ export declare const task: Task<Args>;
17
+ //# sourceMappingURL=gitops_analyze.task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitops_analyze.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gitops_analyze.task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACxC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAetB,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;;;;kBAcf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CAkC3B,CAAC"}