Skip to content

Commit

Permalink
support private repo sha get. at 2022-01-13 14:12:33
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhaiai committed Jan 13, 2022
1 parent 8a0ab76 commit bdb5f75
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/ff/jnezha/jnt/cs/GithubHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static String updateContent(String owner, String repo, String path, Strin
String content = TextUtils.encodeBase64ToString(contentWillBase64);
String base = "https://api.github.com/repos/%s/%s/contents%s";
String uploadUrl = String.format(base, owner, repo, path);
Map<String, ShaInfo> shas = getSha(owner, repo, path);
Map<String, ShaInfo> shas = getSha(owner, repo, path, token);

if (shas == null || shas.size() < 1) {
// 不存在. 则新建
Expand Down Expand Up @@ -126,7 +126,7 @@ public static String deleteFile(String owner, String repo, String path, String t
String base = "https://api.github.com/repos/%s/%s/contents%s";
String uploadUrl = String.format(base, owner, repo, path);

Map<String, ShaInfo> shas = getSha(owner, repo, path);
Map<String, ShaInfo> shas = getSha(owner, repo, path, token);

if (shas == null || shas.size() < 1) {
return "";
Expand Down Expand Up @@ -157,7 +157,7 @@ public static void deleteDir(String owner, String repo, String path, String toke

String base = "https://api.github.com/repos/%s/%s/contents%s";
// String uploadUrl = String.format(base, owner, repo, path);
Map<String, ShaInfo> shas = getSha(owner, repo, path);
Map<String, ShaInfo> shas = getSha(owner, repo, path, token);
if (shas == null || shas.size() < 1) {
return;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public static String createFile(String owner, String repo, String path, String t
public static String createFile(boolean isNeedBase64, String owner, String repo, String path, String token, String uploadContent, String commitMsg, String username, String email) {
try {

Map<String, ShaInfo> shas = getSha(owner, repo, path);
Map<String, ShaInfo> shas = getSha(owner, repo, path, token);
if (shas != null && shas.size() > 0) {
ShaInfo s = shas.get(path);
if (s != null && !TextUtils.isEmpty(s.download_url)) {
Expand Down Expand Up @@ -293,19 +293,21 @@ public static String createFile(boolean isNeedBase64, String owner, String repo,
* "documentation_url": "https://docs.github.com/rest/reference/repos#get-repository-content"
* }
*
* @param owner a {@link java.lang.String} object.
* @param repo a {@link java.lang.String} object.
* @param path a {@link java.lang.String} object.
* @param owner a {@link String} object.
* @param repo a {@link String} object.
* @param path a {@link String} object.
* @param token
* @return
*/
public static Map<String, ShaInfo> getSha(String owner, String repo, String path) {
public static Map<String, ShaInfo> getSha(String owner, String repo, String path, String token) {
Map<String, ShaInfo> shaBody = new HashMap<String, ShaInfo>();
try {
String base = "https://api.github.com/repos/%s/%s/contents%s";
String requestUrl = String.format(base, owner, repo, path);
// System.out.println("getSha url:" + requestUrl);

String result = Jnt.get(requestUrl);
// add header, support private token
String result = Jnt.get(requestUrl, getHttpHeader(token));
// update map
if (TextUtils.isEmpty(result)) {
return shaBody;
Expand Down

0 comments on commit bdb5f75

Please sign in to comment.