Add utility to check repos for commits missing DCO 27/11927/25
authorJeremy Phelps <jphelps@linuxfoundation.org>
Mon, 23 Jul 2018 19:04:30 +0000 (14:04 -0500)
committerJeremy Phelps <jphelps@linuxfoundation.org>
Fri, 27 Jul 2018 18:47:52 +0000 (13:47 -0500)
This only works on git repositories.

Change-Id: I45a0a66dfaaf517cdc5d85fc15f60e403bccfeb9
Co-Authored-By: Eric Ball <eball@linuxfoundation.org>
Co-Authored-By: Thanh Ha <thanh.ha@linuxfoundation.org>
Signed-off-by: Jeremy Phelps <jphelps@linuxfoundation.org>
docs/commands/dco.rst [new file with mode: 0644]
docs/commands/index.rst
lftools/cli/__init__.py
lftools/cli/dco.py [new file with mode: 0644]
setup.py
shell/dco [new file with mode: 0644]

diff --git a/docs/commands/dco.rst b/docs/commands/dco.rst
new file mode 100644 (file)
index 0000000..534b270
--- /dev/null
@@ -0,0 +1,18 @@
+****
+Dco
+****
+
+.. program-output:: lftools dco --help
+
+Commands
+========
+
+.. contents:: Check Commands
+    :local:
+
+check
+---------
+
+.. program-output:: lftools dco check --help
+                    List of git shas that are missing DCO (Signed-off-by line).
+
index 86e449b..2e81508 100644 (file)
@@ -10,6 +10,7 @@ bash. It supports the following commands.
 
     config
     deploy
+    dco
     license
     nexus
     openstack
index 635941a..25fc94e 100644 (file)
@@ -14,6 +14,7 @@ __author__ = 'Thanh Ha'
 import click
 
 from lftools.cli.config import config_sys
+from lftools.cli.dco import dco
 from lftools.cli.deploy import deploy
 from lftools.cli.jenkins import jenkins_cli
 from lftools.cli.license import license
@@ -32,6 +33,7 @@ def cli(ctx):
 
 cli.add_command(config_sys)
 cli.add_command(deploy)
+cli.add_command(dco)
 cli.add_command(jenkins_cli, name='jenkins')
 cli.add_command(license)
 cli.add_command(nexus)
diff --git a/lftools/cli/dco.py b/lftools/cli/dco.py
new file mode 100644 (file)
index 0000000..86d2d94
--- /dev/null
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+"""Script to check a git repository for commits missing DCO."""
+
+import subprocess
+import sys
+
+import click
+
+
+@click.group()
+@click.pass_context
+def dco(ctx):
+    """Check repository for commits missing DCO."""
+    pass
+
+
+@click.command()
+@click.argument('repo-path', required=False)
+@click.pass_context
+def check(ctx, repo_path):
+    """Check repository for commits missing DCO.
+
+    This check will exclude merge commits and empty commits.
+    It operates in your current working directory which has to
+    be a git repository.  Alternatively, you can opt to pass in the
+    path to a git repo.
+    Refer to https://developercertificate.org/
+    """
+    if not repo_path:
+        repo_path = "."
+    status = subprocess.call(['dco', repo_path])
+    sys.exit(status)
+
+
+dco.add_command(check)
index 933d740..afbb0da 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -55,9 +55,10 @@ setup(
         lftools=lftools.cli:main
     ''',
     scripts=[
+        'shell/dco',
         'shell/deploy',
         'shell/sign',
-        'shell/version',
+        'shell/version'
     ],
     data_files=[('etc', ['etc/logging.ini'])],
 )
diff --git a/shell/dco b/shell/dco
new file mode 100644 (file)
index 0000000..df93825
--- /dev/null
+++ b/shell/dco
@@ -0,0 +1,34 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+# This script determines if a git repo contains commits missing DCO.
+# It operates in your current working directory which must be a git repo.
+# Alternatively you can pass it a path to a git repo.
+
+REPO_PATH="$1"
+
+cd $REPO_PATH || exit 1
+
+status=0
+while IFS= read -a line; do
+    my_array+=( "$line" )
+    done < <( git branch -r | grep -v origin/HEAD )
+for branch in "${my_array[@]}"
+do
+    status=1
+    branch=$(echo "$branch" | xargs)
+    echo "Checking commits in branch $branch for commits missing DCO..."
+    git log $branch --no-merges --pretty="%H" --grep 'Signed-off-by' --invert-grep * | \
+        while read commit_hash; do
+            echo "ERROR: Commit $commit_hash is missing Signed-off-by line."
+        done
+done
+exit $status