|
1 | 1 | #!/usr/bin/env ts-node-script |
2 | 2 |
|
| 3 | +// Enable quiet mode for fetch calls to reduce logging noise |
| 4 | +process.env.FETCH_QUIET = "true"; |
| 5 | + |
3 | 6 | import { gh, GitHubDraftRelease, GitHubReleaseAsset } from "../src/github"; |
4 | 7 | import { basename, join } from "path"; |
5 | 8 | import { prompt } from "enquirer"; |
@@ -91,60 +94,66 @@ async function selectRelease(): Promise<GitHubDraftRelease> { |
91 | 94 | printStep(2, 5, "Fetching draft releases..."); |
92 | 95 |
|
93 | 96 | while (true) { |
| 97 | + const currentRepo = gh.getRepo(); |
| 98 | + printInfo(`Current repository: ${chalk.bold(currentRepo)}`); |
| 99 | + |
94 | 100 | const releases = await gh.getDraftReleases(); |
95 | 101 | printSuccess(`Found ${releases.length} draft release${releases.length !== 1 ? "s" : ""}`); |
96 | 102 |
|
97 | 103 | if (releases.length === 0) { |
98 | 104 | printWarning("No draft releases found. Please create a draft release before trying again."); |
99 | | - |
100 | | - console.log(); // spacing |
101 | | - const { action } = await prompt<{ action: string }>({ |
102 | | - type: "select", |
103 | | - name: "action", |
104 | | - message: "What would you like to do?", |
105 | | - choices: [ |
106 | | - { name: "refresh", message: "--- Refresh the list ---" }, |
107 | | - { name: "exit", message: "❌ Exit" } |
108 | | - ] |
109 | | - }); |
110 | | - |
111 | | - if (action === "exit") { |
112 | | - throw new Error("No draft releases found"); |
113 | | - } |
114 | | - // If "refresh", continue the loop |
115 | | - continue; |
116 | 105 | } |
117 | 106 |
|
118 | 107 | console.log(); // spacing |
119 | | - const { tag_name } = await prompt<{ tag_name: string }>({ |
| 108 | + const { selection } = await prompt<{ selection: string }>({ |
120 | 109 | type: "select", |
121 | | - name: "tag_name", |
122 | | - message: "Select a release to process:", |
| 110 | + name: "selection", |
| 111 | + message: releases.length === 0 ? "What would you like to do?" : "Select a release to process:", |
123 | 112 | choices: [ |
124 | | - ...releases.map(r => { |
125 | | - const assetNames = r.assets.map(a => a.name); |
126 | | - const hasReadmeOss = hasReadmeOssInAssets(assetNames); |
127 | | - const indicator = hasReadmeOss ? "✅" : ""; |
128 | | - return { |
129 | | - name: r.tag_name, |
130 | | - message: `${r.name} ${chalk.gray(`(${r.tag_name})`)} ${indicator} ` |
131 | | - }; |
132 | | - }), |
| 113 | + ...(releases.length > 0 |
| 114 | + ? releases.map(r => { |
| 115 | + const assetNames = r.assets.map(a => a.name); |
| 116 | + const hasReadmeOss = hasReadmeOssInAssets(assetNames); |
| 117 | + const indicator = hasReadmeOss ? "✅" : ""; |
| 118 | + return { |
| 119 | + name: r.tag_name, |
| 120 | + message: `${r.name} ${chalk.gray(`(${r.tag_name})`)} ${indicator} ` |
| 121 | + }; |
| 122 | + }) |
| 123 | + : []), |
133 | 124 | { |
134 | 125 | name: "__refresh__", |
135 | | - message: chalk.cyan("--- Refresh the list ---") |
136 | | - } |
| 126 | + message: chalk.dim("--- Refresh the list ---") |
| 127 | + }, |
| 128 | + { |
| 129 | + name: "__switch_repo__", |
| 130 | + message: chalk.dim("--- Switch repository ---") |
| 131 | + }, |
| 132 | + { name: "__exit__", message: chalk.dim("--- Exit ---") } |
137 | 133 | ] |
138 | 134 | }); |
139 | 135 |
|
140 | | - if (tag_name === "__refresh__") { |
| 136 | + // Handle common actions |
| 137 | + if (selection === "__refresh__") { |
141 | 138 | printInfo("Refreshing draft releases list..."); |
142 | | - continue; // Loop again to fetch fresh data |
| 139 | + continue; |
| 140 | + } |
| 141 | + |
| 142 | + if (selection === "__switch_repo__") { |
| 143 | + const newRepo = currentRepo === "web-widgets" ? "atlas" : "web-widgets"; |
| 144 | + gh.setRepo(newRepo); |
| 145 | + printInfo(`Switched to repository: ${chalk.bold(newRepo)}`); |
| 146 | + continue; |
| 147 | + } |
| 148 | + |
| 149 | + if (selection === "__exit__") { |
| 150 | + throw new Error("No releases selected."); |
143 | 151 | } |
144 | 152 |
|
145 | | - const release = releases.find(r => r.tag_name === tag_name); |
| 153 | + // If we get here, it's a release tag_name |
| 154 | + const release = releases.find(r => r.tag_name === selection); |
146 | 155 | if (!release) { |
147 | | - throw new Error(`Release not found: ${tag_name}`); |
| 156 | + throw new Error(`Release not found: ${selection}`); |
148 | 157 | } |
149 | 158 |
|
150 | 159 | printInfo(`Selected release: ${chalk.bold(release.name)}`); |
|
0 commit comments