Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const fs = require("fs");
const PromisePool = require("@supercharge/promise-pool");
const { git, getOriginalCommit } = require("./scripts/changelog-generator");
const gitDir = "/Users/eloy/Code/ReactNative/react-native/.git"
const seen = new Map()
const SHAs = new Set()
const existingChangelogData = fs.readFileSync("./CHANGELOG.md", "utf8");
function forEachSHA(cb) {
return existingChangelogData.replace(/[a-f0-9]{7,40}/g, sha => {
return cb(sha);
})
}
forEachSHA(sha => {
SHAs.add(sha.slice(0, 7));
return sha;
})
const pool = new PromisePool({ concurrency: 20, items: Array.from(SHAs) })
pool.process(sha => {
if (seen.get(sha)) {
return null;
}
return git(gitDir, "log", "--format=%B", "-n", "1", sha).then(message => {
return getOriginalCommit(gitDir, { sha, commit: { message: message.trimRight() } }).then(resolved => {
seen.set(sha.slice(0, 7), resolved.sha.slice(0, 7));
return null;
})
})
}).then(({ errors }) => {
for (const e of errors) {
console.error(e)
}
const newData = forEachSHA(sha => {
const resolved = seen.get(sha.slice(0, 7))
if (resolved) {
return resolved.slice(0, sha.length);
} else {
console.log(sha)
return sha;
}
})
fs.writeFileSync("./CHANGELOG.md", newData, "utf8");
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.