Created
May 23, 2016 22:14
-
-
Save Jotschi/dfb0a560dfc630f8d9c613d02fb1c0d9 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
| //var myrepo = null; | |
| var nodegit = require("nodegit"); | |
| var fs = require('fs'); | |
| var changelogFolder = "changes"; | |
| var files = fs.readdirSync(changelogFolder); | |
| // Iterate over each change file | |
| files.forEach( function(file, index) { | |
| console.log("Checking file ", file); | |
| var myrepo = null; | |
| nodegit.Repository.open(".") | |
| .then(repo => { | |
| myrepo = repo; | |
| return repo.getHeadCommit(); | |
| }) | |
| .then(headCommit => { | |
| //console.log("Found head", headCommit.sha()); | |
| return new Promise(resolve => { | |
| var history = headCommit.history(); | |
| var commits = []; | |
| //console.log("Creating promise", resolve); | |
| history.on('commit', commit => commits.push(commit)); | |
| history.on('end', () => resolve(commits)); | |
| //history.on('commit', () => console.log("Blar")); | |
| history.start(); | |
| }); | |
| }) | |
| .then(allCommits => { | |
| //console.log("Found commit", allCommits); | |
| return Promise.all(allCommits.map(commit => { | |
| return commit.getEntry("changes/" + file) | |
| .then(entry => ({ | |
| commit: commit, | |
| entry: entry | |
| }), fail => null); | |
| })); | |
| }) | |
| .then(allCommits => allCommits.filter(e => e !== null)) | |
| .then(allCommits => allCommits.sort((a, b) => b.commit.date() - a.commit.date())) | |
| .then(allCommits => { | |
| if (allCommits.length != 0) { | |
| var firstCommit = allCommits.pop().commit; | |
| console.log("Commit: " + firstCommit.sha()); | |
| nodegit.Tag.list(myrepo).then(tags => { | |
| return Promise.all(tags.map(tag => { | |
| console.log("Tag" , tag); | |
| return nodegit.Reference.nameToId(myrepo, "refs/tags/" + tag); | |
| })); | |
| }).then(oid => { | |
| console.log(oid[0].tostrS()); | |
| return myrepo.getCommit(oid[2].tostrS()); | |
| }).then(headCommit => { | |
| console.log("Found head ",headCommit); | |
| return new Promise(resolve => { | |
| var history = headCommit.history(); | |
| var commits = []; | |
| //console.log("Creating promise", resolve); | |
| history.on('commit', commit => commits.push(commit)); | |
| history.on('end', () => resolve(commits)); | |
| //history.on('commit', () => console.log("Blar")); | |
| history.start(); | |
| }); | |
| }) | |
| .then(allCommits => allCommits.filter(e => e !== null)) | |
| .then(allCommits => allCommits.filter(e => e.sha() === firstCommit.sha())) | |
| .then(allCommits => { | |
| //allCommits.map(function(e) { | |
| // console.log("Commit: " + e.commit.sha()); | |
| // console.log("Entry: " + e.entry); | |
| //}); | |
| console.log(allCommits.length); | |
| //var firstCommit = allCommits.pop(); | |
| //console.log("Commit: " + firstCommit.sha()); | |
| //console.log("Entry: " + firstCommit.entry); | |
| //console.log(allCommits.map(c => c.entry.isFile())); | |
| // find first commit with entry | |
| // allCommits[0] has .commit, .entry | |
| }).catch(err => console.error(err, err.stack)); | |
| } | |
| //console.log("Entry: " + firstCommit.entry); | |
| //console.log(allCommits.map(c => c.entry.isFile())); | |
| // find first commit with entry | |
| // allCommits[0] has .commit, .entry | |
| }).catch(err => console.error(err, err.stack)); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment