Add API to block projects from code suggestions
requested to merge 430919-technical-breakdown-how-to-block-projects-from-requesting-code-suggestions into master
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
- Disable code suggestions for a project (
project.project_setting.update!(code_suggestions: false)
in rails console) - Alternately, you can disable code suggestions for a project's parent group (Group >> Settings >> General >> Permissions)
- Make a request to the code completion API with the project's repository in the
repositories
argument - Note the
401
response mentioningProject 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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #430919 (closed)
Edited by Allen Cook