Permalink
Browse files

Track watchers and forks as metadata.

  • Loading branch information...
scottgonzalez committed Dec 19, 2011
1 parent 1bac8b8 commit 9d08c050bbd28d82f8dbe44efe40451f41b9b84c
Showing with 97 additions and 4 deletions.
  1. +73 −2 src/main.js
  2. +1 −0 src/service.js
  3. +21 −0 src/wordpress.js
  4. +2 −2 template/page
View
@@ -86,6 +86,30 @@ function processPlugin( data, fn ) {
return fn( new Error( "Could not parse request." ) );
}
+ Step(
+ function() {
+ processVersions( repo, this );
+ },
+
+ function( error ) {
+ if ( error ) {
+ return fn( error );
+ }
+
+ processMeta( repo, this );
+ },
+
+ function( error ) {
+ if ( error ) {
+ return fn( error );
+ }
+
+ fn( null );
+ }
+ );
+}
+
+function processVersions( repo, fn ) {
Step(
// get all new versions of the plugin
function() {
@@ -258,8 +282,6 @@ function processPlugin( data, fn ) {
var pluginData = Object.create( package );
pluginData._downloadUrl = repo.downloadUrl( version );
pluginData.url = repo.siteUrl;
- pluginData.forks = repo.forks;
- pluginData.watchers = repo.watchers;
generatePage( pluginData, this );
},
@@ -353,6 +375,55 @@ function processPlugin( data, fn ) {
}
}
+function processMeta( repo, fn ) {
+ var plugin;
+ Step(
+ function() {
+ repo.getPackageJson( null, this );
+ },
+
+ function( error, package ) {
+ if ( error ) {
+ return fn( error );
+ }
+
+ plugin = package.name;
+ pluginsDb.getOwner( plugin, this );
+ },
+
+ function( error, owner ) {
+ if ( error ) {
+ return fn( error );
+ }
+
+ // the plugin is not being tracked yet
+ if ( !owner ) {
+ return fn( null );
+ }
+
+ // the plugin is owned by someone else
+ if ( owner !== repo.userName ) {
+ // TODO: report error to user
+ return fn( new UserError( "Plugin " + plugin + " is owned by " + owner + "." ) );
+ }
+
+ wordpress.updateMeta( plugin, {
+ watchers: repo.watchers,
+ forks: repo.forks
+ }, this );
+ },
+
+ function( error ) {
+ if ( error ) {
+ return fn( error );
+ }
+
+ console.log( "Updated meta for " + plugin );
+ wordpress.end();
+ fn( null );
+ }
+ );
+}
View
@@ -55,6 +55,7 @@ extend( GithubRepo.prototype, {
},
getPackageJson: function( version, fn ) {
+ version = version || "master";
exec( "git show " + version + ":package.json", { cwd: this.path }, function( error, stdout, stderr ) {
// this will also result in an error being passed, so we check stderr first
if ( stderr && stderr.substring( 0, 41 ) === "fatal: Path 'package.json' does not exist" ) {
View
@@ -12,6 +12,7 @@ function table( name ) {
return "wp_" + (config.siteId ? config.siteId + "_" : "") + name;
}
+// TODO: handle connection error
function connect() {
db = new mysql.createClient({
host: config.dbHost,
@@ -252,6 +253,26 @@ var wordpress = module.exports = {
});
}),
+ updateMeta: auto(function( plugin, meta, fn ) {
+ Step(
+ function() {
+ var key,
+ group = this.group();
+ for ( key in meta ) {
+ setMeta( plugin, key, meta[ key ], group() );
+ }
+ },
+
+ function( error ) {
+ if ( error ) {
+ return fn( error );
+ }
+
+ fn( null );
+ }
+ );
+ }),
+
flush: auto(function( fn ) {
db.query( "DELETE FROM `" + optionsTable + "` WHERE `option_name` = 'rewrite_rules'", fn );
}),
View
@@ -31,11 +31,11 @@
<div class="block clearfix">
<div class="col col4-2">
<h2>Watchers</h2>
- <b>{{watchers}}</b>
+ <b>[jq_plugin_meta key="watchers"]</b>
</div>
<div class="col col4-2 right">
<h2>Forks</h2>
- <b>{{forks}}</b>
+ <b>[jq_plugin_meta key="forks"]</b>
</div>
</div>
<div class="block clearfix">

0 comments on commit 9d08c05

Please sign in to comment.