From: Jeremy Phelps Date: Mon, 23 Jul 2018 19:04:30 +0000 (-0500) Subject: Add utility to check repos for commits missing DCO X-Git-Tag: v0.15.0~2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F27%2F11927%2F25;p=releng%2Flftools.git Add utility to check repos for commits missing DCO This only works on git repositories. Change-Id: I45a0a66dfaaf517cdc5d85fc15f60e403bccfeb9 Co-Authored-By: Eric Ball Co-Authored-By: Thanh Ha Signed-off-by: Jeremy Phelps --- diff --git a/docs/commands/dco.rst b/docs/commands/dco.rst new file mode 100644 index 00000000..534b2701 --- /dev/null +++ b/docs/commands/dco.rst @@ -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). + diff --git a/docs/commands/index.rst b/docs/commands/index.rst index 86e449ba..2e815089 100644 --- a/docs/commands/index.rst +++ b/docs/commands/index.rst @@ -10,6 +10,7 @@ bash. It supports the following commands. config deploy + dco license nexus openstack diff --git a/lftools/cli/__init__.py b/lftools/cli/__init__.py index 635941af..25fc94e2 100644 --- a/lftools/cli/__init__.py +++ b/lftools/cli/__init__.py @@ -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 index 00000000..86d2d94e --- /dev/null +++ b/lftools/cli/dco.py @@ -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) diff --git a/setup.py b/setup.py index 933d7400..afbb0da0 100644 --- 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 index 00000000..df93825d --- /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