@@ -994,7 +994,7 @@ public Optional<ImpersonationToken> getOptionalImpersonationToken(Object userIdO
994
994
*/
995
995
public ImpersonationToken createImpersonationToken (
996
996
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 );
998
998
}
999
999
1000
1000
/**
@@ -1028,10 +1028,32 @@ public void revokeImpersonationToken(Object userIdOrUsername, Long tokenId) thro
1028
1028
* @param scopes an array of scopes of the personal access token
1029
1029
* @return the created PersonalAccessToken instance
1030
1030
* @throws GitLabApiException if any exception occurs
1031
+ * @deprecated use {@link #createPersonalAccessToken(Object, String, String, Date, Scope[])}n
1031
1032
*/
1033
+ @ Deprecated
1032
1034
public ImpersonationToken createPersonalAccessToken (
1033
1035
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 );
1035
1057
}
1036
1058
1037
1059
/**
@@ -1054,15 +1076,22 @@ public void revokePersonalAccessToken(Long tokenId) throws GitLabApiException {
1054
1076
// as per https://docs.gitlab.com/ee/api/README.html#impersonation-tokens, impersonation tokens are a type of
1055
1077
// personal access token
1056
1078
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 )
1058
1085
throws GitLabApiException {
1059
1086
1060
1087
if (scopes == null || scopes .length == 0 ) {
1061
1088
throw new RuntimeException ("scopes cannot be null or empty" );
1062
1089
}
1063
1090
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 );
1066
1095
1067
1096
for (Scope scope : scopes ) {
1068
1097
formData .withParam ("scopes[]" , scope .toString ());
0 commit comments