GitLab API icon

GitLab API

Gitlab

Actions917

Overview

This node operation allows users to protect a specific branch in a GitLab project repository by sending a PUT request to the GitLab API endpoint `/api/v4/projects/{id}/repository/branches/{branch}/protect`. It is useful for scenarios where you want to enforce branch protection rules such as preventing force pushes or requiring approvals before merging. For example, a DevOps engineer can use this node to programmatically protect the main branch of a project to ensure code stability.

Use Case Examples

  1. Protecting the 'main' branch of a project with ID '123' to prevent unauthorized changes.
  2. Automating branch protection rules for multiple projects in a CI/CD pipeline.

Properties

Name Meaning
Skip Authentication Option to skip authentication for the request, useful for public or unauthenticated API calls.
Authentication Specifies the authentication method to use, defaulting to GitLab API key authentication.
baseUrl The base URL of the GitLab instance, defaulting to https://gitlab.com.
Method HTTP method to use for the request, default is PUT for this operation.
Path Parameters Parameters required in the URL path to identify the project and branch to protect.

Output

JSON

  • response - The JSON response from the GitLab API after protecting the branch, typically including branch protection details.

Dependencies

  • GitLab API key credential for authentication

Troubleshooting

  • Ensure the project ID and branch name are correctly specified and URL-encoded if necessary.
  • Verify that the API key has sufficient permissions to modify branch protection settings.
  • Check the base URL if using a self-hosted GitLab instance to ensure it is correct.
  • Common error messages include 404 Not Found if the project or branch does not exist, and 403 Forbidden if the API key lacks permissions.

Links

Discussion