diff --git a/.travis.yml b/.travis.yml index 2ef2d48..40d3f9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,4 @@ node_js: - '12' before_install: - npm install -g grunt-cli + - sudo apt-get -y install libsecret-1-dev diff --git a/package.json b/package.json index 6561686..5b415ec 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "dependencies": { "grunt": "^1.0.3", "inquirer": "^5.1.0", + "keytar": "^5.1.0", "request": "^2.83.0", "xmlrpc": "^1.3.1" }, diff --git a/tasks/patch_wordpress.js b/tasks/patch_wordpress.js index 5568f44..a40e699 100644 --- a/tasks/patch_wordpress.js +++ b/tasks/patch_wordpress.js @@ -13,6 +13,7 @@ const exec = require( 'child_process' ).exec; const execSync = require( 'child_process' ).execSync; const spawn = require( 'child_process' ).spawn; const inquirer = require( 'inquirer' ); +const keytar = require( 'keytar' ); const url = require( 'url' ); const fs = require( 'fs' ); const trac = require( '../lib/trac.js' ); @@ -335,17 +336,26 @@ module.exports = function( grunt ) { ); } ); }; - if ( process.env.WPORG_USERNAME && process.env.WPORG_PASSWORD ) { - uploadPatchWithCredentials( process.env.WPORG_USERNAME, process.env.WPORG_PASSWORD ); - } else { - inquirer.prompt( - [ - { type: 'input', name: 'username', message: 'Enter your WordPress.org username' }, - { type: 'password', name: 'password', message: 'Enter your WordPress.org password' }, - ] ).then( ( answers ) => { - uploadPatchWithCredentials( answers.username, answers.password ); + const getCredentials = keytar.findCredentials( 'wporg_patch' ); + getCredentials.then( ( savedCredentials ) => { + if ( savedCredentials.length > 0 ) { + uploadPatchWithCredentials( savedCredentials[ 0 ].account, savedCredentials[ 0 ].password ); + } else if ( process.env.WPORG_USERNAME && process.env.WPORG_PASSWORD ) { + uploadPatchWithCredentials( process.env.WPORG_USERNAME, process.env.WPORG_PASSWORD ); + } else { + inquirer.prompt( + [ + { type: 'input', name: 'username', message: 'Enter your WordPress.org username' }, + { type: 'password', name: 'password', message: 'Enter your WordPress.org password' }, + { type: 'confirm', name: 'saveCredentials', message: 'Save your credentials?' }, + ] ).then( ( answers ) => { + uploadPatchWithCredentials( answers.username, answers.password ); + if ( answers.saveCredentials ) { + keytar.setPassword( 'wporg_patch', answers.username, answers.password ); + } + } + ); } - ); - } + } ); } ); };