Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
4d79e72b
Commit
4d79e72b
authored
Apr 22, 2018
by
Greg Messner
Browse files
Mods to support Slack and JIRA services (#175 and #176).
parent
ab486100
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/AbstractApi.java
View file @
4d79e72b
...
...
@@ -11,6 +11,7 @@ import javax.ws.rs.core.Response;
import
javax.ws.rs.core.StreamingOutput
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.Project
;
/**
* This class is the base class for all the sub API classes. It provides implementations of
...
...
@@ -24,6 +25,42 @@ public abstract class AbstractApi implements Constants {
this
.
gitLabApi
=
gitLabApi
;
}
/**
* Returns the project ID or path from the provided Integer, String, or Project instance.
*
* @param obj the object to determine the ID or path from
* @return the project ID or path from the provided Integer, String, or Project instance
* @throws GitLabApiException if any exception occurs during execution
*/
public
Object
getProjectIdOrPath
(
Object
obj
)
throws
GitLabApiException
{
if
(
obj
==
null
)
{
throw
(
new
RuntimeException
(
"Cannot determine ID or path from null object"
));
}
else
if
(
obj
instanceof
Integer
)
{
return
(
obj
);
}
else
if
(
obj
instanceof
String
)
{
return
(
urlEncode
(((
String
)
obj
).
trim
()));
}
else
if
(
obj
instanceof
Project
)
{
Integer
id
=
((
Project
)
obj
).
getId
();
if
(
id
!=
null
&&
id
.
intValue
()
>
0
)
{
return
(
id
);
}
String
path
=
((
Project
)
obj
).
getPath
();
if
(
path
!=
null
&&
path
.
trim
().
length
()
>
0
)
{
return
(
urlEncode
(
path
.
trim
()));
}
throw
(
new
RuntimeException
(
"Cannot determine ID or path from provided Project instance"
));
}
else
{
throw
(
new
RuntimeException
(
"Cannot determine ID or path from provided "
+
obj
.
getClass
().
getSimpleName
()
+
" instance, must be Integer, String, or Project instance"
));
}
}
protected
ApiVersion
getApiVersion
()
{
return
(
gitLabApi
.
getApiVersion
());
}
...
...
src/main/java/org/gitlab4j/api/ServicesApi.java
View file @
4d79e72b
This diff is collapsed.
Click to expand it.
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
4d79e72b
...
...
@@ -67,6 +67,7 @@ import org.gitlab4j.api.models.SystemHook;
import
org.gitlab4j.api.models.Tag
;
import
org.gitlab4j.api.models.TreeItem
;
import
org.gitlab4j.api.models.User
;
import
org.gitlab4j.api.services.SlackService
;
import
org.gitlab4j.api.systemhooks.ProjectSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.PushSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.SystemHookEvent
;
...
...
@@ -463,6 +464,17 @@ public class TestGitLabApiBeans {
}
}
@Test
public
void
testSlackService
()
{
try
{
SlackService
slackNotifications
=
makeFakeApiCall
(
SlackService
.
class
,
"slack-notifications"
);
assertTrue
(
compareJson
(
slackNotifications
,
"slack-notifications"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testSystemHook
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment