Skip to content

Instantly share code, notes, and snippets.

@alloy
Created February 27, 2020 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/8851c53214ec20136f69622127d4df71 to your computer and use it in GitHub Desktop.
Save alloy/8851c53214ec20136f69622127d4df71 to your computer and use it in GitHub Desktop.
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