diff --git a/automation/utils/bin/rui-oss-clearance.ts b/automation/utils/bin/rui-oss-clearance.ts index 16d7e4fac9..5058053c59 100755 --- a/automation/utils/bin/rui-oss-clearance.ts +++ b/automation/utils/bin/rui-oss-clearance.ts @@ -1,5 +1,8 @@ #!/usr/bin/env ts-node-script +// Enable quiet mode for fetch calls to reduce logging noise +process.env.FETCH_QUIET = "true"; + import { gh, GitHubDraftRelease, GitHubReleaseAsset } from "../src/github"; import { basename, join } from "path"; import { prompt } from "enquirer"; @@ -91,60 +94,66 @@ async function selectRelease(): Promise { printStep(2, 5, "Fetching draft releases..."); while (true) { + const currentRepo = gh.getRepo(); + printInfo(`Current repository: ${chalk.bold(currentRepo)}`); + const releases = await gh.getDraftReleases(); printSuccess(`Found ${releases.length} draft release${releases.length !== 1 ? "s" : ""}`); if (releases.length === 0) { printWarning("No draft releases found. Please create a draft release before trying again."); - - console.log(); // spacing - const { action } = await prompt<{ action: string }>({ - type: "select", - name: "action", - message: "What would you like to do?", - choices: [ - { name: "refresh", message: "--- Refresh the list ---" }, - { name: "exit", message: "❌ Exit" } - ] - }); - - if (action === "exit") { - throw new Error("No draft releases found"); - } - // If "refresh", continue the loop - continue; } console.log(); // spacing - const { tag_name } = await prompt<{ tag_name: string }>({ + const { selection } = await prompt<{ selection: string }>({ type: "select", - name: "tag_name", - message: "Select a release to process:", + name: "selection", + message: releases.length === 0 ? "What would you like to do?" : "Select a release to process:", choices: [ - ...releases.map(r => { - const assetNames = r.assets.map(a => a.name); - const hasReadmeOss = hasReadmeOssInAssets(assetNames); - const indicator = hasReadmeOss ? "✅" : ""; - return { - name: r.tag_name, - message: `${r.name} ${chalk.gray(`(${r.tag_name})`)} ${indicator} ` - }; - }), + ...(releases.length > 0 + ? releases.map(r => { + const assetNames = r.assets.map(a => a.name); + const hasReadmeOss = hasReadmeOssInAssets(assetNames); + const indicator = hasReadmeOss ? "✅" : ""; + return { + name: r.tag_name, + message: `${r.name} ${chalk.gray(`(${r.tag_name})`)} ${indicator} ` + }; + }) + : []), { name: "__refresh__", - message: chalk.cyan("--- Refresh the list ---") - } + message: chalk.dim("--- Refresh the list ---") + }, + { + name: "__switch_repo__", + message: chalk.dim("--- Switch repository ---") + }, + { name: "__exit__", message: chalk.dim("--- Exit ---") } ] }); - if (tag_name === "__refresh__") { + // Handle common actions + if (selection === "__refresh__") { printInfo("Refreshing draft releases list..."); - continue; // Loop again to fetch fresh data + continue; + } + + if (selection === "__switch_repo__") { + const newRepo = currentRepo === "web-widgets" ? "atlas" : "web-widgets"; + gh.setRepo(newRepo); + printInfo(`Switched to repository: ${chalk.bold(newRepo)}`); + continue; + } + + if (selection === "__exit__") { + throw new Error("No releases selected."); } - const release = releases.find(r => r.tag_name === tag_name); + // If we get here, it's a release tag_name + const release = releases.find(r => r.tag_name === selection); if (!release) { - throw new Error(`Release not found: ${tag_name}`); + throw new Error(`Release not found: ${selection}`); } printInfo(`Selected release: ${chalk.bold(release.name)}`); diff --git a/automation/utils/src/fetch.ts b/automation/utils/src/fetch.ts index c306afb050..90de7773b3 100644 --- a/automation/utils/src/fetch.ts +++ b/automation/utils/src/fetch.ts @@ -20,7 +20,12 @@ export async function fetch( body }; - console.log(`Fetching URL (${method}): ${url}`); + const isQuietMode = process.env.FETCH_QUIET === "true"; + + if (!isQuietMode) { + console.log(`Fetching URL (${method}): ${url}`); + } + try { response = await nodefetch(url, httpsOptions); } catch (error) { @@ -28,7 +33,11 @@ export async function fetch( `An error occurred while retrieving data from ${url}. Technical error: ${(error as Error).message}` ); } - console.log(`Response status Code ${response.status}`); + + if (!isQuietMode) { + console.log(`Response status Code ${response.status}`); + } + if (response.status === 409) { throw new Error( `Fetching Failed (Code ${response.status}). Possible solution: Check & delete drafts in Mendix Marketplace.` diff --git a/automation/utils/src/github.ts b/automation/utils/src/github.ts index 984e39d23f..44e6316106 100644 --- a/automation/utils/src/github.ts +++ b/automation/utils/src/github.ts @@ -55,6 +55,14 @@ export class GitHub { owner = "mendix"; repo = "web-widgets"; + setRepo(repo: string): void { + this.repo = repo; + } + + getRepo(): string { + return this.repo; + } + async ensureAuth(): Promise { if (!this.authSet) { if (process.env.GH_PAT) {