Changes to gnats/gnats/file-pr.c

"Andrew J. Gray" <[email protected]> Thu, 24 Oct 2002 08:45:10 -0400
Newsgroups gmane.comp.bug-tracking.gnats.patches
Message-ID <[email protected]>
Index: gnats/gnats/file-pr.c
diff -c gnats/gnats/file-pr.c:1.47 gnats/gnats/file-pr.c:1.48
*** gnats/gnats/file-pr.c:1.47	Sat Oct 12 18:52:02 2002
--- gnats/gnats/file-pr.c	Thu Oct 24 08:45:09 2002
***************
*** 35,40 ****
--- 35,43 ----
  static int getBugNumber        (const DatabaseInfo database, ErrorDesc *err);
  static char* derive_submitter  (PR *pr);
  
+ static int missing_required_fields (const DatabaseInfo database, PR *pr,
+                                     ErrorDesc *err);
+ 
  
  /* Creates a PR file using the contents of PR.  If an error occurs, a
     negative value will be returned an an appropriate error code will
***************
*** 69,74 ****
--- 72,82 ----
        return -1;
      }
  
+   if (missing_required_fields (database, pr, err) > 0)
+     {
+       return -1;
+     }
+ 
    /*  If we don't have a valid submitter ID, try to get it from the "From:"
        header.  If that doesn't work, use the default from the config file.  */
  
***************
*** 427,432 ****
--- 435,462 ----
      }
  
    return bug_number;
+ }
+ 
+ static int
+ missing_required_fields (const DatabaseInfo database, PR *pr, ErrorDesc *err)
+ {
+   int cnt = 0;
+   FieldList fields = getRequiredInputFields(database);
+ 
+   while (fields != NULL)
+     {
+       const char *fldval = get_field_value (pr, NULL, fields->ent, NULL, NULL);
+       if (fldval == NULL || *fldval == '\0')
+ 	{
+           setError (err, CODE_INVALID_PR_CONTENTS,
+                     "Required field %s missing from new PR - cannot submit.",
+                     complexFieldIndexToString (fields->ent),
+                     field_value (pr, NUMBER (pr->database)));
+ 	  cnt++;
+ 	}
+       fields = fields->next;
+     }
+   return cnt;
  }
  
  /* XXX ??? !!! FIXME Shouldn't be hardcoded.   */