use of org.gitlab4j.api.models.User in project octane-gitlab-service by MicroFocus.
the class GitlabServices method init.
@PostConstruct
private void init() throws MalformedURLException {
// Adding webHooks
initWebHookListenerURL();
gitLabApi = gitLabApiWrapper.getGitLabApi();
try {
List<Project> projects = isCurrentUserAdmin() ? gitLabApi.getProjectApi().getProjects() : gitLabApi.getProjectApi().getMemberProjects();
User currentUser = gitLabApi.getUserApi().getCurrentUser();
if (cleanupOnly) {
log.info("start with cleanup process");
for (Project project : projects) {
if (gitLabApiWrapper.isUserHasPermissionForProject(project, currentUser)) {
deleteWebHooks(project.getId());
}
}
} else {
for (Project project : projects) {
if (gitLabApiWrapper.isUserHasPermissionForProject(project, currentUser)) {
addWebHookToProject(project.getId(), true);
}
}
}
} catch (GitLabApiException e) {
log.warn("Failed to create GitLab web hooks", e);
throw new RuntimeException(e);
}
// start cleanUp thread
executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(new TestResultsCleanUpRunnable(applicationSettings.getConfig().getTestResultsOutputFolderPath()), TestResultsCleanUpRunnable.INTERVAL, TestResultsCleanUpRunnable.INTERVAL, TimeUnit.MINUTES);
}
use of org.gitlab4j.api.models.User in project legend-sdlc by finos.
the class AbstractGitLabApiTest method prepareGitLabUser.
/**
* Create the proper users for authenticating the GitLab operations.
*/
protected static void prepareGitLabUser() throws LegendSDLCServerException {
try {
GitLabApi rootGitLabApi = GitLabApi.oauth2Login(TEST_HOST_URL, TEST_ADMIN_USERNAME, TEST_ADMIN_PASSWORD, null, null, true);
Optional<User> testUser = rootGitLabApi.getUserApi().getOptionalUser(TEST_OWNER_USERNAME);
if (!testUser.isPresent()) {
User userSettings = new User().withUsername(TEST_OWNER_USERNAME).withEmail(TEST_OWNER_USERNAME + "@testUser.org").withName("Owner User").withSkipConfirmation(true).withIsAdmin(true);
rootGitLabApi.getUserApi().createUser(userSettings, TEST_OWNER_PASSWORD, false);
LOGGER.info("Created user with name {} and username {}", userSettings.getName(), userSettings.getUsername());
}
Optional<User> testMember = rootGitLabApi.getUserApi().getOptionalUser(TEST_MEMBER_USERNAME);
if (!testMember.isPresent()) {
User userSettings = new User().withUsername(TEST_MEMBER_USERNAME).withEmail(TEST_MEMBER_PASSWORD + "@testUser.org").withName("Member User").withSkipConfirmation(true).withIsAdmin(true);
rootGitLabApi.getUserApi().createUser(userSettings, TEST_MEMBER_PASSWORD, false);
LOGGER.info("Created user with name {} and username {}", userSettings.getName(), userSettings.getUsername());
}
} catch (GitLabApiException e) {
StringBuilder builder = new StringBuilder("Error creating user for authentication; response status: ").append(e.getHttpStatus());
String eMessage = e.getMessage();
if (eMessage != null) {
builder.append("; error message: ").append(eMessage);
}
if (e.hasValidationErrors()) {
builder.append("; validation error(s): ").append(e.getValidationErrors());
}
throw new LegendSDLCServerException(builder.toString(), e);
}
}
use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.
the class UserApi method createUser.
/**
* Creates a new user. Note only administrators can create new users.
* <p>
* POST /users
* <p>
* email (required) - Email
* password (required) - Password
* username (required) - Username
* name (required) - Name
* skype (optional) - Skype ID
* linkedin (optional) - Linkedin
* twitter (optional) - Twitter account
* website_url (optional) - Website url
* projects_limit (optional) - Number of projects user can create
* extern_uid (optional) - External UID
* provider (optional) - External provider name
* bio (optional) - User's bio
* admin (optional) - User is admin - true or false (default)
* can_create_group (optional) - User can create groups - true or false
*
* @param user the User instance with the user info to create
* @param password the password for the new user
* @param projectsLimit the maximum number of project
* @return created User instance
* @throws GitLabApiException if any exception occurs
*/
public User createUser(User user, String password, Integer projectsLimit) throws GitLabApiException {
Form formData = userToForm(user, projectsLimit, password, true);
Response response = post(Response.Status.CREATED, formData, "users");
return (response.readEntity(User.class));
}
use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.
the class UserApi method getActiveUsers.
/**
* Get a list of active users using the specified page and per page settings.
* <p>
* GET /users?active=true
*
* @param page the page to get
* @param perPage the number of users per page
* @return the list of active Users in the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<User> getActiveUsers(int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("active", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {
}));
}
use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.
the class UserApi method getUser.
/**
* Lookup a user by username.
* <p>
* NOTE: This is for admin users only.
* <p>
* GET /users?username=:username
*
* @param username the username of the user to get
* @return the User instance for the specified username
* @throws GitLabApiException if any exception occurs
*/
public User getUser(String username) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("username", username, true);
Response response = get(Response.Status.OK, formData.asMap(), "users");
List<User> users = response.readEntity(new GenericType<List<User>>() {
});
return (users.isEmpty() ? null : users.get(0));
}
Aggregations