@@ -215,13 +215,20 @@ func (a *Applier) CreateTree(ctx context.Context) (*github.Tree, error) {
215
215
return tree , nil
216
216
}
217
217
218
- // Commit commits the latest tree, optionally using the details in header. If
219
- // there are pending tree entries, it calls CreateTree before creating the
220
- // commit. If header is nil or missing fields, Commit uses a default message,
221
- // the current time, and the authenticated user as needed for the commit
222
- // details. Commit returns an error if there are no pending trees or tree
223
- // entries.
224
- func (a * Applier ) Commit (ctx context.Context , header * gitdiff.PatchHeader ) (* github.Commit , error ) {
218
+ // Commit commits the latest tree, optionally using the details in tmpl and
219
+ // header. If there are pending tree entries, it calls CreateTree before
220
+ // creating the commit. It returns an error if there are no pending trees or
221
+ // tree entries.
222
+ //
223
+ // If tmpl is not nil, Commit uses it as a template for the new commit,
224
+ // overwriting fields as needed. If header is not nil, Commit uses it to set
225
+ // the message, author, and committer for the new commit. Values in header
226
+ // overwrite those in tmpl.
227
+ //
228
+ // If both tmpl and header are nil or missing fields, Commit uses a default
229
+ // message, the current time, and the authenticated user as needed for the
230
+ // commit details.
231
+ func (a * Applier ) Commit (ctx context.Context , tmpl * github.Commit , header * gitdiff.PatchHeader ) (* github.Commit , error ) {
225
232
if ! a .uncommitted && len (a .entries ) == 0 {
226
233
return nil , errors .New ("no pending tree or tree entries" )
227
234
}
@@ -231,13 +238,16 @@ func (a *Applier) Commit(ctx context.Context, header *gitdiff.PatchHeader) (*git
231
238
}
232
239
}
233
240
234
- c := & github.Commit {
235
- Tree : & github.Tree {
236
- SHA : github .String (a .tree ),
237
- },
238
- Parents : []* github.Commit {
239
- a .commit ,
240
- },
241
+ var c github.Commit
242
+ if tmpl != nil {
243
+ c = * tmpl
244
+ }
245
+
246
+ c .Tree = & github.Tree {
247
+ SHA : github .String (a .tree ),
248
+ }
249
+ c .Parents = []* github.Commit {
250
+ a .commit ,
241
251
}
242
252
243
253
if header != nil {
@@ -249,7 +259,7 @@ func (a *Applier) Commit(ctx context.Context, header *gitdiff.PatchHeader) (*git
249
259
c .Message = github .String ("Apply patch with patch2pr" )
250
260
}
251
261
252
- commit , _ , err := a .client .Git .CreateCommit (ctx , a .owner , a .repo , c )
262
+ commit , _ , err := a .client .Git .CreateCommit (ctx , a .owner , a .repo , & c )
253
263
if err != nil {
254
264
return nil , err
255
265
}
0 commit comments