This project is a code review pipeline that runs on GitLab CI, incorporating a Python script to analyze changes in source code with ChatGPT API and generates a report in the artifacts.
- Docker Runner
- GitLab CI/CD
- ChatGPT API Key
The project includes the following files:
.gitlab-ci.yml
: GitLab CI/CD configuration file that defines the pipeline to run the code review script.check_code.py
: A Python script that analyzes modified files and performs various checks.
The pipeline is defined in .gitlab-ci.yml
and includes the following steps:
- Stage
code_check
:- Uses a Python 3.9 Docker image.
- Installs required packages such as
openai
andrequests
. - Gathers all modified files with relevant extensions in the current commit.
- Creates a diff of the changes and saves it to a temporary file.
- Runs the
check_code.py
script, passing in the list of modified files and the diff. - Saves the results to an XML file (
code_check_results.xml
) and retains these artifacts for one week.
The check_code.py
script is executed within the pipeline and:
- Analyzes the provided modified files and performs a series of checks.
- Returns the result to the pipeline, which determines whether the pipeline succeeds or fails.
The pipeline is configured to continue even if the check_code.py
script fails with specific error codes (2 and 3). The results are stored in an XML file and are available as artifacts.
- To properly run the script you need an OPENAI_API_KEY Key defined in the CI/CD Settings Variables. The script will use this as default
- You should at least mark the key as Protected and Masked
- Add new changes to your repository.
- Commit and push your changes to GitLab.
- The pipeline will automatically start and run the code review script.
- Check the artifacts and pipeline status to view the review results.
This project is released under the MIT License.