Skip to content

Commit 07e3a69

Browse files
committed
Fixes
1 parent a03cb91 commit 07e3a69

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void revokePersonalAccessToken(Long tokenId) throws GitLabApiException {
106106
throw new RuntimeException("tokenId cannot be null");
107107
}
108108
Response.Status expectedStatus =
109-
(isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
109+
(isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
110110
delete(expectedStatus, null, "personal_access_tokens", tokenId);
111111
}
112112
}

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,30 @@ public Optional<SshKey> getOptionalSshKey(Long keyId) {
786786
* @param key the new SSH key
787787
* @return an SshKey instance with info on the added SSH key
788788
* @throws GitLabApiException if any exception occurs
789+
* @deprecated use {@link #addSshKey(String, String, Date)} instead
789790
*/
791+
@Deprecated
790792
public SshKey addSshKey(String title, String key) throws GitLabApiException {
791-
GitLabApiForm formData = new GitLabApiForm().withParam("title", title).withParam("key", key);
793+
return addSshKey(title, key, null);
794+
}
795+
796+
/**
797+
* Creates a new key owned by the currently authenticated user.
798+
*
799+
* <pre><code>GitLab Endpoint: POST /user/keys</code></pre>
800+
*
801+
* @param title the new SSH Key's title
802+
* @param key the new SSH key
803+
* @param expiresAt the expiration date of the ssh key, optional
804+
* @return an SshKey instance with info on the added SSH key
805+
* @throws GitLabApiException if any exception occurs
806+
*/
807+
public SshKey addSshKey(String title, String key, Date expiresAt) throws GitLabApiException {
808+
GitLabApiForm formData = new GitLabApiForm()
809+
.withParam("title", title)
810+
.withParam("key", key)
811+
.withParam("expires_at", expiresAt);
812+
792813
Response response = post(Response.Status.CREATED, formData, "user", "keys");
793814
return (response.readEntity(SshKey.class));
794815
}
@@ -803,7 +824,9 @@ public SshKey addSshKey(String title, String key) throws GitLabApiException {
803824
* @param key the new SSH key
804825
* @return an SshKey instance with info on the added SSH key
805826
* @throws GitLabApiException if any exception occurs
827+
* @deprecated use {@link #addSshKey(Long, String, String, Date)} instead
806828
*/
829+
@Deprecated
807830
public SshKey addSshKey(Long userId, String title, String key) throws GitLabApiException {
808831
return addSshKey(userId, title, key, null);
809832
}
@@ -825,10 +848,11 @@ public SshKey addSshKey(Long userId, String title, String key, Date expiresAt) t
825848
throw new RuntimeException("userId cannot be null");
826849
}
827850

828-
GitLabApiForm formData = new GitLabApiForm().withParam("title", title).withParam("key", key);
829-
if (expiresAt != null) {
830-
formData.withParam("expires_at", expiresAt);
831-
}
851+
GitLabApiForm formData = new GitLabApiForm()
852+
.withParam("title", title)
853+
.withParam("key", key)
854+
.withParam("expires_at", expiresAt);
855+
832856
Response response = post(Response.Status.CREATED, formData, "users", userId, "keys");
833857
SshKey sshKey = response.readEntity(SshKey.class);
834858
if (sshKey != null) {

0 commit comments

Comments
 (0)