2 ################################################################################
4 # File: CheckinPreop.pl
5 # Description: This trigger script is run when the user is attempting to
6 # checkin. Several checks are performed on the check in comment.
7 # The comment should contain the bug ID, which we will later used
8 # to label this element checkin (See CheckinPostop.pl). We will
9 # also check to insure the bug ID is valid in Clearquest and that
10 # the bug is in the proper state.
12 # If the check in is on the "main" or "trial" branch then we will
13 # consult a file to insure that the bug ID is listed. This is an
14 # additional method for limiting checkins.
15 # Assumptions: Clearprompt is in the users PATH
16 # Author: Andrew@DeFaria.com
17 # Created: Fri Oct 26 15:32:12 2001
19 # Modifications:6/25/2002: Added check to see if a bug ID label exists and it
20 # is locked. If so then that's an indication that we should not
22 # 6/20/2002: Added interface to cqd to verify that the bug exists
23 # in Clearquest, is of a certain state and has an owner
24 # 5/15/2002: Added tests so that bug IDs must exist in
25 # mainbugs.txt or trialbugs.txt for the main and trial branches.
26 # 5/17/2002: Exempted EMS code.
27 # 5/31/2002: Exempted hardware code.
28 # 10/22/2002: Changed to allow checkins to main branch with no
29 # bug IDs. Removed $mainbugs.
30 # 11/20/2002: It was determined to relax restrictions of checkins
31 # for non 1.0 branches such that bug ID's are not required, in fact
32 # they are not allowed.
33 # 04/11/2003: Added support for multiple bug IDs in the comment
34 # 05/18/2003: Changed code to only check for bug IDs in comments
35 # for check ins on certain branches.
37 # (c) Copyright 2003, Andrew@DeFaria.com, all rights reserved
39 ################################################################################
45 # Add the appropriate path to our modules to @INC array. We use ipconfig to
46 # get the current host's IP address then determine whether we are in the US
48 my @ipconfig = grep (/IP Address/, `ipconfig`);
49 my ($ipaddr) = ($ipconfig[0] =~ /(\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3})/);
51 # US is in the subnets of 192 and 172 while China is in the subnet of 10
52 if ($ipaddr =~ /^192|^172/) {
54 unshift (@INC, "//sons-clearcase/Views/official/Tools/lib");
55 } elsif ($ipaddr =~ /^10/) {
57 unshift (@INC, "//sons-cc/Views/official/Tools/lib");
59 die "Internal Error: Unable to find our modules!\n"
68 # The following environment variables are set by Clearcase when this
70 my $comment = $ENV{CLEARCASE_COMMENT};
71 my $branch = $ENV{CLEARCASE_BRTYPE};
72 my $pname = $ENV{CLEARCASE_PN};
74 # Which vob we will look up labels in
82 my @fields = split (/\W/,$comment);
83 my $bugid = "unknown";
86 if (/BUGS2[0-9]{8}/) {
98 my @fields = split (/\W/,$comment);
100 # Use associative array to insure uniqueness
102 # Return unique array
106 if (/BUGS2[0-9]{8}/) {
111 foreach (keys %bugids) {
126 return 1 if $pname =~ /salira\\ems/i;
128 # Excempt Hardware code
129 return 1 if $pname =~ /salira\\hardware/i;
132 return 1 if $bugid eq "BUGS200002912";
135 return 1 if $bugid eq "BUGS200003035";
140 $filename = "//sons-clearcase/Views/official/Tools/bin/clearcase/triggers/data/$branch.lst";
141 } elsif ($site eq "CN") {
142 $filename = "//sons-cc/Views/official/Tools/bin/clearcase/triggers/data/$branch.lst";
144 die "Internal Error: Site not set properly! ($site)\n";
148 open (FILE, $filename) || die "Can't open $filename!\n";
151 $bug = ExtractBugID $_;
152 next if ($bug eq "unknown");
153 if ($bug eq $bugid) {
161 clearlog "Skipping check because $filename does not exist!";
162 # Since there is no file list to check return that the bug id was found
170 # 04/28/2003: Oddity! All of a sudden this subroutine broke! I don't know
171 # why but even though we used to cd to the official view and issue our
172 # cleartool lslock command we started getting "Unable to determine VOB
173 # from pname" errors. Weird! Anyways we have changed to use the @<vob
174 # selector> syntax instead. This means we must now specify the vob
175 # specifically. Fortunately we only have one vob to worry about at this
176 # time. On the plus side we no longer need to rely on the "official" view.
179 my $output = `cleartool lslock -short lbtype:$bugid@\\$vob 2>&1`;
192 my @valid_branches = (
207 if ($comment eq "") {
208 clearlogmsg "You need to specify checkin comments";
212 if (length $comment <= 4) {
213 clearlogmsg "The comment, '$comment' is too short!";
217 if ($comment !~ m/.*BUGS2[0-9]{8}.*/) {
218 # Bug ID's are only required on certain branches
221 foreach (@valid_branches) {
229 clearlogmsg "Could not find bug ID in comment! This is required for the $branch branch";
242 foreach my $bugid (@bugs) {
243 # Check if label is locked
244 if (LabelLocked ($bugid)) {
245 clearlog "Bug id $bugid is locked!";
246 clearmsg "Bug id $bugid is locked!\nSee your Clearcase Admin to unlock it";
250 # Get Clearquest information
251 $result = cqc::GetBugRecord ($bugid, %fields);
254 # Make sure bug is owned
255 if ($fields {owner} eq "<Unspecified>") {
256 clearlogmsg "No owner specified in Clearquest for bug ID $bugid.";
260 # Make sure bug is in the correct state
261 if ($fields {state} ne "Assigned" and $fields {state} ne "Resolved") {
262 clearlogmsg "Bug ID $bugid is in the wrong state. It is in the " . $fields {state}. " state but should be in Assigned or Resolved state.";
265 } elsif ($result > 0) {
266 clearlogmsg "Bug ID $bugid is not in Clearquest.";
269 clearlogmsg "Clearquest Daemon (cqd) is not running!
270 Please contact the Clearquest Administrator.";
274 # Check if bug is on a branch list file
275 if (! BugOnList ($bugid, $branch)) {
276 clearlog "Bug ID $bugid is not on the list of acceptable bugs for the $branch branch!";
277 clearmsg "Bug ID $bugid is not on the list\nof acceptable bugs for the $branch branch!";
283 clearlog "Checkin checks started for $pname on $branch branch";
285 if (CheckComment ($comment, $branch)) {
287 } elsif (CheckBugIDs (ExtractBugIDs $comment)) {
291 clearlog "Successful precheckin of $pname on $branch branch with bug ID $bugid";