Skip to content

Show warnings when signatures are not validated #3

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

Open
wants to merge 2 commits into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ commits as properly signed.
npm run collaborator:sync-keys
```

Once you have synced the keys to your localk keyring, you can now
Once you have synced the keys to your local keyring, you can now
test that all commits are indeed signed.

```shell
Expand Down
48 changes: 41 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ function logFlag(flag, desc) {
}

function showHelpAndExit(flag) {
console.log(chalk.cyan.bold(`Usage: git-signed [--help|--join|--sync|--export|commit hash])`))
console.log(chalk.cyan.bold(`Usage: git-signed [--help|--join|--sync|--export|--trust-commits|commit hash])`))
console.log(``)

logFlag(` --help`, ` Print this help screen`)
logFlag(` --add`, ` Add yourself as a contributor to the project`)
logFlag(` --sync`, ` Import GPG keys from all contributors`)
logFlag(` [commit hash]`, ` Check history from this commit onward (optional)`)
logFlag(` --help`, ` Print this help screen`)
logFlag(` --add`, ` Add yourself as a contributor to the project`)
logFlag(` --sync`, ` Import GPG keys from all contributors`)
logFlag(` --trust-commits`, `Check if commits were made with certified keys (default false)`)
logFlag(` [commit hash]`, ` Check history from this commit onward (optional)`)
console.log(``)

console.log(chalk.yellow.bold(`If no commit hash is provided, the entire
Expand Down Expand Up @@ -50,6 +51,9 @@ function showGuide() {
// Command and arguments
const argOne = process.argv[2]

// If untrusted commits found, program shall exit
var trustCommits = false

switch (argOne) {
case '--join':
case '--sync':
Expand All @@ -58,7 +62,9 @@ switch (argOne) {
break

default:
if (argOne && argOne[0] === '-') {
if (argOne === '--trust-commits') {
trustCommits = true
} else if (argOne && argOne[0] === '-') {
showHelpAndExit(argOne[0])
}

Expand All @@ -70,7 +76,7 @@ switch (argOne) {
'--pretty=format:%G? %h %aN\t%s'
]

if (checkAfter) {
if (checkAfter && checkAfter !== '--trust-commits') {
args.push(`${checkAfter}..`)
}

Expand All @@ -88,6 +94,9 @@ switch (argOne) {
// We will store all unsigned commits here
let unsignedCommits = []

// We will store all invalidated commits here
let invalidatedCommits = []

const rl = readline.createInterface({
input: proc.stdout
})
Expand All @@ -99,11 +108,36 @@ switch (argOne) {
if (line.substring(0, 2) === 'N ') {
unsignedCommits.push(line.substring(2))
}
if (line.substring(0, 2) !== 'G ') {
invalidatedCommits.push(line.substring(2))
}
})

// On readline close, make sure we have no
// unsigned commits
rl.on('close', function () {
if (invalidatedCommits.length > 0) {
console.error('')
console.error(chalk.gray('The following commits are not validated'))
console.error(chalk.gray('---------------------------------------'))
console.error('')

invalidatedCommits.forEach((line) => {
const [ details, title ] = line.split('\t')
const [ hash, user ] = details.split(' ')

console.error(chalk.white(hash), chalk.white(user) + '\t' + chalk.gray(title))
})
console.error('')
console.error(chalk.gray('----------------------------------------'))

if (trustCommits) {
console.error('')
showGuide()
process.exit(1)
}
}

if (unsignedCommits.length > 0) {
console.error('')
console.error(chalk.red.bold('The following commits are not signed'))
Expand Down