From f0a1de62f1abc37c8a627c7b5ab393e5e67f48c3 Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Mon, 30 Nov 2015 21:40:34 +1100 Subject: [PATCH] Check for correct DocImpact tag usage Enforces Review DocImpact spec. Could be used later for enforcing other formatting to commit messages (such as line length, blueprint/bug closes syntax etc.) Implements: blueprint review-docimpact Change-Id: I7846f162172a12ba3d0abade088b9301c5a0db49 --- jenkins/jobs/git.yaml | 15 +++++ jenkins/jobs/projects.yaml | 1 + jenkins/scripts/check-git-commit-message.sh | 65 +++++++++++++++++++++ zuul/layout.yaml | 4 ++ 4 files changed, 85 insertions(+) create mode 100644 jenkins/jobs/git.yaml create mode 100755 jenkins/scripts/check-git-commit-message.sh diff --git a/jenkins/jobs/git.yaml b/jenkins/jobs/git.yaml new file mode 100644 index 0000000000..7b97b4f0f6 --- /dev/null +++ b/jenkins/jobs/git.yaml @@ -0,0 +1,15 @@ +# General jobs relating to git (such as commit messages) + +- job-template: + name: 'gate-{name}-commit-message' + node: 'bare-precise || bare-trusty' + + builders: + - print-template-name: + template-name: "{template-name}" + - revoke-sudo + - zuul-git-prep + - shell: /usr/local/jenkins/slave_scripts/check-git-commit-message.sh + + publishers: + - zuul-swift-upload-console-log diff --git a/jenkins/jobs/projects.yaml b/jenkins/jobs/projects.yaml index c8ac63c34e..5b9444515e 100644 --- a/jenkins/jobs/projects.yaml +++ b/jenkins/jobs/projects.yaml @@ -3493,6 +3493,7 @@ - python-kilo-bitrot-jobs - python-liberty-bitrot-jobs - openstack-publish-jobs + - gate-{name}-commit-message - gate-{name}-pylint - gate-{name}-pip-missing-reqs - 'gate-{name}-tox-{envlist}': diff --git a/jenkins/scripts/check-git-commit-message.sh b/jenkins/scripts/check-git-commit-message.sh new file mode 100755 index 0000000000..454967f7b3 --- /dev/null +++ b/jenkins/scripts/check-git-commit-message.sh @@ -0,0 +1,65 @@ +#!/bin/bash -xe + +# Copyright 2015 Rackspace Australia +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Check the commit message at HEAD for style + + +CHECK_SUBJECT_LENGTH=${CHECK_SUBJECT_LENGTH:-0} +CHECK_DOCIMPACT_STRING=${CHECK_DOCIMPACT_STRING:-1} +COMMIT=${COMMIT:-HEAD} + +function check_subject_length { + # Checks that the subject (first line of the commit message) is less than + # the max-length + + # $1 message + # $2 max-length + + # TODO(jhesketh) if this is a thing we want + echo "check_subject_length not implemented" + exit 1 +} + + +function check_docimpact_string { + # Checks there is a description following the DocImpact tag as per + # http://specs.openstack.org/openstack/docs-specs/specs/mitaka/review-docimpact.html + + # $1 message + + # Check if there is a line starting with DocImpact (case-insensitive). + # If there is, then check it's in the correct format (case-sensitive). + echo "$1" | grep -qi "^DocImpact" + if [ $? -eq 0 ]; then + echo "$1" | grep -q "^DocImpact\: .*$" + if [ $? -ne 0 ]; then + echo "DocImpact must have a description following it." + exit 1 + fi + fi +} + + +# Grab the message +message="$(git log --format=%B -n 1 $COMMIT)" + +if [ $CHECK_SUBJECT_LENGTH -gt 0 ]; then + check_subject_length "$message" $CHECK_SUBJECT_LENGTH +fi + +if [ $CHECK_DOCIMPACT_STRING -gt 0 ]; then + check_docimpact_string "$message" +fi diff --git a/zuul/layout.yaml b/zuul/layout.yaml index b388d52a27..4ece7a74b3 100644 --- a/zuul/layout.yaml +++ b/zuul/layout.yaml @@ -1776,6 +1776,9 @@ jobs: - name: gate-tempest-dsvm-ceilometer-mongodb-full voting: false + - name: gate-nova-commit-message + voting: false + - name: gate-nova-pip-missing-reqs voting: false @@ -6637,6 +6640,7 @@ projects: - gate-tempest-dsvm-full-devstack-plugin-ceph-nv - gate-tempest-dsvm-multinode-full - gate-compute-api-guide + - gate-nova-commit-message - gate-nova-python27-constraints - gate-nova-python34-constraints - gate-nova-docs-constraints