debian-mirror-gitlab/doc/api/graphql/branch_rules.md
2023-06-09 08:11:10 +05:30

4.2 KiB

stage group info
Create Source Code To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments

List branch rules for a project (FREE)

Introduced in GitLab 15.8.

This guide demonstrates how to use GraphiQL explorer to query for branch rules in a given project.

The example query looks for a project in a GitLab instance either by its full path for example gitlab-org/gitlab-docs. In the query we request all configured branch rules for a project.

NOTE: You can run the same query directly via a HTTP endpoint, using cURL. For more information, see our guidance on getting started from the command line.

Set up the GraphiQL explorer

This procedure presents a substantive example that you can copy and paste into your own instance of the GraphiQL explorer:

  1. Copy the following code excerpt:

    query {
      project(fullPath: "gitlab-org/gitlab-docs") {
        branchRules {
          nodes {
            name
            isDefault
            isProtected
            matchingBranchesCount
            createdAt
            updatedAt
            branchProtection {
              allowForcePush
              codeOwnerApprovalRequired
              mergeAccessLevels {
                nodes {
                  accessLevel
                  accessLevelDescription
                  user {
                    name
                  }
                  group {
                    name
                  }
                }
              }
              pushAccessLevels {
                nodes {
                  accessLevel
                  accessLevelDescription
                  user {
                    name
                  }
                  group {
                    name
                  }
                }
              }
              unprotectAccessLevels {
                nodes {
                  accessLevel
                  accessLevelDescription
                  user {
                    name
                  }
                  group {
                    name
                  }
                }
              }
            }
            externalStatusChecks {
              nodes {
                id
                name
                externalUrl
              }
            }
            approvalRules {
              nodes {
                id
                name
                type
                approvalsRequired
                eligibleApprovers {
                  nodes {
                    name
                  }
                }
              }
            }
          }
        }
      }
    }
    
  2. Open the GraphiQL explorer tool.

  3. Paste the query listed above into the left window of your GraphiQL explorer tool.

  4. Select Play to get this result:

    GraphiQL explorer query for branch rules

If no branch rules are displayed, it may be because:

  • No branch rules are configured.
  • Your role doesn't have permission to view branch rules. Administrators have access to all records.

Run the query in the GDK

Instead of requesting access, it may be easier for you to run the query in the GitLab Development Kit (GDK).

  1. Sign in as the default admin, root, with the credentials from the GDK documentation.

  2. Ensure you have some branch rules configured for the flightjs/Flight project.

  3. Replace the full path in the query:

    query {
      project(fullPath: "flightjs/Flight") {
    
  4. Visit the GraphiQL explorer tool for your GDK instance.

  5. Paste the query listed above into the left window of your GraphiQL explorer tool.

  6. Select Play to view the result.

For more information on each field, see the GraphQL API Resources.