Last active
March 24, 2025 22:04
-
-
Save toky-nomena/9d085d327bec593906d0daf6ac0b781c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { exec } = require("child_process"); | |
| const path = require("path"); | |
| // Base directory for repositories | |
| const baseDir = path.resolve("~/dev/projects"); | |
| // List of repositories (relative to baseDir) | |
| const repositories = [ | |
| "repo-1", | |
| "repo-2" | |
| ]; | |
| // Branches to compare | |
| const branch1 = "origin/rc/1.0"; | |
| const branch2 = "origin/rc/2.0"; | |
| function getLatestTag(repoPath, branch) { | |
| return new Promise((resolve) => { | |
| exec("git fetch --tags", { cwd: repoPath }, (fetchErr) => { | |
| if (fetchErr) { | |
| return resolve(colorize(`Error fetching tags: ${fetchErr.message}`, 31)); // Red | |
| } | |
| // git describe --tags $(git rev-list --tags --max-count=1) | |
| const tagCommand = `git describe --tags $(git rev-list --tags --max-count=1)`; | |
| exec(tagCommand, { cwd: repoPath }, (tagErr, stdout) => { | |
| if (tagErr) { | |
| return resolve(colorize(`Error fetching latest tag: ${tagErr.message}`, 31)); // Red | |
| } | |
| resolve(stdout.trim() ? colorize(stdout, 32) : colorize("No tags found.", 33)); // Green or Yellow | |
| }); | |
| }); | |
| }); | |
| } | |
| // Function to execute git command and return output as a Promise | |
| function getGitLog(repoPath, branch1, branch2) { | |
| return new Promise((resolve) => { | |
| exec("git fetch", { cwd: repoPath }, (fetchErr) => { | |
| if (fetchErr) { | |
| return resolve(colorize(`Error fetching updates: ${fetchErr.message}`, 31)); // Red | |
| } | |
| const logCommand = `git log ${branch1}..${branch2} --oneline --no-merges`; | |
| exec(logCommand, { cwd: repoPath }, (logErr, stdout) => { | |
| if (logErr) { | |
| return resolve(colorize(`Error fetching log: ${logErr.message}`, 31)); // Red | |
| } | |
| resolve(stdout.trim() ? colorize(stdout, 32) : colorize("No new commits.", 33)); // Green or Yellow | |
| }); | |
| }); | |
| }); | |
| } | |
| // Function to colorize output | |
| function colorize(text, colorCode) { | |
| return `\x1b[${colorCode}m${text}\x1b[0m`; | |
| } | |
| // Loop through repositories and compare branches using async/await | |
| (async () => { | |
| for (const repo of repositories) { | |
| const repoPath = path.join(baseDir, repo); | |
| console.log(colorize(`\n${path.basename(repoPath)}: ${branch1} -> ${branch2}`, 36)); // Cyan | |
| console.log(await getGitLog(repoPath, branch1, branch2)); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment