Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gpg signingkey option #403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/gh-pages.js
Expand Up @@ -59,6 +59,10 @@ function main(args) {
'-u, --user <address>',
'The name and email of the user (defaults to the git config). Format is "Your Name <email@example.com>".'
)
.option(
'--signingkey <signingkey>',
'The signing key for signing the commits (defaults to the git config).'
)
.option(
'-v, --remove <pattern>',
'Remove files that match the given pattern ' +
Expand Down Expand Up @@ -122,6 +126,7 @@ function main(args) {
push: !!program.push,
history: !!program.history,
user: user,
signingkey: program.signingkey,
beforeAdd: beforeAdd
};

Expand Down
12 changes: 10 additions & 2 deletions lib/index.js
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 => {
Expand Down
9 changes: 7 additions & 2 deletions lib/util.js
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions readme.md
Expand Up @@ -216,15 +216,16 @@ 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:

```js
ghpages.publish('dist', {
user: {
name: 'Joe Code',
email: 'coder@example.com'
email: 'coder@example.com',
signingkey: 'D29XXXXXXXXXXXXX'
}
}, callback);
```
Expand Down