Skip to content

Commit 9d08c05

Browse files
committed
Track watchers and forks as metadata.
1 parent 1bac8b8 commit 9d08c05

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

src/main.js

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ function processPlugin( data, fn ) {
8686
return fn( new Error( "Could not parse request." ) );
8787
}
8888

89+
Step(
90+
function() {
91+
processVersions( repo, this );
92+
},
93+
94+
function( error ) {
95+
if ( error ) {
96+
return fn( error );
97+
}
98+
99+
processMeta( repo, this );
100+
},
101+
102+
function( error ) {
103+
if ( error ) {
104+
return fn( error );
105+
}
106+
107+
fn( null );
108+
}
109+
);
110+
}
111+
112+
function processVersions( repo, fn ) {
89113
Step(
90114
// get all new versions of the plugin
91115
function() {
@@ -258,8 +282,6 @@ function processPlugin( data, fn ) {
258282
var pluginData = Object.create( package );
259283
pluginData._downloadUrl = repo.downloadUrl( version );
260284
pluginData.url = repo.siteUrl;
261-
pluginData.forks = repo.forks;
262-
pluginData.watchers = repo.watchers;
263285
generatePage( pluginData, this );
264286
},
265287

@@ -353,6 +375,55 @@ function processPlugin( data, fn ) {
353375
}
354376
}
355377

378+
function processMeta( repo, fn ) {
379+
var plugin;
380+
Step(
381+
function() {
382+
repo.getPackageJson( null, this );
383+
},
384+
385+
function( error, package ) {
386+
if ( error ) {
387+
return fn( error );
388+
}
389+
390+
plugin = package.name;
391+
pluginsDb.getOwner( plugin, this );
392+
},
393+
394+
function( error, owner ) {
395+
if ( error ) {
396+
return fn( error );
397+
}
398+
399+
// the plugin is not being tracked yet
400+
if ( !owner ) {
401+
return fn( null );
402+
}
403+
404+
// the plugin is owned by someone else
405+
if ( owner !== repo.userName ) {
406+
// TODO: report error to user
407+
return fn( new UserError( "Plugin " + plugin + " is owned by " + owner + "." ) );
408+
}
409+
410+
wordpress.updateMeta( plugin, {
411+
watchers: repo.watchers,
412+
forks: repo.forks
413+
}, this );
414+
},
415+
416+
function( error ) {
417+
if ( error ) {
418+
return fn( error );
419+
}
420+
421+
console.log( "Updated meta for " + plugin );
422+
wordpress.end();
423+
fn( null );
424+
}
425+
);
426+
}
356427

357428

358429

src/service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extend( GithubRepo.prototype, {
5555
},
5656

5757
getPackageJson: function( version, fn ) {
58+
version = version || "master";
5859
exec( "git show " + version + ":package.json", { cwd: this.path }, function( error, stdout, stderr ) {
5960
// this will also result in an error being passed, so we check stderr first
6061
if ( stderr && stderr.substring( 0, 41 ) === "fatal: Path 'package.json' does not exist" ) {

src/wordpress.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function table( name ) {
1212
return "wp_" + (config.siteId ? config.siteId + "_" : "") + name;
1313
}
1414

15+
// TODO: handle connection error
1516
function connect() {
1617
db = new mysql.createClient({
1718
host: config.dbHost,
@@ -252,6 +253,26 @@ var wordpress = module.exports = {
252253
});
253254
}),
254255

256+
updateMeta: auto(function( plugin, meta, fn ) {
257+
Step(
258+
function() {
259+
var key,
260+
group = this.group();
261+
for ( key in meta ) {
262+
setMeta( plugin, key, meta[ key ], group() );
263+
}
264+
},
265+
266+
function( error ) {
267+
if ( error ) {
268+
return fn( error );
269+
}
270+
271+
fn( null );
272+
}
273+
);
274+
}),
275+
255276
flush: auto(function( fn ) {
256277
db.query( "DELETE FROM `" + optionsTable + "` WHERE `option_name` = 'rewrite_rules'", fn );
257278
}),

template/page

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
<div class="block clearfix">
3232
<div class="col col4-2">
3333
<h2>Watchers</h2>
34-
<b>{{watchers}}</b>
34+
<b>[jq_plugin_meta key="watchers"]</b>
3535
</div>
3636
<div class="col col4-2 right">
3737
<h2>Forks</h2>
38-
<b>{{forks}}</b>
38+
<b>[jq_plugin_meta key="forks"]</b>
3939
</div>
4040
</div>
4141
<div class="block clearfix">

0 commit comments

Comments
 (0)