@@ -136,16 +136,28 @@ static function factory(ProjGroup $group, string $url, $type,
136
136
throw new ValidationException (
137
137
'Invalid email used in commit: ' . $ commit ['email ' ]);
138
138
139
- if (str_starts_with ($ commit ['message ' ], 'Merge branch ' ))
139
+ $ msg = $ commit ['message ' ];
140
+ if (str_starts_with ($ msg , 'Merge branch ' ))
140
141
throw new ValidationException ('Merge commits are not allowed ' );
141
142
142
143
if (empty ($ commit ['co-authored ' ]) &&
143
- preg_match ('/Co[- ]*authored[- ]*by\s*:.*/Si ' ,
144
- $ commit ['commit ' ]['message ' ], $ m ))
144
+ preg_match ('/Co[- ]*authored[- ]*by\s*:.*/Si ' , $ msg , $ m ))
145
145
throw new ValidationException ("Invalid Co-authored-by line: \n$ m [0 ]" );
146
146
147
+ if (!empty ($ commit ['co-authored ' ])) {
148
+ $ coauthor = false ;
149
+ foreach (explode ("\n" , trim ($ msg )) as $ line ) {
150
+ if (str_starts_with ($ line , 'Co-authored-by: ' )) {
151
+ $ coauthor = true ;
152
+ } else if ($ coauthor ) {
153
+ throw new ValidationException ("Co-authored-by lines must be at " .
154
+ "the end \n$ msg " );
155
+ }
156
+ }
157
+ }
158
+
147
159
check_reasonable_name ($ commit ['name ' ], $ group );
148
- check_wrapped_commit_text ($ commit [ ' message ' ] , 72 );
160
+ check_wrapped_commit_text ($ msg , 72 );
149
161
}
150
162
151
163
if ($ url_exception = DONT_WANT_ISSUE_IN_COMMIT_MSG [$ repo ->id ] ?? '' ) {
0 commit comments