Created
February 2, 2016 00:20
-
-
Save anonymous/86be1bab58039b223019 to your computer and use it in GitHub Desktop.
example.js
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
'use strict'; | |
// Helper Methods Used | |
var fs = require('fs'); | |
var NodeGit = require('NodeGit'); | |
class GitClient { | |
static clone(options) { | |
return NodeGit.Clone(options.remote, options.local, { | |
checkoutBranch: options.branch | |
}); | |
} | |
static addAndCommit(repo, filesArray, msg) { | |
return repo.createCommitOnHead( | |
filesArray, | |
NodeGit.Signature.create('test-service', '[email protected]', new Date().getTime(), 0), | |
NodeGit.Signature.create('test-service', '[email protected]', new Date().getTime(), 0), | |
msg || 'Anonymous Commit by the Test-Service' | |
); | |
} | |
static push(repo, repoName, remoteName, refs) { | |
return repo.getRemote(remoteName || 'origin').then(remote => { | |
return remote.push( | |
refs || [`refs/heads/${repoName || 'master'}:refs/heads/${repoName || 'master'}`] | |
).then(function () { | |
console.log('success', arguments); | |
}).catch(e => { | |
console.error(e.message); | |
}); | |
}); | |
} | |
} | |
// Unit/Integration Test | |
it('should push', () => { | |
let repo; | |
return GitClient.clone({ | |
branch: 'repo-0', | |
remote: 'REPO_URL', | |
local: 'test-git-module/test-push', | |
path: 'src', | |
cwd: 'test-git-module' | |
}).then(r => { | |
repo = r; | |
fs.writeFileSync('test-git-module/test-push/1/test.json', new Date().getTime() + 'UDPATE'); | |
// add the file | |
return GitClient.addAndCommit(repo, ['1/test.json'], 'Committing'); | |
}).then(() => { | |
return GitClient.push(repo, 'repo-0'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment