Skip to content

Commit

Permalink
(Engineering) Accept additional Gitlab issue references in commit mesgs
Browse files Browse the repository at this point in the history
The following Gitlab issue reference styles are accepted in addition
to those that were already accepted:

* Phrases like "Issue #217" and "Issue #217+" which mean issue 217 in
  the Gitlab group to which this repository belongs. Gitlab
  understands the "#217" and "#217+" part as an issue link; the word
  "Issue" before it is because Git will treat lines that start with a
  hash as if they are comments.

* Phrases like "rose#217" and "rose#217+" which mean issue 217 in a
  project named "rose" within Gitlab. Gitlab understands the entire
  phrase.

* Phrases like "foo/testing#217" and "foo/testing#217+" which mean
  issue 217 in a project named "foo/testing". Gitlab understands the
  entire phrase.

The versions that end with a "+" cause Gitlab to insert the issue
title as the link text.

The policy checker also makes sure that the issue reference list is
the last thing in the commit message.

Issue #217
Issue #217+
ROSE#217
ROSE#217+
#217
#217
  • Loading branch information
matzke1 authored and rosecompiler committed Aug 1, 2024
1 parent f40926f commit b0afbf6
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions scripts/good-commits.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ sub badTitleCategory {
# Finds a ticket number within a string and returns it.
sub findTicketNumber {
my($s) = @_;
#---------------------- Upper-case word, hyphen, number |Gitlab issue
my($ticket) = $s =~ /\b([A-Z][A-Z0-9]*(_[A-Z][A-Z0-9]*)*-\d+|Issue #\d+\+?)\b/;
#---------------------- Upper-case word, hyphen, number |Gen. Gitlab |Gitlab project
my($ticket) = $s =~ /\b([A-Z][A-Z0-9]*(_[A-Z][A-Z0-9]*)*-\d+|Issue #\d+\+?|\w+(\/\w+)*#\d+\+?)\b/;
return $ticket;
}

Expand All @@ -46,14 +46,28 @@ sub badTitle {
return;
}

# Return an error message if the commit body has no issue tracker ticket number lines
# Return an error message if the commit body doesn't end with one or more issue references.
sub badBodyIssue {
my($body) = @_;
my $ends_with_ticket_reference = 0;
my $last_line = "";
for my $line (map {s/^(.*?)\s+$/\1/; $_} (split /\n/, $body)) {
my($ticket) = findTicketNumber($line);
return if $ticket && $ticket == $line;
if ($line =~ /\S/) {
$last_line = $line;
my($ticket) = findTicketNumber($line);
if ($ticket && $ticket == $line) {
++$ends_with_ticket_reference;
} else {
$ends_with_ticket_reference = 0;
}
}
}

if ($ends_with_ticket_reference) {
return "";
} else {
return "body doesn't end with ticket number lines (last is \"$last_line\")";
}
return "body lacks issue tracker ticket number line(s)";
}

# Returns an error message if anything is wrong with the commit message body
Expand Down

0 comments on commit b0afbf6

Please sign in to comment.