-
Notifications
You must be signed in to change notification settings - Fork 486
Fixed MembershipSourceType enum, UserApi.getMemberships() and implemented KeysApi #796
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0a191c1
Fixed the MembershipSourceType enum so it actually works in stead of …
flfr-stibosystems-com ef5aad7
Fixed UserApi.getMemberships() so it returns all the memberships of a…
flfr-stibosystems-com a4dfaf4
Implemented KeysApi
flfr-stibosystems-com 8f13b76
Merge branch 'gitlab4j:master' into master
dren-dk 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.gitlab4j.api; | ||
|
|
||
| import org.gitlab4j.api.models.Key; | ||
|
|
||
| import javax.ws.rs.core.MultivaluedHashMap; | ||
| import javax.ws.rs.core.MultivaluedMap; | ||
| import javax.ws.rs.core.Response; | ||
| import java.util.Collections; | ||
|
|
||
| /** | ||
| * See: | ||
| * https://docs.gitlab.com/ee/api/keys.html#get-user-by-fingerprint-of-ssh-key | ||
| */ | ||
| public class KeysApi extends AbstractApi { | ||
| public KeysApi(GitLabApi gitLabApi) { | ||
| super(gitLabApi); | ||
| } | ||
|
|
||
| /** | ||
| * @param fingerprint The md5 hash of a ssh public key with : separating the bytes Or SHA256:$base64hash | ||
| * @return The Key which includes the user who owns the key | ||
| * @throws GitLabApiException If anything goes wrong | ||
| */ | ||
| public Key getUserBySSHKeyFingerprint(String fingerprint) throws GitLabApiException { | ||
| MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>(); | ||
| queryParams.put("fingerprint", Collections.singletonList(fingerprint)); | ||
| Response response = get(Response.Status.OK, queryParams, "keys"); | ||
| return response.readEntity(Key.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
25 changes: 16 additions & 9 deletions
25
src/main/java/org/gitlab4j/api/models/MembershipSourceType.java
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 |
|---|---|---|
| @@ -1,31 +1,38 @@ | ||
| package org.gitlab4j.api.models; | ||
|
|
||
| import org.gitlab4j.api.utils.JacksonJsonEnumHelper; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
|
|
||
| public enum MembershipSourceType { | ||
| import java.util.Locale; | ||
|
|
||
| PROJECT, | ||
| public enum MembershipSourceType { | ||
| PROJECT("Project"), | ||
|
|
||
| /** Representing a group */ | ||
| NAMESPACE; | ||
| NAMESPACE("Namespace"); | ||
|
|
||
| private static JacksonJsonEnumHelper<MembershipSourceType> enumHelper = new JacksonJsonEnumHelper<>(MembershipSourceType.class); | ||
| public final String name; | ||
|
|
||
| MembershipSourceType(String name) { | ||
dren-dk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.name = name; | ||
| } | ||
|
|
||
| @JsonCreator | ||
| public static MembershipSourceType forValue(String value) { | ||
| return enumHelper.forValue(value); | ||
| if (value == null) { | ||
| return null; | ||
| } else { | ||
| return MembershipSourceType.valueOf(value.toUpperCase(Locale.ROOT)); | ||
| } | ||
| } | ||
|
|
||
| @JsonValue | ||
| public String toValue() { | ||
| return (enumHelper.toString(this)); | ||
| return this.name; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return (enumHelper.toString(this)); | ||
| return this.name; | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/test/java/org/gitlab4j/api/models/MembershipSourceTypeTest.java
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,19 @@ | ||
| package org.gitlab4j.api.models; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| public class MembershipSourceTypeTest { | ||
|
|
||
| @Test | ||
| public void forValue() { | ||
| final MembershipSourceType namespace = MembershipSourceType.forValue(MembershipSourceType.NAMESPACE.name); | ||
| Assert.assertEquals(MembershipSourceType.NAMESPACE, namespace); | ||
| Assert.assertEquals("Namespace", namespace.name); | ||
| final MembershipSourceType project = MembershipSourceType.forValue(MembershipSourceType.PROJECT.name); | ||
| Assert.assertEquals(MembershipSourceType.PROJECT, project); | ||
| Assert.assertEquals("Project", project.name); | ||
| } | ||
| } |
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.