Skip to content

Commit 37be402

Browse files
committed
Added script to transfer ownership of a plugin.
1 parent 3541ce8 commit 37be402

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

bin/transfer.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env node
2+
3+
var Step = require( "step" ),
4+
service = require( "../lib/service" ),
5+
pluginsDb = require( "../lib/pluginsdb" );
6+
7+
process.stdin.setEncoding( "utf8" );
8+
9+
function prompt( message, fn ) {
10+
process.stdout.write( message + " " );
11+
process.stdin.resume();
12+
13+
process.stdin.once( "data", function( chunk ) {
14+
process.stdin.pause();
15+
fn( null, chunk.trim() );
16+
});
17+
}
18+
19+
function showError( error ) {
20+
console.log( "Error transferring ownership" );
21+
console.log( error.stack );
22+
process.exit( 1 );
23+
}
24+
25+
function transfer( fn ) {
26+
var plugin;
27+
28+
Step(
29+
function() {
30+
// Find out which plugin to transfer
31+
prompt( "Plugin:", this );
32+
},
33+
34+
function( error, _plugin ) {
35+
if ( error ) {
36+
return showError( error );
37+
}
38+
39+
plugin = _plugin;
40+
41+
// Find out who currently owns the plugin
42+
pluginsDb.getOwner( plugin, this.parallel() );
43+
},
44+
45+
function( error, actualOwner ) {
46+
if ( error ) {
47+
return showError( error );
48+
}
49+
50+
// Verify the plugin exists
51+
if ( !actualOwner ) {
52+
console.log( plugin + " does not exist." );
53+
process.exit( 1 );
54+
}
55+
56+
// Find out who we think owns the plugin
57+
this.parallel()( null, actualOwner );
58+
prompt( "Current owner:", this.parallel() );
59+
},
60+
61+
function( error, actualOwner, providedOwner ) {
62+
if ( error ) {
63+
return showError( error );
64+
}
65+
66+
// Verify the expected owner is the real owner
67+
if ( providedOwner !== actualOwner ) {
68+
console.log( plugin + " is owned by " + actualOwner +
69+
", not " + providedOwner + "." );
70+
process.exit( 1 );
71+
}
72+
73+
// Find out where the plugin is being transferred to
74+
prompt( "New repository id (e.g., github/owner/repo)", this );
75+
},
76+
77+
function( error, id ) {
78+
if ( error ) {
79+
return showError( error );
80+
}
81+
82+
// Create a Repo instance to verify the new id and parse the data
83+
var repo;
84+
try {
85+
repo = service.getRepoById( id );
86+
} catch ( error ) {
87+
fn( error );
88+
return;
89+
}
90+
91+
// Transfer ownersip
92+
this.parallel()( null, repo.userId );
93+
pluginsDb.transferOwnership( plugin, repo.userId, repo.id, this.parallel() );
94+
},
95+
96+
function( error, owner ) {
97+
if ( error ) {
98+
return showError( error );
99+
}
100+
101+
console.log( "Succesfully transferred " + plugin + " to " + owner + "." );
102+
}
103+
);
104+
}
105+
106+
transfer();

lib/pluginsdb.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ var pluginsDb = module.exports = {
6969
});
7070
}),
7171

72+
transferOwnership: auto(function( plugin, owner, repo, fn ) {
73+
db.run( "UPDATE plugins SET owner = ?, repo = ? WHERE plugin = ?",
74+
[ owner, repo, plugin ], fn );
75+
}),
76+
7277
getTags: auto(function( repoId, fn ) {
7378
db.all( "SELECT tag FROM repos WHERE repo = ?", [ repoId ], function( error, tags ) {
7479
if ( error ) {

0 commit comments

Comments
 (0)