diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index bd8c1ff7af2..15b602595c4 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -157,6 +157,7 @@ author_line_regex = \ additional_author_regex = re.compile(r'^\t(?P\ *)?(?P.* <.*>)') changelog_regex = re.compile(r'^(?:[fF]or +)?([a-z0-9+-/]*)ChangeLog:?') pr_regex = re.compile(r'\tPR (?P[a-z+-]+\/)?([0-9]+)$') +title_pr_regex = re.compile(r' \[PR ?([0-9]+)]$') dr_regex = re.compile(r'\tDR ([0-9]+)$') star_prefix_regex = re.compile(r'\t\*(?P\ *)(?P.*)') end_of_location_regex = re.compile(r'[\[<(:]') @@ -343,6 +344,7 @@ class GitCommit: self.check_for_broken_parentheses() self.deduce_changelog_locations() self.check_file_patterns() + self.check_pr_consistent() if not self.errors: self.check_mentioned_files() self.check_for_correct_changelog() @@ -568,6 +570,18 @@ class GitCommit: msg = 'unsupported wildcard prefix' self.errors.append(Error(msg, name)) + def check_pr_consistent(self): + """Check that a 'PR component/nnn' line is present if the first + line ends with a bug number like [PRnnn] or [PR nnn].""" + title_pr = title_pr_regex.search(self.info.lines[0]) + if title_pr: + for line in self.changes: + body_pr = pr_regex.match(line) + if body_pr and body_pr.group(2) == title_pr.group(1): + return + msg = 'changelog does not contain the PR in the summary:%s' + self.errors.append(Error(msg % title_pr.group())) + def check_for_empty_description(self): for entry in self.changelog_entries: for i, line in enumerate(entry.lines):