-
Notifications
You must be signed in to change notification settings - Fork 428
Expand file tree
/
Copy pathGitHubName.java
More file actions
57 lines (46 loc) · 1.46 KB
/
GitHubName.java
File metadata and controls
57 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.thirtydegreesray.openhub.mvp.model;
import android.net.Uri;
import android.support.annotation.NonNull;
import com.thirtydegreesray.openhub.util.GitHubHelper;
import java.util.List;
/**
* Created by ThirtyDegreesRay on 2017/10/30 13:49:02
*/
public class GitHubName {
private String url;
private String userName;
private String repoName;
public static GitHubName fromUrl(@NonNull String url) {
if (!GitHubHelper.isGitHubUrl(url)) return null;
GitHubName gitHubName = new GitHubName();
url = url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
gitHubName.url = url;
try {
Uri uri = Uri.parse(url);
List<String> list = uri.getPathSegments();
list.remove("repos");
if (list.size() > 0) gitHubName.userName = list.get(0);
if (list.size() > 1) gitHubName.repoName = list.get(1);
} catch (Exception e) {
}
return gitHubName;
}
public String getUserName() {
return userName;
}
public String getRepoName() {
return repoName;
}
public String getReleaseTagName() {
if (!GitHubHelper.isReleaseTagUrl(url)) {
return null;
}
return url.substring(url.lastIndexOf("/") + 1);
}
public String getCommitShaName() {
if (!GitHubHelper.isCommitUrl(url)) {
return null;
}
return url.substring(url.lastIndexOf("/") + 1);
}
}