1 |
On Fri, 2 Feb 2018 23:53:05 +0100 |
2 |
Michał Górny <mgorny@g.o> wrote: |
3 |
|
4 |
> Add a check for common mistakes in commit messages. For now, it is |
5 |
> pretty rough and exits immediately but it should be integrated with |
6 |
> the editor in the future. |
7 |
> --- |
8 |
> repoman/pym/repoman/actions.py | 68 |
9 |
> ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 |
10 |
> insertions(+) |
11 |
> |
12 |
> diff --git a/repoman/pym/repoman/actions.py |
13 |
> b/repoman/pym/repoman/actions.py index b76a6e466..97a71d0f5 100644 |
14 |
> --- a/repoman/pym/repoman/actions.py |
15 |
> +++ b/repoman/pym/repoman/actions.py |
16 |
> @@ -124,6 +124,15 @@ class Actions(object): |
17 |
> |
18 |
> commitmessage = commitmessage.rstrip() |
19 |
> |
20 |
> + res, expl = self.verify_commit_message(commitmessage) |
21 |
> + if not res: |
22 |
> + print(bad("RepoMan does not like your commit |
23 |
> message:")) |
24 |
> + print(expl) |
25 |
> + if self.options.force: |
26 |
> + print('(but proceeding due to |
27 |
> --force)') |
28 |
> + else: |
29 |
> + sys.exit(1) |
30 |
> + |
31 |
> # Update copyright for new and changed files |
32 |
> year = time.strftime('%Y', time.gmtime()) |
33 |
> for fn in chain(mynew, mychanged): |
34 |
> @@ -585,3 +594,62 @@ class Actions(object): |
35 |
> print("* no commit message? aborting |
36 |
> commit.") sys.exit(1) |
37 |
> return commitmessage |
38 |
> + |
39 |
> + footer_re = re.compile(r'^[\w-]+:') |
40 |
> + |
41 |
> + def verify_commit_message(self, msg): |
42 |
> + """ |
43 |
> + Check whether the message roughly complies with |
44 |
> GLEP66. Returns |
45 |
> + (True, None) if it does, (False, <explanation>) if |
46 |
> it does not. |
47 |
> + """ |
48 |
> + |
49 |
> + problems = [] |
50 |
> + paras = msg.strip().split('\n\n') |
51 |
> + summary = paras.pop(0) |
52 |
> + |
53 |
> + if '\n' in summary.strip(): |
54 |
> + problems.append('commit message must start |
55 |
> with a *single* line of summary, followed by empty line') |
56 |
> + if ':' not in summary: |
57 |
> + problems.append('summary line must start |
58 |
> with a logical unit name, e.g. "cat/pkg:"') |
59 |
> + # accept 69 overall or unit+50, in case of very long |
60 |
> package names |
61 |
> + if len(summary.strip()) > 69 and |
62 |
> len(summary.split(':', 1)[-1]) > 50: |
63 |
> + problems.append('summary line is too long |
64 |
> (max 69 characters)') + |
65 |
> + multiple_footers = False |
66 |
> + gentoo_bug_used = False |
67 |
> + bug_closes_without_url = False |
68 |
> + body_too_long = False |
69 |
> + |
70 |
> + found_footer = False |
71 |
> + for p in paras: |
72 |
> + lines = p.splitlines() |
73 |
> + # if all lines look like footer material, we |
74 |
> assume it's footer |
75 |
> + # else, we assume it's body text |
76 |
> + if all(self.footer_re.match(l) for l in |
77 |
> lines if l.strip()): |
78 |
> + # multiple footer-like blocks? |
79 |
> + if found_footer: |
80 |
> + multiple_footers = True |
81 |
> + found_footer = True |
82 |
> + for l in lines: |
83 |
> + if |
84 |
> l.startswith('Gentoo-Bug'): |
85 |
> + gentoo_bug_used = |
86 |
> True |
87 |
> + elif l.startswith('Bug:') or |
88 |
> l.startswith('Closes:'): |
89 |
> + if 'http://' not in |
90 |
> l and 'https://' not in l: |
91 |
> + |
92 |
> bug_closes_without_url = True |
93 |
> + else: |
94 |
> + for l in lines: |
95 |
> + if len(l.strip()) > 72: |
96 |
> + body_too_long = True |
97 |
> + |
98 |
> + if multiple_footers: |
99 |
> + problems.append('multiple footer-style |
100 |
> blocks found, please combine them into one') |
101 |
> + if gentoo_bug_used: |
102 |
> + problems.append('please replace Gentoo-Bug |
103 |
> with GLEP 66-compliant Bug/Closes') |
104 |
> + if bug_closes_without_url: |
105 |
> + problems.append('Bug/Closes footers require |
106 |
> full URL') |
107 |
> + if body_too_long: |
108 |
> + problems.append('body lines should be |
109 |
> wrapped at 72 characters') + |
110 |
> + if problems: |
111 |
> + return (False, '\n'.join('- %s' % x for x in |
112 |
> problems)) |
113 |
> + return (True, None) |
114 |
|
115 |
|
116 |
I know there are not a lot of repoman unit tests, but, can you please |
117 |
create some to test this? That way it doesn't get any worse. |
118 |
|
119 |
In the PR, you mentioned adding in an editor call to re-edit the |
120 |
message. This would be a good thing and I know is not that difficult |
121 |
to accomplish. Is this coming in another patch? |
122 |
|
123 |
-- |
124 |
Brian Dolbec <dolsen> |