Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a56357f

Browse filesBrowse files
Implement the ability to retrieve conent if not populated.
The create and update API calls don't send back the content you just sent, so that field is null. If this GHContent was instantiated from one of those calls, we want to make sure we can retrieve the content (and updated sha, etc) on the fly.
1 parent f8d14d2 commit a56357f
Copy full SHA for a56357f

File tree

Expand file treeCollapse file tree

1 file changed

+28
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-2
lines changed

‎src/main/java/org/kohsuke/github/GHContent.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHContent.java
+28-2Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,37 @@ public String getPath() {
5151
return path;
5252
}
5353

54-
public String getContent() {
54+
/**
55+
* Retrieve the decoded content that is stored at this location.
56+
*
57+
* Due to the nature of GitHub's API, you're not guaranteed that
58+
* the content will already be populated, so this may trigger
59+
* network activity, and can throw an IOException.
60+
**/
61+
public String getContent() throws IOException {
5562
return new String(DatatypeConverter.parseBase64Binary(getEncodedContent()));
5663
}
5764

58-
public String getEncodedContent() {
65+
/**
66+
* Retrieve the raw content that is stored at this location.
67+
*
68+
* Due to the nature of GitHub's API, you're not guaranteed that
69+
* the content will already be populated, so this may trigger
70+
* network activity, and can throw an IOException.
71+
**/
72+
public String getEncodedContent() throws IOException {
73+
if (content != null)
74+
return content;
75+
76+
GHContent retrievedContent = owner.getFileContent(path);
77+
78+
this.size = retrievedContent.size;
79+
this.sha = retrievedContent.sha;
80+
this.content = retrievedContent.content;
81+
this.url = retrievedContent.url;
82+
this.git_url = retrievedContent.git_url;
83+
this.html_url = retrievedContent.html_url;
84+
5985
return content;
6086
}
6187

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.