On the command line you
can run the following to get the SHA of the latest commit.
> git
rev-parse HEAD
|
To get the name of the
current branch run the following.
> git
rev-parse --abbrev-ref HEAD
|
How do you do this in Node?
I am sure there are
several libraries out there that can help me out.
Poking around…
Run the following command to install this module and save it
to the package.json
> npm install -S git-repo-info
|
Here is my app.js
var express = require('express');
var config = require('config'); var gitInfo = require('git-repo-info')(); var app = express(); var server; var start = exports.start = function start(port, callback) { server = app.listen(port, callback); }; var stop = exports.stop = function stop(callback) { server.close(callback); }; app.get('/git-info', function sendResponse(req, res) { res.json( { "commit-sha" : gitInfo.sha, "branch" : gitInfo.branch }); }); |
Nice! That worked pretty well.
Pretty simple easy node
library to pull in and use.
References
[1] node git-repo-info github page
Accessed 5/2015
No comments:
Post a Comment