Skip to content

Commit bbed9b4

Browse files
committed
Initial support for suites.
1 parent 8d51d4e commit bbed9b4

File tree

3 files changed

+104
-5
lines changed

3 files changed

+104
-5
lines changed

src/hook.js

+24
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ function processVersions( repo, fn ) {
117117
}
118118

119119
function processRelease( repo, release, fn ) {
120+
// if this is a suite, process each plugin individually
121+
if ( Array.isArray( release.package ) ) {
122+
return Step(
123+
function() {
124+
var group = this.group();
125+
release.package.forEach(function( package ) {
126+
processRelease( repo, {
127+
tag: release.tag,
128+
package: package
129+
}, group() );
130+
});
131+
},
132+
133+
function( error ) {
134+
if ( error ) {
135+
return fn( error );
136+
}
137+
138+
fn( null, release );
139+
}
140+
);
141+
}
142+
143+
// TODO: track plugin name for retry in suites
120144
Step(
121145
// find out who owns this plugin
122146
// if there is no owner, then set the user as the owner

src/service.js

+65-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ var semver = require( "semver" ),
22
Step = require( "step" ),
33
config = require( "./config" );
44

5+
var suites = {
6+
"github/rdworth/temp-jqueryui": "ui-"
7+
};
8+
59
function extend( a, b ) {
610
for ( var prop in b ) {
711
a[ prop ] = b[ prop ];
@@ -12,12 +16,18 @@ function Repo() {
1216
this.userId = this.service + "/" + this.userName;
1317
this.id = this.userId + "/" + this.repoName;
1418
this.path = config.repoDir + "/" + this.id;
19+
this.isSuite = this.id in suites;
1520
}
1621

1722
// package.json
1823
extend( Repo.prototype, {
19-
getPackageJson: function( version, fn ) {
20-
this._getPackageJson( version, function( error, package ) {
24+
getPackageJson: function( version, file, fn ) {
25+
if ( typeof file === "function" ) {
26+
fn = file;
27+
file = "package.json";
28+
}
29+
30+
this._getPackageJson( version, file, function( error, package ) {
2131
if ( error ) {
2232
return fn( error );
2333
}
@@ -236,6 +246,10 @@ extend( Repo.prototype, {
236246
},
237247

238248
validateVersion: function( tag, fn ) {
249+
if ( this.isSuite ) {
250+
return this.validateVersion_suite( tag, fn );
251+
}
252+
239253
var repo = this;
240254
Step(
241255
// get the package.json
@@ -250,7 +264,7 @@ extend( Repo.prototype, {
250264
}
251265

252266
if ( !package ) {
253-
return fn( null );
267+
return fn( null, null );
254268
}
255269

256270
return package;
@@ -268,6 +282,54 @@ extend( Repo.prototype, {
268282
fn( null, package );
269283
}
270284
);
285+
},
286+
287+
validateVersion_suite: function( tag, fn ) {
288+
var repo = this;
289+
Step(
290+
// get list of package.json files
291+
function() {
292+
repo.getPackageJsonFiles( tag, this );
293+
},
294+
295+
// get all package.jsons
296+
function( error, files ) {
297+
if ( error ) {
298+
return fn( error );
299+
}
300+
301+
if ( !files.length ) {
302+
return fn( null, null );
303+
}
304+
305+
var group = this.group();
306+
files.forEach(function( file ) {
307+
repo.getPackageJson( tag, file, group() );
308+
});
309+
},
310+
311+
// validate package.jsons
312+
function( error, packages ) {
313+
if ( error ) {
314+
return fn( error );
315+
}
316+
317+
// if any package.json is invalid, then the whole version is invalid
318+
if ( packages.some(function( package ) {
319+
return !package;
320+
})) {
321+
return fn( null, null );
322+
}
323+
324+
for ( var i = 0, l = packages.length; i < l; i++ ) {
325+
if ( repo.validatePackageJson( packages[ i ], tag ).length ) {
326+
return fn( null, null );
327+
}
328+
}
329+
330+
fn( null, packages );
331+
}
332+
);
271333
}
272334
});
273335

src/service/github.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,22 @@ extend( GithubRepo.prototype, {
8484
);
8585
},
8686

87-
_getPackageJson: function( version, fn ) {
87+
getPackageJsonFiles: function( tag, fn ) {
88+
exec( "git ls-tree " + tag + " --name-only", { cwd: this.path }, function( error, stdout, stderr ) {
89+
if ( error ) {
90+
return fn( error );
91+
}
92+
93+
// filter to *.package.json
94+
fn( null, stdout.split( "\n" ).filter(function( file ) {
95+
return file.indexOf( ".package.json" ) > 0;
96+
}));
97+
});
98+
},
99+
100+
_getPackageJson: function( version, file, fn ) {
88101
version = version || "master";
89-
exec( "git show " + version + ":package.json", { cwd: this.path }, function( error, stdout, stderr ) {
102+
exec( "git show " + version + ":" + file, { cwd: this.path }, function( error, stdout, stderr ) {
90103
// this will also result in an error being passed, so we check stderr first
91104
if ( stderr && stderr.substring( 0, 11 ) === "fatal: Path" ) {
92105
return fn( null, null );

0 commit comments

Comments
 (0)