Skip to content

Commit 48ceab8

Browse files
authored
oss-prepare-script: allow switching to atlas repo, less logging (#2115)
2 parents 4fb97be + e3868ed commit 48ceab8

3 files changed

Lines changed: 63 additions & 37 deletions

File tree

automation/utils/bin/rui-oss-clearance.ts

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env ts-node-script
22

3+
// Enable quiet mode for fetch calls to reduce logging noise
4+
process.env.FETCH_QUIET = "true";
5+
36
import { gh, GitHubDraftRelease, GitHubReleaseAsset } from "../src/github";
47
import { basename, join } from "path";
58
import { prompt } from "enquirer";
@@ -91,60 +94,66 @@ async function selectRelease(): Promise<GitHubDraftRelease> {
9194
printStep(2, 5, "Fetching draft releases...");
9295

9396
while (true) {
97+
const currentRepo = gh.getRepo();
98+
printInfo(`Current repository: ${chalk.bold(currentRepo)}`);
99+
94100
const releases = await gh.getDraftReleases();
95101
printSuccess(`Found ${releases.length} draft release${releases.length !== 1 ? "s" : ""}`);
96102

97103
if (releases.length === 0) {
98104
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;
116105
}
117106

118107
console.log(); // spacing
119-
const { tag_name } = await prompt<{ tag_name: string }>({
108+
const { selection } = await prompt<{ selection: string }>({
120109
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:",
123112
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+
: []),
133124
{
134125
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 ---") }
137133
]
138134
});
139135

140-
if (tag_name === "__refresh__") {
136+
// Handle common actions
137+
if (selection === "__refresh__") {
141138
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.");
143151
}
144152

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);
146155
if (!release) {
147-
throw new Error(`Release not found: ${tag_name}`);
156+
throw new Error(`Release not found: ${selection}`);
148157
}
149158

150159
printInfo(`Selected release: ${chalk.bold(release.name)}`);

automation/utils/src/fetch.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ export async function fetch<T = unknown>(
2020
body
2121
};
2222

23-
console.log(`Fetching URL (${method}): ${url}`);
23+
const isQuietMode = process.env.FETCH_QUIET === "true";
24+
25+
if (!isQuietMode) {
26+
console.log(`Fetching URL (${method}): ${url}`);
27+
}
28+
2429
try {
2530
response = await nodefetch(url, httpsOptions);
2631
} catch (error) {
2732
throw new Error(
2833
`An error occurred while retrieving data from ${url}. Technical error: ${(error as Error).message}`
2934
);
3035
}
31-
console.log(`Response status Code ${response.status}`);
36+
37+
if (!isQuietMode) {
38+
console.log(`Response status Code ${response.status}`);
39+
}
40+
3241
if (response.status === 409) {
3342
throw new Error(
3443
`Fetching Failed (Code ${response.status}). Possible solution: Check & delete drafts in Mendix Marketplace.`

automation/utils/src/github.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ export class GitHub {
5555
owner = "mendix";
5656
repo = "web-widgets";
5757

58+
setRepo(repo: string): void {
59+
this.repo = repo;
60+
}
61+
62+
getRepo(): string {
63+
return this.repo;
64+
}
65+
5866
async ensureAuth(): Promise<void> {
5967
if (!this.authSet) {
6068
if (process.env.GH_PAT) {

0 commit comments

Comments
 (0)