master
py 96 lines 2.5 KB
Raw
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 print(f"adding upstream git repo @ {repourl}")
23 subprocess.check_call(["git", "remote", "add", "check-dco", repourl])
24 subprocess.check_call(["git", "fetch", "--refetch", "check-dco", "master"])
25
26 ancestor = subprocess.check_output(["git", "merge-base",
27 "check-dco/master", "HEAD"],
28 universal_newlines=True)
29
30 ancestor = ancestor.strip()
31
32 subprocess.check_call(["git", "remote", "rm", "check-dco"])
33
34 errors = False
35
36 print("\nChecking for 'Signed-off-by: NAME <EMAIL>' " +
37 "on all commits since %s...\n" % ancestor)
38
39 log = subprocess.check_output(["git", "log", "--format=%H %s",
40 ancestor + "..."],
41 universal_newlines=True)
42
43 if log == "":
44 commits = []
45 else:
46 commits = [[c[0:40], c[41:]] for c in log.strip().split("\n")]
47
48 for sha, subject in commits:
49
50 msg = subprocess.check_output(["git", "show", "-s", sha],
51 universal_newlines=True)
52 lines = msg.strip().split("\n")
53
54 print("🔍 %s %s" % (sha, subject))
55 sob = False
56 for line in lines:
57 if "Signed-off-by:" in line:
58 sob = True
59 if "localhost" in line:
60 print(" ❌ FAIL: bad email in %s" % line)
61 errors = True
62
63 if not sob:
64 print(" ❌ FAIL missing Signed-off-by tag")
65 errors = True
66
67 if errors:
68 print("""
69
70 ❌ ERROR: One or more commits are missing a valid Signed-off-By tag.
71
72
73 This project requires all contributors to assert that their contributions
74 are provided in compliance with the terms of the Developer's Certificate
75 of Origin 1.1 (DCO):
76
77 https://developercertificate.org/
78
79 To indicate acceptance of the DCO every commit must have a tag
80
81 Signed-off-by: YOUR NAME <EMAIL>
82
83 where "YOUR NAME" is your commonly known identity in the context
84 of the community.
85
86 This can be achieved by passing the "-s" flag to the "git commit" command.
87
88 To bulk update all commits on current branch "git rebase" can be used:
89
90 git rebase -i master -x 'git commit --amend --no-edit -s'
91
92 """)
93
94 sys.exit(1)
95
96 sys.exit(0)