Integrate CodeScene in your CI/CD Pipeline
==========================================

By integrating CodeScene into your CI/CD Pipeline and/or your Pull and Merge Requests, you get the following advantages:

* Quality gates for hotspot goals.
* Quality gates for Code Health decline.
* Automated code review of new modules.
* Early warnings such a complexity trend increase or detect the absence of expected change coupling.
* Prioritize code reviews based on the risk of the commits.

**Note**: some of these checks can be accomplished locally using the :doc:`../../cli/index`.

The integration is automated for GitHub, BitBucket, BitBucket Server, GitLab, Azure DevOps, and Gerrit.

CodeScene also provides an official Jenkins plugin + a CircleCI orb + a REST API and library for integrations with any
other platform or build pipeline (custom integrations are described in :doc:`/guides/delta/automated-delta-analyses`).

To enable the pull request (PR) integration, you go to the project configuration and select your Git provider:

.. figure:: pr-integration-config.png
   :alt: Enable the automated pull request integration to use CodeScene as review input and quality gate.
   :name: pr-integration-config

   Enable the automated pull request integration to use CodeScene as review input and quality gate.

All that is required are API credentials (API Token/App Password) authorized to modify webhooks and  pull requests.
Enter the proper credentials, and press "Save Configuration". CodeScene will now act on new or modified PRs and provide
an automated review:

.. figure:: pull-request-integration.png
   :alt: CodeScene provides automated pull request reviews.
   :scale: 50 %
   :name: pull-request-integration

   CodeScene provides automated pull request reviews.

Use Cases and how to interpret the results
------------------------------------------

The use cases and configuration options are explained in :doc:`/guides/delta/automated-delta-analyses`.

Control the pull request comments
---------------------------------

By default, CodeScene will only post a PR review comment if a) a quality gate fails, or b) the change is high risk and has a
higher recommended review level. You can change this defaults inside your project's configuration, by selecting Delta Analysis in the left menu:

.. figure:: delta-analysis-config.png
   :alt: Configure how often you want CodeScene to comment on your PRs.
   :name: delta-analysis-config

   Configure how often you want CodeScene to comment on your PRs.

Note that Delta Analysis will only be performed if the CodeScene project is configured to analyse the PR target branch.
To analyse PRs with different target branches, you need to set up one CodeScene project per target branch.

.. include:: ../../../shared/integrations/pr-integration/suppressions.rst

Supported Integrations
----------------------

    .. toctree::
      :maxdepth: 1

      azure
      bitbucket
      bitbucket-server
      github
      gitlab
      gerrit

CodeScene Jenkins Plugin
~~~~~~~~~~~~~~~~~~~~~~~~

CodeScene provides an official Jenkins plugin, available via `Jenkins Update Center <https://plugins.jenkins.io/codescene>`_.

More detailed installation and configuration instructions are
available `here <https://github.com/jenkinsci/codescene-plugin/blob/master/README.md#installation>`__.

Integrate CodeScene in build pipelines using codescene-ci-cd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We provide an open source library that encapsulates the CodeScene integration. Using this library, you can easily add
PR check steps to build pipelines. See the library documentation for configuration examples and
options: `codescene-ci-cd <https://github.com/empear-analytics/codescene-ci-cd>`_.

CodeScene Orb for CircleCI Integration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CodeScene provides an official CircleCI Orb, available directly via the `CircleCI Orb Registry <https://circleci.com/orbs/registry/orb/empear/codescene-ci-cd>`_.

Connect using CodeScene's REST API
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CodeScene provides a REST API that lets you integrate the analysis results in a continuous integration pipeline and/or as robot comments in a code review tool like Gerrit.

See :doc:`/guides/delta/automated-delta-analyses`.

 .. _Pull-Requests-Statistics-Actions-and-Impact:

.. include:: ../../../shared/integrations/pr-integration/pr-check-stats.rst

