@@ -994,7 +994,7 @@ public Optional<ImpersonationToken> getOptionalImpersonationToken(Object userIdO
994994 */
995995 public ImpersonationToken createImpersonationToken (
996996 Object userIdOrUsername , String name , Date expiresAt , Scope [] scopes ) throws GitLabApiException {
997- return createPersonalAccessTokenOrImpersonationToken (userIdOrUsername , name , expiresAt , scopes , true );
997+ return createPersonalAccessTokenOrImpersonationToken (userIdOrUsername , name , null , expiresAt , scopes , true );
998998 }
999999
10001000 /**
@@ -1028,10 +1028,32 @@ public void revokeImpersonationToken(Object userIdOrUsername, Long tokenId) thro
10281028 * @param scopes an array of scopes of the personal access token
10291029 * @return the created PersonalAccessToken instance
10301030 * @throws GitLabApiException if any exception occurs
1031+ * @deprecated use {@link #createPersonalAccessToken(Object, String, String, Date, Scope[])}n
10311032 */
1033+ @ Deprecated
10321034 public ImpersonationToken createPersonalAccessToken (
10331035 Object userIdOrUsername , String name , Date expiresAt , Scope [] scopes ) throws GitLabApiException {
1034- return createPersonalAccessTokenOrImpersonationToken (userIdOrUsername , name , expiresAt , scopes , false );
1036+ return createPersonalAccessTokenOrImpersonationToken (userIdOrUsername , name , null , expiresAt , scopes , false );
1037+ }
1038+
1039+ /**
1040+ * Create a personal access token. Available only for admin users.
1041+ *
1042+ * <pre><code>GitLab Endpoint: POST /users/:user_id/personal_access_tokens</code></pre>
1043+ *
1044+ * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance
1045+ * @param name the name of the personal access token, required
1046+ * @param description description of personal access token, optional
1047+ * @param expiresAt the expiration date of the personal access token, optional
1048+ * @param scopes an array of scopes of the personal access token
1049+ * @return the created PersonalAccessToken instance
1050+ * @throws GitLabApiException if any exception occurs
1051+ */
1052+ public ImpersonationToken createPersonalAccessToken (
1053+ Object userIdOrUsername , String name , String description , Date expiresAt , Scope [] scopes )
1054+ throws GitLabApiException {
1055+ return createPersonalAccessTokenOrImpersonationToken (
1056+ userIdOrUsername , name , description , expiresAt , scopes , false );
10351057 }
10361058
10371059 /**
@@ -1054,15 +1076,22 @@ public void revokePersonalAccessToken(Long tokenId) throws GitLabApiException {
10541076 // as per https://docs.gitlab.com/ee/api/README.html#impersonation-tokens, impersonation tokens are a type of
10551077 // personal access token
10561078 private ImpersonationToken createPersonalAccessTokenOrImpersonationToken (
1057- Object userIdOrUsername , String name , Date expiresAt , Scope [] scopes , boolean impersonation )
1079+ Object userIdOrUsername ,
1080+ String name ,
1081+ String description ,
1082+ Date expiresAt ,
1083+ Scope [] scopes ,
1084+ boolean impersonation )
10581085 throws GitLabApiException {
10591086
10601087 if (scopes == null || scopes .length == 0 ) {
10611088 throw new RuntimeException ("scopes cannot be null or empty" );
10621089 }
10631090
1064- GitLabApiForm formData =
1065- new GitLabApiForm ().withParam ("name" , name , true ).withParam ("expires_at" , expiresAt );
1091+ GitLabApiForm formData = new GitLabApiForm ()
1092+ .withParam ("name" , name , true )
1093+ .withParam ("description" , description )
1094+ .withParam ("expires_at" , expiresAt );
10661095
10671096 for (Scope scope : scopes ) {
10681097 formData .withParam ("scopes[]" , scope .toString ());
0 commit comments