Skip to content

Commit 739c7d0

Browse files
committed
Try adding keytar to store credentials
See: https://core.trac.wordpress.org/ticket/49390 Previusly: #40
1 parent eb1eccc commit 739c7d0

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"dependencies": {
4646
"grunt": "^1.0.3",
4747
"inquirer": "^5.1.0",
48+
"keytar": "^5.1.0",
4849
"request": "^2.83.0",
4950
"xmlrpc": "^1.3.1"
5051
},

tasks/patch_wordpress.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const exec = require( 'child_process' ).exec;
1313
const execSync = require( 'child_process' ).execSync;
1414
const spawn = require( 'child_process' ).spawn;
1515
const inquirer = require( 'inquirer' );
16+
const keytar = require('keytar')
1617
const url = require( 'url' );
1718
const fs = require( 'fs' );
1819
const trac = require( '../lib/trac.js' );
@@ -335,17 +336,27 @@ module.exports = function( grunt ) {
335336
);
336337
} );
337338
};
338-
if ( process.env.WPORG_USERNAME && process.env.WPORG_PASSWORD ) {
339-
uploadPatchWithCredentials( process.env.WPORG_USERNAME, process.env.WPORG_PASSWORD );
340-
} else {
341-
inquirer.prompt(
342-
[
343-
{ type: 'input', name: 'username', message: 'Enter your WordPress.org username' },
344-
{ type: 'password', name: 'password', message: 'Enter your WordPress.org password' },
345-
] ).then( ( answers ) => {
346-
uploadPatchWithCredentials( answers.username, answers.password );
339+
const getCredentials = keytar.findCredentials( 'wporg_patch' );
340+
getCredentials.then( savedCredentials => {
341+
if ( savedCredentials.length > 0 ){
342+
uploadPatchWithCredentials( savedCredentials[0].account, savedCredentials[0].password );
347343
}
348-
);
349-
}
344+
else if ( process.env.WPORG_USERNAME && process.env.WPORG_PASSWORD ) {
345+
uploadPatchWithCredentials( process.env.WPORG_USERNAME, process.env.WPORG_PASSWORD );
346+
} else {
347+
inquirer.prompt(
348+
[
349+
{ type: 'input', name: 'username', message: 'Enter your WordPress.org username' },
350+
{ type: 'password', name: 'password', message: 'Enter your WordPress.org password' },
351+
{ type: 'confirm', name: 'saveCredentials', message: 'Save your credentials?' },
352+
] ).then( ( answers ) => {
353+
uploadPatchWithCredentials( answers.username, answers.password );
354+
if ( answers.saveCredentials ){
355+
keytar.setPassword( 'wporg_patch', answers.username, answers.password );
356+
}
357+
}
358+
);
359+
}
360+
});
350361
} );
351362
};

0 commit comments

Comments
 (0)