Gitea icon

Gitea

Interact with Gitea via API

Actions393

Overview

This node operation allows you to create or update branch protection rules for a repository in Gitea. Branch protection is a critical feature that helps enforce workflows and maintain code quality by restricting how branches can be modified. It is especially useful in collaborative development environments where multiple contributors work on the same repository.

Typical use cases include:

  • Preventing force pushes or direct pushes to important branches like main or master.
  • Requiring a minimum number of approvals before pull requests can be merged.
  • Enforcing status checks to pass before merging.
  • Whitelisting specific teams or users who are allowed to push, merge, or approve changes.
  • Blocking merges if reviews are rejected or if the branch is outdated.

For example, a team might use this node to ensure that the main branch cannot be directly pushed to, requires at least two approving reviews, and only allows merges after all CI checks have passed.

Properties

Name Meaning
Owner The owner (user or organization) of the repository.
Repo The name of the repository.
Approvals Whitelist Teams JSON array of team names allowed to approve pull requests without counting towards required approvals.
Approvals Whitelist Username JSON array of usernames allowed to approve pull requests without counting towards required approvals.
Block Admin Merge Override Boolean to block administrators from overriding branch protection rules when merging.
Block On Official Review Requests Boolean to block merges if there are official review requests pending.
Block On Outdated Branch Boolean to block merges if the branch is outdated compared to the base branch.
Block On Rejected Reviews Boolean to block merges if any reviews have been rejected.
Branch Name Deprecated string property for the branch name.
Dismiss Stale Approvals Boolean to automatically dismiss stale pull request approvals when new commits are pushed.
Enable Approvals Whitelist Boolean to enable the approvals whitelist feature.
Enable Force Push Boolean to allow force pushing to the protected branch.
Enable Force Push Allowlist Boolean to enable an allowlist for force pushing.
Enable Merge Whitelist Boolean to enable a whitelist of users/teams allowed to merge.
Enable Push Boolean to allow pushing to the protected branch.
Enable Push Whitelist Boolean to enable a whitelist of users/teams allowed to push.
Enable Status Check Boolean to require status checks to pass before merging.
Force Push Allowlist Deploy Keys Boolean to allow deploy keys to force push.
Force Push Allowlist Teams JSON array of team names allowed to force push.
Force Push Allowlist Usernames JSON array of usernames allowed to force push.
Ignore Stale Approvals Boolean to ignore stale approvals instead of dismissing them.
Merge Whitelist Teams JSON array of team names allowed to merge pull requests.
Merge Whitelist Usernames JSON array of usernames allowed to merge pull requests.
Priority Numeric priority of the branch protection rule.
Protected File Patterns String pattern(s) specifying files that are protected by this rule.
Push Whitelist Deploy Keys Boolean to allow deploy keys to push.
Push Whitelist Teams JSON array of team names allowed to push.
Push Whitelist Usernames JSON array of usernames allowed to push.
Require Signed Commits Boolean to require commits to be signed.
Required Approvals Number of required approvals before merging.
Rule Name Name of the branch protection rule.
Status Check Contexts JSON array of status check contexts that must pass before merging.
Unprotected File Patterns String pattern(s) specifying files excluded from protection.

Output

The node outputs JSON data representing the created or updated branch protection rule as returned by the Gitea API. This typically includes details such as the rule's ID, name, branch patterns, protection settings, whitelists, and enforcement flags.

No binary data output is expected from this operation.

Dependencies

  • Requires an active connection to a Gitea instance via its API.
  • Requires an API authentication token credential configured in n8n to authorize requests.
  • The node uses the Gitea REST API v1 endpoints under the /api/v1 path.

Troubleshooting

  • Authentication errors: Ensure the API token credential is valid and has sufficient permissions to modify repository settings.
  • Invalid JSON input: Properties expecting JSON arrays (e.g., whitelist teams or usernames) must be valid JSON strings; malformed JSON will cause errors.
  • Permission denied: The authenticated user must have admin or maintainer rights on the repository to set branch protections.
  • Deprecated branch_name property: Avoid using the deprecated branch_name property; use the appropriate current properties instead.
  • API rate limits: If many requests are made in a short time, the Gitea API may throttle requests; consider adding delays or retries.

Links and References

Discussion