11package org .kohsuke .github ;
22
3+ import com .fasterxml .jackson .annotation .JsonInclude ;
4+ import com .fasterxml .jackson .annotation .JsonInclude .Include ;
5+
36import java .io .IOException ;
47import java .nio .charset .StandardCharsets ;
8+ import java .time .Instant ;
59import java .util .Base64 ;
10+ import java .util .Date ;
611
712// TODO: Auto-generated Javadoc
813/**
1520 * @see GHRepository#createContent() GHRepository#createContent()
1621 */
1722public final class GHContentBuilder {
23+ @ JsonInclude (Include .NON_NULL )
24+ private static final class UserInfo {
25+ private final String date ;
26+ private final String email ;
27+ private final String name ;
28+
29+ private UserInfo (String name , String email , Instant date ) {
30+ this .name = name ;
31+ this .email = email ;
32+ this .date = date != null ? GitHubClient .printInstant (date ) : null ;
33+ }
34+ }
35+
1836 private String path ;
1937 private final GHRepository repo ;
2038 private final Requester req ;
@@ -30,6 +48,52 @@ public final class GHContentBuilder {
3048 this .req = repo .root ().createRequest ().method ("PUT" );
3149 }
3250
51+ /**
52+ * Configures the author of the commit. If not specified, the authenticated user is used as the author.
53+ *
54+ * @param name
55+ * the name of the author
56+ * @param email
57+ * the email of the author
58+ * @return the gh content builder
59+ */
60+ public GHContentBuilder author (String name , String email ) {
61+ return author (name , email , (Instant ) null );
62+ }
63+
64+ /**
65+ * Configures the author of the commit. If not specified, the authenticated user is used as the author.
66+ *
67+ * @param name
68+ * the name of the author
69+ * @param email
70+ * the email of the author
71+ * @param date
72+ * the date of the authoring
73+ * @return the gh content builder
74+ * @deprecated use {@link #author(String, String, Instant)} instead
75+ */
76+ @ Deprecated
77+ public GHContentBuilder author (String name , String email , Date date ) {
78+ return author (name , email , GitHubClient .toInstantOrNull (date ));
79+ }
80+
81+ /**
82+ * Configures the author of the commit. If not specified, the authenticated user is used as the author.
83+ *
84+ * @param name
85+ * the name of the author
86+ * @param email
87+ * the email of the author
88+ * @param date
89+ * the timestamp for the authoring
90+ * @return the gh content builder
91+ */
92+ public GHContentBuilder author (String name , String email , Instant date ) {
93+ req .with ("author" , new UserInfo (name , email , date ));
94+ return this ;
95+ }
96+
3397 /**
3498 * Branch gh content builder.
3599 *
@@ -59,6 +123,52 @@ public GHContentUpdateResponse commit() throws IOException {
59123 return response ;
60124 }
61125
126+ /**
127+ * Configures the committer of the commit. If not specified, the authenticated user is used as the committer.
128+ *
129+ * @param name
130+ * the name of the committer
131+ * @param email
132+ * the email of the committer
133+ * @return the gh content builder
134+ */
135+ public GHContentBuilder committer (String name , String email ) {
136+ return committer (name , email , (Instant ) null );
137+ }
138+
139+ /**
140+ * Configures the committer of the commit. If not specified, the authenticated user is used as the committer.
141+ *
142+ * @param name
143+ * the name of the committer
144+ * @param email
145+ * the email of the committer
146+ * @param date
147+ * the date of the commit
148+ * @return the gh content builder
149+ * @deprecated use {@link #committer(String, String, Instant)} instead
150+ */
151+ @ Deprecated
152+ public GHContentBuilder committer (String name , String email , Date date ) {
153+ return committer (name , email , GitHubClient .toInstantOrNull (date ));
154+ }
155+
156+ /**
157+ * Configures the committer of the commit. If not specified, the authenticated user is used as the committer.
158+ *
159+ * @param name
160+ * the name of the committer
161+ * @param email
162+ * the email of the committer
163+ * @param date
164+ * the timestamp of the commit
165+ * @return the gh content builder
166+ */
167+ public GHContentBuilder committer (String name , String email , Instant date ) {
168+ req .with ("committer" , new UserInfo (name , email , date ));
169+ return this ;
170+ }
171+
62172 /**
63173 * Content gh content builder.
64174 *
0 commit comments