Skip to content

Add approvalProjectRules to graphql endpoint

Joe Woodward requested to merge feat/graphql-branch-rules--approval-rules into master

What does this MR do and why?

#362706 (closed) -> #372362 (closed)

Adds approvalRules collection under project.branchRules to display information about the approval rule for a given branch

How to set up and validate locally

  1. Find a project.full_path of a project that has at least one protected branch
       rule = ApprovalProjectRule.last
       project = rule.project
       # If you don't have any protected branches this will fail to link the approval rule to the
       # protected branch and therefore will not be returned in GraphiQL.
       # Go to GDK and in the project (`"gdk.test:3000/#{project.full_path}/-/settings/repository"`)
       # create a protected branch and then link it with the code below.
       rule.protected_branches << project.protected_branches.first if rule.protected_branches.empty?
       project.full_path
  2. Or add an approval rule for a branch via UI: https://docs.gitlab.com/ee/user/project/merge_requests/approvals/rules.html#add-an-approval-rule
  3. Test permissions by assigning yourself as a guest to the project
      # user = User.find_by(email: "YOUR_EMAIL") # Use this if you do not use the default admin user in GDK
      user = User.find_by(email: "admin@example.com")
      project.add_guest(user)
  4. Visit http://gdk.test:3000/-/graphql-explorer
  5. Execute the following query, replace the full path value (as guest you should not see any rules)
{
  project(fullPath: FULL_PATH) {
    __typename
    branchRules {
      nodes {
        approvalRules {
          nodes {
            id
            name
            type
            approvalsRequired
            eligibleApprovers {
              nodes {
                name
              }
            }
          }
        }
      }
    }
  }
}
  1. Make yourself a maintainer
      project.add_maintainer(user)
  2. Execute the following query, replace the full path value (as maintainer you should see all the rules)
{
  project(fullPath: FULL_PATH) {
    __typename
    branchRules {
      nodes {
        approvalRules {
          nodes {
            id
            name
            type
            approvalsRequired
            eligibleApprovers {
              nodes {
                name
              }
            }
          }
        }
      }
    }
  }
}

"All branches" and "All protected branches"

The approval rules created for "All branches" and "All protected branches" are going to be displayed separately: #372362 (comment 1090472612)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Igor Drozdov

Merge request reports

Loading