### Get Installed System Hooks (Java) Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This snippet fetches a list of all system hooks currently installed on the GitLab instance. System hooks are used for executing actions when certain events occur across the entire GitLab server. The result is a List of SystemHook objects. ```java List hooks = gitLabApi.getSystemHooksApi().getSystemHooks(); ``` -------------------------------- ### Get GitLab Server Application Settings with gitlab4j-api Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This example shows how to retrieve the current application settings for the GitLab server using the ApplicationSettingsApi. This operation does not require any specific input parameters. The result is an ApplicationSettings object. ```java ApplicationSettings appSettings = gitLabApi.getApplicationSettingsApi().getAppliationSettings(); ``` -------------------------------- ### Get Deploy Keys for Authenticated User with gitlab4j-api Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This example demonstrates fetching a list of DeployKeys associated with the currently authenticated user using the DeployKeysApi. No input parameters are required. The result is a list of DeployKey objects. ```java // Get a list of DeployKeys for the authenticated user List deployKeys = gitLabApi.getDeployKeysApi().getDeployKeys(); ``` -------------------------------- ### Get Environments for a Project with gitlab4j-api Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This example shows how to fetch a list of Environments belonging to a specific project using the EnvironmentsApi. The projectId is a required input. The output is a list of Environment objects. ```java // Get a list of Environments for the specified project List environments = gitLabApi.getEnvironmentsApi().getEnvironments(projectId); ``` -------------------------------- ### License Templates API Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Get a list of available open-source license templates. ```APIDOC ## GET /api/v4/templates/licenses ### Description Get a list of open-source license templates. ### Method GET ### Endpoint /api/v4/templates/licenses ### Parameters No parameters required. ### Request Example (No request body needed for GET request) ### Response #### Success Response (200) - **license_templates** (array) - List of LicenseTemplate objects. #### Response Example ```json [ { "key": "mit", "name": "MIT License" } ] ``` ``` -------------------------------- ### Get Project Tags (Java) Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This code example retrieves a list of all tags associated with a specific project, identified by its project ID. Tags are commonly used for version control and marking release points. The output is a List of Tag objects. ```java List tags = gitLabApi.getTagsApi().getTags(projectId); ``` -------------------------------- ### Get User Information (Java) Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This example demonstrates how to fetch the details of a specific user by their user ID. It returns a User object containing information like name, username, and email. Requires the user ID as input. ```java User user = gitLabApi.getUserApi().getUser(1); ``` -------------------------------- ### GitLab Repository File Management Examples Source: https://context7.com/gitlab4j/gitlab4j-api/llms.txt This snippet demonstrates how to manage files within a GitLab repository using the RepositoryFileApi. It includes operations for retrieving file content, checking file existence, creating, updating, and deleting files. This requires the gitlab4j-api library and a connection to a GitLab instance. ```java import org.gitlab4j.api.RepositoryFileApi; import org.gitlab4j.api.models.RepositoryFile; import java.util.Optional; RepositoryFileApi fileApi = gitLabApi.getRepositoryFileApi(); // Get a file from repository RepositoryFile file = fileApi.getFile(1234L, "path/to/file.txt", "main"); System.out.println("Content: " + file.getDecodedContentAsString()); System.out.println("Size: " + file.getSize()); System.out.println("Last commit: " + file.getLastCommitId()); // Get file with Optional Optional optionalFile = fileApi.getOptionalFile(1234L, "config.yml", "main"); if (optionalFile.isPresent()) { RepositoryFile config = optionalFile.get(); System.out.println(config.getDecodedContentAsString()); } // Get raw file content String rawContent = fileApi.getRawFile(1234L, "main", "README.md"); System.out.println(rawContent); // Check if file exists boolean exists = fileApi.existsFile(1234L, "path/to/file.txt", "main"); // Create a new file RepositoryFile newFile = new RepositoryFile(); newFile.setFilePath("path/to/newfile.txt"); newFile.setContent("Initial content"); RepositoryFile created = fileApi.createFile( 1234L, newFile, "main", "Add new file" ); // Update an existing file file.setContent("Updated content"); RepositoryFile updated = fileApi.updateFile( 1234L, file, "main", "Update file content" ); // Delete a file fileApi.deleteFile(1234L, "path/to/oldfile.txt", "main", "Remove old file"); ``` -------------------------------- ### Login to GitLab Server (Java) Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This example shows how to log in to a GitLab server using provided credentials and retrieve session information. It requires the user's username, email, and password. This is a foundational step for many authenticated API operations. ```java gitLabApi.getSessionApi().login("your-username", "your-email", "your-password"); ``` -------------------------------- ### Get License Templates Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves a list of open-source license templates available in GitLab. This method does not require any parameters. ```java // Get a list of open sourcse license templates List licenses = gitLabApi.getLicenseTemplatesApi().getLicenseTemplates(); ``` -------------------------------- ### GitLab Commits API Examples Source: https://context7.com/gitlab4j/gitlab4j-api/llms.txt This snippet shows how to interact with GitLab commits using the CommitsApi. It covers fetching commits by branch or date range, retrieving a specific commit, viewing commit diffs, creating new commits with file changes, cherry-picking, and reverting commits. It requires the gitlab4j-api library and a GitLab instance connection. ```java import org.gitlab4j.api.CommitsApi; import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.CommitAction; import org.gitlab4j.api.models.CommitPayload; import org.gitlab4j.api.models.CommitAction.Action; import java.util.Arrays; import java.util.Date; CommitsApi commitsApi = gitLabApi.getCommitsApi(); // Get commits for a branch List commits = commitsApi.getCommits(1234L, "main"); // Get commits within a time range Date since = ISO8601.toDate("2024-01-01T00:00:00Z"); Date until = new Date(); List recentCommits = commitsApi.getCommits(1234L, "main", since, until); // Get a specific commit Commit commit = commitsApi.getCommit(1234L, "abc123def"); System.out.println("Author: " + commit.getAuthorName()); System.out.println("Message: " + commit.getMessage()); System.out.println("Stats: +" + commit.getStats().getAdditions() + " -" + commit.getStats().getDeletions()); // Get commit diff List diffs = commitsApi.getDiff(1234L, "abc123def"); diffs.forEach(diff -> { System.out.println("File: " + diff.getNewPath()); System.out.println(diff.getDiff()); }); // Create a commit with file changes CommitAction createFile = new CommitAction() .withAction(Action.CREATE) .withFilePath("path/to/newfile.txt") .withContent("File content here"); CommitAction updateFile = new CommitAction() .withAction(Action.UPDATE) .withFilePath("path/to/existing.txt") .withContent("Updated content"); CommitPayload payload = new CommitPayload() .withBranch("main") .withCommitMessage("Add and update files") .withActions(Arrays.asList(createFile, updateFile)); Commit newCommit = commitsApi.createCommit(1234L, payload); // Cherry-pick a commit Commit cherryPicked = commitsApi.cherryPickCommit(1234L, "abc123def", "target-branch"); // Revert a commit Commit reverted = commitsApi.revertCommit(1234L, "abc123def", "main"); ``` -------------------------------- ### Manage GitLab Projects Source: https://context7.com/gitlab4j/gitlab4j-api/llms.txt Covers operations on GitLab projects using the ProjectApi, including retrieving all projects, paginating through projects, getting a specific project by ID or path, creating a new project, updating project settings, retrieving project statistics, and deleting a project. ```java import org.gitlab4j.api.ProjectApi; import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.ProjectFilter; import org.gitlab4j.api.Pager; import org.gitlab4j.api.models.Visibility; import org.gitlab4j.api.models.ProjectFetches; import java.util.List; // Assume gitLabApi is an initialized GitLabApi instance // GitLabApi gitLabApi = new GitLabApi("https://gitlab.example.com", "your-personal-access-token"); ProjectApi projectApi = gitLabApi.getProjectApi(); // Get all accessible projects List projects = projectApi.getProjects(); // Get projects with pagination Pager pager = projectApi.getProjects(50); // 50 items per page while (pager.hasNext()) { List page = pager.next(); for (Project project : page) { System.out.println(project.getName() + ": " + project.getWebUrl()); } } // Get a specific project by ID or path Project project = projectApi.getProject("my-group/my-project"); Project projectById = projectApi.getProject(1234L); // Create a new project Project newProject = new Project() .withName("my-new-project") .withDescription("A demonstration project") .withIssuesEnabled(true) .withMergeRequestsEnabled(true) .withWikiEnabled(true) .withSnippetsEnabled(true) .withVisibility(Visibility.PRIVATE); Project created = projectApi.createProject(newProject); // Update project settings project.setDescription("Updated description"); Project updated = projectApi.updateProject(project); // Get project statistics ProjectFetches stats = projectApi.getProjectStatistics(1234L); System.out.println("Total fetches: " + stats.getFetches().getTotal()); // Delete a project projectApi.deleteProject(1234L); ``` -------------------------------- ### Get Releases for Project Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves a list of releases for a specified project. Requires a valid projectId. ```java // Get a list of releases for the specified project List releases = gitLabApi.getReleasesApi().getReleases(projectId); ``` -------------------------------- ### Get Pipelines for Project Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves all pipelines for a specified project ID. Requires a valid projectId. ```java // Get all pipelines for the specified project ID List pipelines = gitLabApi.getPipelineApi().getPipelines(1234); ``` -------------------------------- ### Get Commits within a Time Window with gitlab4j-api Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This example demonstrates retrieving a list of commits for a given project and branch within a specified time frame using the CommitsApi. It leverages ISO8601 date utilities for date handling. Dependencies include gitlab4j-api, Date, and ISO8601. ```java // Get a list of commits associated with the specified branch that fall within the specified time window // This uses the ISO8601 date utilities the in org.gitlab4j.api.utils.ISO8601 class Date since = ISO8601.toDate("2017-01-01T00:00:00Z"); Date until = new Date(); // now List commits = gitLabApi.getCommitsApi().getCommits(1234, "new-feature", since, until); ``` -------------------------------- ### Get Packages for Project Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves all packages associated with a specified project ID. Requires a valid projectId. ```java // Get all packages for the specified project ID List packages = gitLabApi.getPackagesApi().getPackages(1234); ``` -------------------------------- ### Get Accessible Projects Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves a list of projects that the authenticated user has access to. This method does not require any parameters. ```java // Get a list of accessible projects public List projects = gitLabApi.getProjectApi().getProjects(); ``` -------------------------------- ### Create New User with Reset Email (Java) Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This code creates a new user account. It allows specifying user details like email, name, and username. Crucially, it can be configured to send a password reset email to the new user, which is useful for initial account setup. The `password` parameter can be set to `null` to trigger the email. ```java User userConfig = new User() .withEmail("jdoe@example.com") .withName("Jane Doe") .withUsername("jdoe"); String password = null; boolean sendResetPasswordEmail = true; gitLabApi.getUserApi().createUser(userConfig, password, sendResetPasswordEmail); ``` -------------------------------- ### Get Container Registry Repositories with gitlab4j-api Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md This snippet shows how to retrieve a list of registry repositories for a specified project using the ContainerRegistryApi. The projectId is a required input. The output is a list of RegistryRepository objects. ```java // Get a list of the registry repositories belonging to the specified project List registryRepos = gitLabApi.ContainerRegistryApi().getRepositories(projectId); ``` -------------------------------- ### Get License Information Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves information about the current GitLab license. This method does not require any parameters. ```java // Retrieve information about the current license License license = gitLabApi.getLicenseApi().getLicense(); ``` -------------------------------- ### Get All Runners Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves a list of all available runners. This method does not require any parameters. ```java // Get All Runners. List runners = gitLabApi.getRunnersApi().getAllRunners(); ``` -------------------------------- ### Get Labels for Project Source: https://github.com/gitlab4j/gitlab4j-api/blob/main/README.md Retrieves a list of labels for a specified project ID. Requires a valid projectId. ```java // Get a list of labels for the specified project ID List