Created
February 27, 2020 20:01
-
-
Save alloy/8851c53214ec20136f69622127d4df71 to your computer and use it in GitHub Desktop.
This file contains 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 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