Skip to content

Add API to block projects from code suggestions

What does this MR do and why?

Adds new repositories parameter to the code completions API and a new project setting code_suggestions. If a project has code_suggestions disabled and it's repository URL is passed to the code completion API, the request is denied as this project has disabled code suggestions for it's code.

Adds ability to read and update code_suggestions on the project to update the new project settings field

Screenshots or screen recordings

POST /api/v4/code_suggestions/completions Payload (gitlab-org/public_test has code suggestions disabled)

  "current_file": {
    "file_name": "test.py",
    "content_above_cursor": "''' generate code that can find the unique values '''",
    "content_below_cursor": ""
  },
  "repositories": ["ssh://git@gdk.test:2222/gitlab-org/public_test.git"]
}

Output

{
  "message": "401 Unauthorized - Project Blocked - One or more repositories does not allow code suggestions"
}

Migration Output - !136479 (comment 1652407104)

How to set up and validate locally

  1. Disable code suggestions for a project (project.project_setting.update!(code_suggestions: false) in rails console)
  2. Alternately, you can disable code suggestions for a project's parent group (Group >> Settings >> General >> Permissions)
  3. Make a request to the code completion API with the project's repository in the repositories argument
  4. Note the 401 response mentioning Project Blocked

MR acceptance checklist

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

Related to #430919 (closed)

Edited by Allen Cook

Merge request reports

Loading