Skip to content

Commit 4d79e72

Browse files
committed
Mods to support Slack and JIRA services (#175 and #176).
1 parent ab48610 commit 4d79e72

File tree

3 files changed

+273
-55
lines changed

3 files changed

+273
-55
lines changed

src/main/java/org/gitlab4j/api/AbstractApi.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.ws.rs.core.StreamingOutput;
1212

1313
import org.gitlab4j.api.GitLabApi.ApiVersion;
14+
import org.gitlab4j.api.models.Project;
1415

1516
/**
1617
* This class is the base class for all the sub API classes. It provides implementations of
@@ -24,6 +25,42 @@ public AbstractApi(GitLabApi gitLabApi) {
2425
this.gitLabApi = gitLabApi;
2526
}
2627

28+
/**
29+
* Returns the project ID or path from the provided Integer, String, or Project instance.
30+
*
31+
* @param obj the object to determine the ID or path from
32+
* @return the project ID or path from the provided Integer, String, or Project instance
33+
* @throws GitLabApiException if any exception occurs during execution
34+
*/
35+
public Object getProjectIdOrPath(Object obj) throws GitLabApiException {
36+
37+
if (obj == null) {
38+
throw (new RuntimeException("Cannot determine ID or path from null object"));
39+
} else if (obj instanceof Integer) {
40+
return (obj);
41+
} else if (obj instanceof String) {
42+
return (urlEncode(((String) obj).trim()));
43+
} else if (obj instanceof Project) {
44+
45+
Integer id = ((Project) obj).getId();
46+
if (id != null && id.intValue() > 0) {
47+
return (id);
48+
}
49+
50+
String path = ((Project) obj).getPath();
51+
if (path != null && path.trim().length() > 0) {
52+
return (urlEncode(path.trim()));
53+
}
54+
55+
throw (new RuntimeException("Cannot determine ID or path from provided Project instance"));
56+
57+
} else {
58+
59+
throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() +
60+
" instance, must be Integer, String, or Project instance"));
61+
}
62+
}
63+
2764
protected ApiVersion getApiVersion() {
2865
return (gitLabApi.getApiVersion());
2966
}

0 commit comments

Comments
 (0)