Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 44 additions & 35 deletions automation/utils/bin/rui-oss-clearance.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -91,60 +94,66 @@ async function selectRelease(): Promise<GitHubDraftRelease> {
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)}`);
Expand Down
13 changes: 11 additions & 2 deletions automation/utils/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ export async function fetch<T = unknown>(
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) {
throw new Error(
`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.`
Expand Down
8 changes: 8 additions & 0 deletions automation/utils/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (!this.authSet) {
if (process.env.GH_PAT) {
Expand Down
Loading