-
Notifications
You must be signed in to change notification settings - Fork 475
Fix #858: Added missing TopicsApi #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f170545
Removed JavaDoc Error
NadeoWolf 5532778
Added topics
NadeoWolf a844abd
Minor Changes for the TopicsApi
NadeoWolf 90cc914
Renamed TopicsApi.setTopicAvatar to TopicsApi.updateTopicAvatar.
NadeoWolf f63fef9
Removed Topic and TopicID from existing Methods to mantain backwards …
NadeoWolf 1cb3685
Topic improvements
jmini a543024
Fix Javadoc
jmini 315d64f
Fix Javadoc.
NadeoWolf 1cb014c
Fix upload with "null"
jmini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
package org.gitlab4j.api; | ||
|
||
import org.gitlab4j.api.models.Topic; | ||
import org.gitlab4j.api.models.TopicParams; | ||
|
||
import javax.ws.rs.core.GenericType; | ||
import javax.ws.rs.core.Response; | ||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
public class TopicsApi extends AbstractApi{ | ||
|
||
public TopicsApi(GitLabApi gitLabApi) { | ||
super(gitLabApi); | ||
} | ||
|
||
/** | ||
* <p>Get a list of Topics. </p> | ||
* | ||
* <strong>WARNING:</strong> Do not use this method to fetch Topics from https://gitlab.com, | ||
* gitlab.com has many 1,000's of public topics and it will a long time to fetch all of them. | ||
* Instead use {@link #getTopics(int itemsPerPage)} which will return a Pager of Topic instances. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /topics</code></pre> | ||
* | ||
* @return the list of topics viewable by the authenticated user | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public List<Topic> getTopics() throws GitLabApiException { | ||
return (getTopics(getDefaultPerPage()).all()); | ||
} | ||
|
||
/** | ||
* Get a list of topics in the specified page range. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /topics</code></pre> | ||
* | ||
* @param page the page to get | ||
* @param perPage the number of Topic instances per page | ||
* @return the list of topics | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public List<Topic> getTopics(int page, int perPage) throws GitLabApiException { | ||
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "topics"); | ||
return (response.readEntity(new GenericType<List<Topic>>() {})); | ||
} | ||
|
||
/** | ||
* Get a Pager of topics. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /topics</code></pre> | ||
* | ||
* @param itemsPerPage the number of Topic instances that will be fetched per page | ||
* @return the pager of topics | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Pager<Topic> getTopics(int itemsPerPage) throws GitLabApiException { | ||
return (new Pager<Topic>(this, Topic.class, itemsPerPage, null, "topics")); | ||
} | ||
|
||
/** | ||
* Get a Stream of topics. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /topics</code></pre> | ||
* | ||
* @return the stream of topics | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Stream<Topic> getTopicsStream() throws GitLabApiException { | ||
return (getTopics(getDefaultPerPage()).stream()); | ||
} | ||
|
||
/** | ||
* Get all details of a topic. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /topics/:id</code></pre> | ||
* | ||
* @param id the topic ID | ||
* @return the topic for the specified topic id | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Topic getTopic(Integer id) throws GitLabApiException { | ||
Response response = get(Response.Status.OK, null, "topics", id); | ||
return (response.readEntity(Topic.class)); | ||
} | ||
|
||
/** | ||
* Get all details of a topic as an Optional instance. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /topics/:id</code></pre> | ||
* | ||
* @param id the topic ID | ||
* @return the Topic for the specified topic id as an Optional instance | ||
*/ | ||
public Optional<Topic> getOptionalTopic(Integer id) { | ||
try { | ||
return (Optional.ofNullable(getTopic(id))); | ||
} catch (GitLabApiException glae) { | ||
return (GitLabApi.createOptionalFromException(glae)); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new Topic. Available only for users who can create topics. | ||
* | ||
* <pre><code>GitLab Endpoint: POST /topics</code></pre> | ||
* | ||
* @param params a TopicParams instance holding the parameters for the topic creation | ||
* @return the created Topic instance | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Topic createTopic(TopicParams params) throws GitLabApiException { | ||
Response response = post(Response.Status.CREATED, params.getForm(true), "topics"); | ||
return (response.readEntity(Topic.class)); | ||
} | ||
|
||
/** | ||
* Update a project topic. | ||
* | ||
* <pre><code>GitLab Endpoint: PUT /topics/:id</code></pre> | ||
* | ||
* @param id the topic id | ||
* @param params a TopicParams instance holding the properties to Update | ||
* @return the updated Topic instance | ||
* @throws GitLabApiException at any exception | ||
*/ | ||
public Topic updateTopic(Integer id, TopicParams params) throws GitLabApiException { | ||
Response response = putWithFormData(Response.Status.OK, | ||
params.getForm(false), "topics", id); | ||
return (response.readEntity(Topic.class)); | ||
} | ||
|
||
/** | ||
* Uploads and sets the topic's avatar for the specified topic. | ||
* | ||
* <pre><code>GitLab Endpoint: PUT /topics/:id</code></pre> | ||
* | ||
* @param id the topic in the form of an Integer | ||
* @param avatarFile the File instance of the avatar file to upload | ||
* @return the updated Topic instance | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Topic updateTopicAvatar(final Integer id, File avatarFile) throws GitLabApiException { | ||
Response response = putUpload(Response.Status.OK, "avatar", avatarFile, "topics", id); | ||
return (response.readEntity(Topic.class)); | ||
} | ||
|
||
/** | ||
* Delete the topic's avatar for the specified topic. | ||
* | ||
* <pre><code>GitLab Endpoint: PUT /topics/:id</code></pre> | ||
* | ||
* @param id the topic in the form of an Integer | ||
* @return the updated Topic instance | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Topic deleteTopicAvatar(final Integer id) throws GitLabApiException { | ||
Response response = putUpload(Response.Status.OK, "avatar", null, "topics", id); | ||
return (response.readEntity(Topic.class)); | ||
} | ||
|
||
/** | ||
* Delete a topic. You must be an administrator to delete a project topic. When you delete a project topic, you also delete the topic assignment for projects. | ||
* | ||
* <pre><code>GitLab Endpoint: DELETE /topics/:id</code></pre> | ||
* | ||
* @param id the topic to deleted in the form of an Integer | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public void deleteTopic(Integer id) throws GitLabApiException { | ||
if(isApiVersion(GitLabApi.ApiVersion.V3)){ | ||
throw new GitLabApiException("Topics need api v4+"); | ||
} | ||
delete(Response.Status.NO_CONTENT,null, "topics", id); | ||
} | ||
|
||
/** | ||
* Merge two topics together. You must be an administrator to merge a source topic into a target topic. When you merge topics, you delete the source topic and move all assigned projects to the target topic. | ||
* | ||
* <pre><code>GitLab Endpoint: POST /topics/merge</code></pre> | ||
* | ||
* @param sourceTopicId ID of source project topic | ||
* @param targetTopicId ID of target project topic | ||
* @return the merged Topic instance | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Topic mergeTopics(Integer sourceTopicId, Integer targetTopicId) throws GitLabApiException { | ||
Response response = post(Response.Status.OK,new GitLabApiForm().withParam("source_topic_id",sourceTopicId).withParam("target_topic_id",targetTopicId),"topics/merge"); | ||
return (response.readEntity(Topic.class)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.