From a03d04e28047d376f31b0518d4d512d820037a1a Mon Sep 17 00:00:00 2001 From: 6gx7iycn53ioq2e8apk1j1ypwov4giui <65741741+6gx7iycn53ioq2e8apk1j1ypwov4giui@users.noreply.github.com> Date: Sun, 1 Aug 2021 22:47:01 +0300 Subject: [PATCH] add gpg signingkey option --- bin/gh-pages.js | 5 +++++ lib/index.js | 12 ++++++++++-- lib/util.js | 9 +++++++-- readme.md | 5 +++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bin/gh-pages.js b/bin/gh-pages.js index cb21967e..7f8eadec 100755 --- a/bin/gh-pages.js +++ b/bin/gh-pages.js @@ -59,6 +59,10 @@ function main(args) { '-u, --user
', 'The name and email of the user (defaults to the git config). Format is "Your Name ".' ) + .option( + '--signingkey ', + 'The signing key for signing the commits (defaults to the git config).' + ) .option( '-v, --remove ', 'Remove files that match the given pattern ' + @@ -122,6 +126,7 @@ function main(args) { push: !!program.push, history: !!program.history, user: user, + signingkey: program.signingkey, beforeAdd: beforeAdd }; diff --git a/lib/index.js b/lib/index.js index b053ceb9..6d3bd3f4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -114,7 +114,10 @@ exports.publish = function publish(basePath, config, callback) { let repoUrl; let userPromise; if (options.user) { - userPromise = Promise.resolve(options.user); + userPromise = Promise.resolve({ + ...options.user, + signingkey: options.signingkey + }); } else { userPromise = getUser(); } @@ -205,7 +208,12 @@ exports.publish = function publish(basePath, config, callback) { if (!user.name) { return git; } - return git.exec('config', 'user.name', user.name); + return git.exec('config', 'user.name', user.name).then(() => { + if (!user.signingkey) { + return git; + } + return git.exec('config', 'user.signingkey', user.signingkey); + }); }); }) .then(git => { diff --git a/lib/util.js b/lib/util.js index e31f2ef2..acedb5c0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -157,10 +157,15 @@ exports.copy = function(files, base, dest) { exports.getUser = function(cwd) { return Promise.all([ new Git(cwd).exec('config', 'user.name'), - new Git(cwd).exec('config', 'user.email') + new Git(cwd).exec('config', 'user.email'), + new Git(cwd).exec('config', 'user.signingkey') ]) .then(results => { - return {name: results[0].output.trim(), email: results[1].output.trim()}; + return { + name: results[0].output.trim(), + email: results[1].output.trim(), + signingkey: results[2].output.trim() + }; }) .catch(err => { // git config exits with 1 if name or email is not set diff --git a/readme.md b/readme.md index 1f58ac75..56f7b642 100644 --- a/readme.md +++ b/readme.md @@ -216,7 +216,7 @@ ghpages.publish('dist', { * type: `Object` * default: `null` -If you are running the `gh-pages` task in a repository without a `user.name` or `user.email` git config properties (or on a machine without these global config properties), you must provide user info before git allows you to commit. The `options.user` object accepts `name` and `email` string values to identify the committer. +If you are running the `gh-pages` task in a repository without a `user.name`, `user.email` or `user.signingkey` git config properties (or on a machine without these global config properties), you must provide user info before git allows you to commit. The `options.user` object accepts `name`, `email` and `signingkey` string values to identify the committer. Example use of the `user` option: @@ -224,7 +224,8 @@ Example use of the `user` option: ghpages.publish('dist', { user: { name: 'Joe Code', - email: 'coder@example.com' + email: 'coder@example.com', + signingkey: 'D29XXXXXXXXXXXXX' } }, callback); ```