]>
Commit | Line | Data |
---|---|---|
34ed46a2 DB |
1 | #!/usr/bin/env python3 |
2 | # | |
3 | # check-dco.py: validate all commits are signed off | |
4 | # | |
5 | # Copyright (C) 2020 Red Hat, Inc. | |
6 | # | |
7 | # SPDX-License-Identifier: GPL-2.0-or-later | |
8 | ||
9 | import os | |
10 | import os.path | |
11 | import sys | |
12 | import subprocess | |
13 | ||
14 | namespace = "qemu-project" | |
15 | if len(sys.argv) >= 2: | |
16 | namespace = sys.argv[1] | |
17 | ||
18 | cwd = os.getcwd() | |
19 | reponame = os.path.basename(cwd) | |
20 | repourl = "https://gitlab.com/%s/%s.git" % (namespace, reponame) | |
21 | ||
22 | subprocess.check_call(["git", "remote", "add", "check-dco", repourl]) | |
23 | subprocess.check_call(["git", "fetch", "check-dco", "master"], | |
24 | stdout=subprocess.DEVNULL, | |
25 | stderr=subprocess.DEVNULL) | |
26 | ||
27 | ancestor = subprocess.check_output(["git", "merge-base", | |
28 | "check-dco/master", "HEAD"], | |
29 | universal_newlines=True) | |
30 | ||
31 | ancestor = ancestor.strip() | |
32 | ||
33 | subprocess.check_call(["git", "remote", "rm", "check-dco"]) | |
34 | ||
35 | errors = False | |
36 | ||
37 | print("\nChecking for 'Signed-off-by: NAME <EMAIL>' " + | |
38 | "on all commits since %s...\n" % ancestor) | |
39 | ||
40 | log = subprocess.check_output(["git", "log", "--format=%H %s", | |
41 | ancestor + "..."], | |
42 | universal_newlines=True) | |
43 | ||
44 | if log == "": | |
45 | commits = [] | |
46 | else: | |
47 | commits = [[c[0:40], c[41:]] for c in log.strip().split("\n")] | |
48 | ||
49 | for sha, subject in commits: | |
50 | ||
51 | msg = subprocess.check_output(["git", "show", "-s", sha], | |
52 | universal_newlines=True) | |
53 | lines = msg.strip().split("\n") | |
54 | ||
55 | print("🔍 %s %s" % (sha, subject)) | |
56 | sob = False | |
57 | for line in lines: | |
58 | if "Signed-off-by:" in line: | |
59 | sob = True | |
60 | if "localhost" in line: | |
61 | print(" ❌ FAIL: bad email in %s" % line) | |
62 | errors = True | |
63 | ||
64 | if not sob: | |
65 | print(" ❌ FAIL missing Signed-off-by tag") | |
66 | errors = True | |
67 | ||
68 | if errors: | |
69 | print(""" | |
70 | ||
71 | ❌ ERROR: One or more commits are missing a valid Signed-off-By tag. | |
72 | ||
73 | ||
74 | This project requires all contributors to assert that their contributions | |
75 | are provided in compliance with the terms of the Developer's Certificate | |
76 | of Origin 1.1 (DCO): | |
77 | ||
78 | https://developercertificate.org/ | |
79 | ||
80 | To indicate acceptance of the DCO every commit must have a tag | |
81 | ||
82 | Signed-off-by: REAL NAME <EMAIL> | |
83 | ||
84 | This can be achieved by passing the "-s" flag to the "git commit" command. | |
85 | ||
86 | To bulk update all commits on current branch "git rebase" can be used: | |
87 | ||
88 | git rebase -i master -x 'git commit --amend --no-edit -s' | |
89 | ||
90 | """) | |
91 | ||
92 | sys.exit(1) | |
93 | ||
94 | sys.exit(0) |