Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle semver tags: when a semver tag is pushed create the workspace …

…and check out the tagged version - fixes #4
  • Loading branch information...
commit 7e24021aa310baffbb611ed29a358414ea884d2c 1 parent 5303548
@gseguin authored
Showing with 22 additions and 10 deletions.
  1. +2 −1  lib/project.js
  2. +3 −1 package.json
  3. +17 −8 server.js
View
3  lib/project.js
@@ -4,6 +4,7 @@ var _ = require( 'underscore' ),
async = require( 'async'),
fs = require( 'fs' ),
Git = require( './git'),
+ mkdirp = require('mkdirp' ),
path = require( 'path' ),
rimraf = require( 'rimraf' );
@@ -74,7 +75,7 @@ function checkout( project, force, callback ){
rimraf( path.join( workDir ), next );
},
function( next ) {
- fs.mkdir( workDir, function( err ) {
+ mkdirp( workDir, function( err ) {
if ( err && err.code != "EEXIST" ) {
next( err );
} else {
View
4 package.json
@@ -1,7 +1,7 @@
{
"name":"amd-builder",
"description":"A service that builds bundles from AMD projects resources",
- "version":"0.4.1",
+ "version":"0.4.2",
"keywords":[
"jquery mobile",
"amd",
@@ -30,12 +30,14 @@
"css-concat":"latest",
"express":"2.5.2",
"mime":"latest",
+ "mkdirp": "latest",
"logger": "git://github.com/jquery/node-logger.git",
"optimist":"latest",
"node-promise":"latest",
"request":"latest",
"requirejs":"1.0.8",
"rimraf":"latest",
+ "semver":"latest",
"underscore":"latest",
"node-native-zip":"~1.0.1"
},
View
25 server.js
@@ -16,6 +16,7 @@ var _ = require( 'underscore' ),
when = require( 'node-promise').when,
regexp = require( './lib/regexp' ),
requirejs = require( 'requirejs' ),
+ semver = require( 'semver' ),
url = require( 'url' ),
zip = require("node-native-zip" );
@@ -56,6 +57,7 @@ app.configure('production', function(){
app.use(express.bodyParser());
function afterProjectCheckout( project ) {
+ // Clear caches
var wsDir = project.getWorkspaceDirSync(),
filterPath;
for ( filterPath in filters[ wsDir ] ) {
@@ -72,7 +74,7 @@ app.get( '/', function ( req, res ) {
app.post( '/post_receive', function ( req, res ) {
var payload = req.body.payload,
- owner, repo, repoUrl, ref, project,
+ owner, repo, repoUrl, ref, refType, refName, project,
fetchIfExists = function( candidates, callback ) {
var dir = candidates.shift();
fs.exists( dir , function( exists ) {
@@ -90,7 +92,7 @@ app.post( '/post_receive', function ( req, res ) {
if ( candidates.length ) {
fetchIfExists( candidates );
} else {
- logger.error( "Error in post_receive route: Workspace for '" + repo + "' hasn't been checked out" );
+ logger.error( "Error in /post_receive route: Workspace for '" + repo + "' hasn't been checked out" );
res.send( "Workspace for '" + repo + "' hasn't been checked out", 404 );
}
}
@@ -101,19 +103,26 @@ app.post( '/post_receive', function ( req, res ) {
try {
payload = JSON.parse( payload );
repo = payload.repository.name;
- repoUrl = url.parse( payload.repository.url );
- owner = path.dirname( repoUrl.path ).substring( 1 );
- ref = payload.ref.split( "/" ).pop();
- project = new Project( owner, repo, ref );
+ owner = payload.repository.owner.name;
+ ref = payload.ref.split( "/" );
+ refName = ref.pop();
+ refType = ref.pop();
+ project = new Project( owner, repo, refName );
+
+ if ( refType === "tags" && semver.valid( refName ) != null ) {
+ logger.log( "/post_receive received SEMVER ref: ", refName, "for SHASUM:", payload.after );
+ }
if ( project ) {
async.series([
_.bind( project.fetch, project ),
- _.bind( project.checkout, project )
+ function( next ) {
+ project.checkout( refType === "tags" && semver.valid( refName ) != null, next );
+ }
],
function ( err ) {
if ( err ) {
- logger.error( "Error in post_receive route: " + err );
+ logger.error( "Error in /post_receive route: " + err );
res.send( err, 500 );
} else {
afterProjectCheckout( project );
Please sign in to comment.
Something went wrong with that request. Please try again.