Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Nov 28, 2024
1 parent a03cb91 commit 07e3a69
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void revokePersonalAccessToken(Long tokenId) throws GitLabApiException {
throw new RuntimeException("tokenId cannot be null");
}
Response.Status expectedStatus =
(isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
(isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "personal_access_tokens", tokenId);
}
}
34 changes: 29 additions & 5 deletions src/main/java/org/gitlab4j/api/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,30 @@ public Optional<SshKey> getOptionalSshKey(Long keyId) {
* @param key the new SSH key
* @return an SshKey instance with info on the added SSH key
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #addSshKey(String, String, Date)} instead
*/
@Deprecated
public SshKey addSshKey(String title, String key) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("title", title).withParam("key", key);
return addSshKey(title, key, null);
}

/**
* Creates a new key owned by the currently authenticated user.
*
* <pre><code>GitLab Endpoint: POST /user/keys</code></pre>
*
* @param title the new SSH Key's title
* @param key the new SSH key
* @param expiresAt the expiration date of the ssh key, optional
* @return an SshKey instance with info on the added SSH key
* @throws GitLabApiException if any exception occurs
*/
public SshKey addSshKey(String title, String key, Date expiresAt) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title)
.withParam("key", key)
.withParam("expires_at", expiresAt);

Response response = post(Response.Status.CREATED, formData, "user", "keys");
return (response.readEntity(SshKey.class));
}
Expand All @@ -803,7 +824,9 @@ public SshKey addSshKey(String title, String key) throws GitLabApiException {
* @param key the new SSH key
* @return an SshKey instance with info on the added SSH key
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #addSshKey(Long, String, String, Date)} instead
*/
@Deprecated
public SshKey addSshKey(Long userId, String title, String key) throws GitLabApiException {
return addSshKey(userId, title, key, null);
}
Expand All @@ -825,10 +848,11 @@ public SshKey addSshKey(Long userId, String title, String key, Date expiresAt) t
throw new RuntimeException("userId cannot be null");
}

GitLabApiForm formData = new GitLabApiForm().withParam("title", title).withParam("key", key);
if (expiresAt != null) {
formData.withParam("expires_at", expiresAt);
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title)
.withParam("key", key)
.withParam("expires_at", expiresAt);

Response response = post(Response.Status.CREATED, formData, "users", userId, "keys");
SshKey sshKey = response.readEntity(SshKey.class);
if (sshKey != null) {
Expand Down

0 comments on commit 07e3a69

Please sign in to comment.