|
26 | 26 | import com.fasterxml.jackson.annotation.JsonProperty; |
27 | 27 | import com.infradna.tool.bridge_method_injector.WithBridgeMethods; |
28 | 28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
29 | | -import org.apache.commons.codec.binary.Base64; |
30 | 29 | import org.apache.commons.lang3.StringUtils; |
31 | 30 |
|
32 | 31 | import java.io.FileNotFoundException; |
|
35 | 34 | import java.io.InputStreamReader; |
36 | 35 | import java.io.InterruptedIOException; |
37 | 36 | import java.io.Reader; |
38 | | -import java.io.UnsupportedEncodingException; |
39 | 37 | import java.net.URL; |
40 | 38 | import java.util.AbstractSet; |
41 | 39 | import java.util.ArrayList; |
@@ -1394,70 +1392,43 @@ public GHContent getReadme() throws IOException { |
1394 | 1392 | return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this); |
1395 | 1393 | } |
1396 | 1394 |
|
1397 | | - public GHContentUpdateResponse createContent(GHContentUpdateRequest updateRequest) throws IOException { |
1398 | | - return createContent(updateRequest.getContent(), updateRequest.getCommitMessage(), updateRequest.getPath(), updateRequest.getBranch(), updateRequest.getSha()); |
| 1395 | + /** |
| 1396 | + * Creates a new content, or update an existing content. |
| 1397 | + */ |
| 1398 | + public GHContentBuilder createContent() { |
| 1399 | + return new GHContentBuilder(this); |
1399 | 1400 | } |
1400 | 1401 |
|
1401 | 1402 | /** |
1402 | | - * Use {@link GHContentUpdateRequest}. |
| 1403 | + * Use {@link #createContent()}. |
1403 | 1404 | */ |
1404 | 1405 | @Deprecated |
1405 | 1406 | public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException { |
1406 | | - return createContent(content.getBytes(), commitMessage, path, null, null); |
| 1407 | + return createContent().content(content).message(commitMessage).path(path).commit(); |
1407 | 1408 | } |
1408 | 1409 |
|
1409 | 1410 | /** |
1410 | | - * Use {@link GHContentUpdateRequest}. |
| 1411 | + * Use {@link #createContent()}. |
1411 | 1412 | */ |
1412 | 1413 | @Deprecated |
1413 | 1414 | public GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch) throws IOException { |
1414 | | - final byte[] payload; |
1415 | | - try { |
1416 | | - payload = content.getBytes("UTF-8"); |
1417 | | - } catch (UnsupportedEncodingException ex) { |
1418 | | - throw (IOException) new IOException("UTF-8 encoding is not supported").initCause(ex); |
1419 | | - } |
1420 | | - return createContent(payload, commitMessage, path, branch, null); |
| 1415 | + return createContent().content(content).message(commitMessage).path(path).branch(branch).commit(); |
1421 | 1416 | } |
1422 | 1417 |
|
1423 | 1418 | /** |
1424 | | - * Use {@link GHContentUpdateRequest}. |
| 1419 | + * Use {@link #createContent()}. |
1425 | 1420 | */ |
1426 | 1421 | @Deprecated |
1427 | 1422 | public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path) throws IOException { |
1428 | | - return createContent(contentBytes, commitMessage, path, null, null); |
| 1423 | + return createContent().content(contentBytes).message(commitMessage).path(path).commit(); |
1429 | 1424 | } |
1430 | 1425 |
|
1431 | 1426 | /** |
1432 | | - * Use {@link GHContentUpdateRequest}. |
| 1427 | + * Use {@link #createContent()}. |
1433 | 1428 | */ |
1434 | 1429 | @Deprecated |
1435 | 1430 | public GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch) throws IOException { |
1436 | | - return createContent(contentBytes, commitMessage, path, branch, null); |
1437 | | - } |
1438 | | - |
1439 | | - private GHContentUpdateResponse createContent(byte[] contentBytes, String commitMessage, String path, String branch, String sha1) throws IOException { |
1440 | | - Requester requester = new Requester(root) |
1441 | | - .with("path", path) |
1442 | | - .with("message", commitMessage) |
1443 | | - .with("content", Base64.encodeBase64String(contentBytes)) |
1444 | | - .method("PUT"); |
1445 | | - |
1446 | | - if (sha1 != null) { |
1447 | | - requester.with("sha", sha1); |
1448 | | - } |
1449 | | - |
1450 | | - |
1451 | | - if (branch != null) { |
1452 | | - requester.with("branch", branch); |
1453 | | - } |
1454 | | - |
1455 | | - GHContentUpdateResponse response = requester.to(getApiTailUrl("contents/" + path), GHContentUpdateResponse.class); |
1456 | | - |
1457 | | - response.getContent().wrap(this); |
1458 | | - response.getCommit().wrapUp(this); |
1459 | | - |
1460 | | - return response; |
| 1431 | + return createContent().content(contentBytes).message(commitMessage).path(path).branch(branch).commit(); |
1461 | 1432 | } |
1462 | 1433 |
|
1463 | 1434 | public GHMilestone createMilestone(String title, String description) throws IOException { |
|
0 commit comments