@@ -1086,11 +1086,39 @@ private ImpersonationToken createPersonalAccessTokenOrImpersonationToken(
1086
1086
}
1087
1087
1088
1088
String tokenTypePathArg = impersonation ? "impersonation_tokens" : "personal_access_tokens" ;
1089
- Response response = post (
1090
- Response .Status .CREATED , formData , "users" , getUserIdOrUsername (userIdOrUsername ), tokenTypePathArg );
1089
+
1090
+ Response response ;
1091
+ if (userIdOrUsername != null ) {
1092
+ response = post (
1093
+ Response .Status .CREATED ,
1094
+ formData ,
1095
+ "users" ,
1096
+ getUserIdOrUsername (userIdOrUsername ),
1097
+ tokenTypePathArg );
1098
+ } else {
1099
+ response = post (Response .Status .CREATED , formData , "user" , tokenTypePathArg );
1100
+ }
1101
+
1091
1102
return (response .readEntity (ImpersonationToken .class ));
1092
1103
}
1093
1104
1105
+ /**
1106
+ * Create a personal access token for your account.
1107
+ *
1108
+ * <pre><code>GitLab Endpoint: POST /users/personal_access_tokens</code></pre>
1109
+ *
1110
+ * @param name the name of the personal access token, required
1111
+ * @param description description of personal access token, optional
1112
+ * @param expiresAt the expiration date of the personal access token, optional
1113
+ * @param scopes an array of scopes of the personal access token
1114
+ * @return the created PersonalAccessToken instance
1115
+ * @throws GitLabApiException if any exception occurs
1116
+ */
1117
+ public ImpersonationToken createSelfPersonalAccessToken (
1118
+ String name , String description , Date expiresAt , Scope [] scopes ) throws GitLabApiException {
1119
+ return createPersonalAccessTokenOrImpersonationToken (null , name , description , expiresAt , scopes , false );
1120
+ }
1121
+
1094
1122
/**
1095
1123
* Populate the REST form with data from the User instance.
1096
1124
*
0 commit comments