Skip to content

Commit

Permalink
Ensure TODOs associated with commit's RTC/CQ are addressed.
Browse files Browse the repository at this point in the history
Verify-commit will throw warnings when TODO or FIXME
tags are found with RTC or CQ numbers that are the
same as the ones in the commit message.

Change-Id: Ia1b89edfeaa99eab480d99de26397af7883798fc
RTC:166676
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/34454
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Reviewed-by: Stephen M. Cprek <smcprek@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
Ilya Smirnov authored and dcrowell77 committed Feb 3, 2017
1 parent c36ec02 commit 03e362b
Showing 1 changed file with 169 additions and 0 deletions.
169 changes: 169 additions & 0 deletions src/build/tools/verify-commit
Expand Up @@ -33,8 +33,13 @@ my $projectName = $ENV{'PROJECT_NAME'};
# Relative path of import tree from project root
my $importPrefix = $ENV{'IMPORT_REL_PATH'}."/";

my $rtcNumber = rtc_workitem_num();
my $cqNumber = cq_workitem_num();

verifyPatchSet(); # Verify the patch contents.
verifyCommitMsg(); # Verify the commit message.
verifyTodoFixme(); # Make sure there are no TODO/FIXME
# associated with current RTC/CQ

# Finish out the divider.
if ($issueFound)
Expand Down Expand Up @@ -334,6 +339,70 @@ sub verifyCommitMsg
}
}

# sub verifyTodoFixme
#
# Verifies that there are no Todo or Fixme
# tags in the code with the current commit's
# RTC or CQ number.
#
sub verifyTodoFixme
{
my $file;
my $commentText;
my $lineNumber;
# Get the list of TODO/FIXME lines in src/
open TODO_LIST, "egrep -rn '(TODO.*(CQ|RTC).*)|(FIXME.*(CQ|RTC).*)' src/* |"
or die "Cannot get the list of TODO/FIXME lines.\n";

while(my $line = <TODO_LIST>)
{
chomp $line;
if(check_rtc_todo_fixme($line))
{
($file, $commentText, $lineNumber) = parse_todo_fixme_line($line);
strong_warning($file, $commentText, $lineNumber,
"TODO/FIXME tag with the same RTC number as in the current commit message.");
}
elsif(check_cq_todo_fixme($line))
{
($file, $commentText, $lineNumber) = parse_todo_fixme_line($line);
strong_warning($file, $commentText, $lineNumber,
"TODO/FIXME tag with the same CQ number as in the current commit message.");
}
}
}

sub parse_todo_fixme_line
{
my $line = shift;
my ($file, $lineNumber, $commentText) = split(/:/, $line, 3);
return ($file, $commentText, $lineNumber);
}

sub check_rtc_todo_fixme
{
my $line = shift;
if($line =~ m/RTC\s*:*\s*([0-9]+)/ &&
$1 eq $rtcNumber && $rtcNumber ne "")
{
return 1;
}

return 0;
}

sub check_cq_todo_fixme
{
my $line = shift;
if($line =~ m/CQ\s*:*\s*([A-Z][A-Z][0-9]+)/ &&
$1 eq $cqNumber && $cqNumber ne "")
{
return 1;
}

return 0;
}

sub warning
{
my ($file, $line, $count, $statement) = @_;
Expand All @@ -345,6 +414,20 @@ sub warning
$issueFound = 1;
}

sub strong_warning
{
my ($file, $line, $count, $statement) = @_;

# Always show strong warnings
print "------------------------------------------------------------\n";
print "***WARNING: $statement\n";
print " $file:$count\n";
print " $line\n";

$issueFound = 1;
$warningCount++;
}

sub error
{
my ($file, $line, $count, $statement) = @_;
Expand All @@ -357,3 +440,89 @@ sub error
$errorFound = 1;
}

# sub rtc_workitem_num
#
# Determines the RTC WorkItem associated with a git commit.
#
# @param[in] commit - The git commit, or no parameter for last commit
#
# @return string - RTC WorkItem number (or "").
#
sub rtc_workitem_num
{
my $commit = shift;
my $message;

if(defined($commit))
{
$message = git_commit_msg($commit);
}
else
{
$message = git_commit_msg("");
}

if ($message =~ m/RTC:\s*([0-9]+)/)
{
return $1;
}
else
{
return "";
}
}


# sub cq_workitem_num
#
# Determines the CQ WorkItem associated with a git commit.
#
# @param[in] commit - The git commit, or no parameter for last commit
#
# @return string - CQ WorkItem number (or "").
#
sub cq_workitem_num
{
my $commit = shift;
my $message;

if(defined($commit))
{
$message = git_commit_msg($commit);
}
else
{
$message = git_commit_msg("");
}

if ($message =~ m/CQ:\s*([A-Z][A-Z][0-9]+)/)
{
return $1;
}
else
{
return "";
}
}

# sub git_commit_msg
#
# Get the entire commit message associated with a commit.
#
# @param[in] commit - The commit to examine.
# @return string - The commit message.
#
sub git_commit_msg
{
my $commit = shift;
open COMMAND, "git log -n1 --pretty=%B $commit |";
my $message = "";
while (my $line = <COMMAND>)
{
$message = $message.$line;
}
close COMMAND;

return $message;
}

0 comments on commit 03e362b

Please sign in to comment.