# GitHub Enterprise Pull Request

SeaLights Pull Request Integration exposes Quality Risks to the developer as part of the Pull Request process, to be displayed and handled before the code is merged into the main branch.

{% hint style="warning" %}
Note that this feature is supported from GitHub Enterprise version v2.14 and newer.
{% endhint %}

## SeaLights GitHub App Setup <a href="#sealights-github-app-setup" id="sealights-github-app-setup"></a>

In order to benefit of the Pull Request Analysis, you will need to create a new App on your Github Enterprise instance.

* This app will be **used by the Sealights Task Runner to push the information** to your GitHub Entreprise instance.

{% hint style="info" %}
The application will **not require any access to your source code**. It only requires:

* **Read** access to **metadata**
* **Read** and **write** access to **checks**
* **Website** & **Website** **hook** must be filled in
  {% endhint %}

The creation of the application is a pretty simple and straightforward procedure in GitHub Entreprise settings:

1. Open your *GitHub Settings > Developer Settings > Github Apps > New GitHub App page*
   * You can also access this setting page using a similar link to: [https://](https://github.com/apps/sealights-pull-request-analysis)[githubenterprise.yourorg.net/settings/apps/new](http://githubenterprise.yourorg.net/settings/apps/new)
2. Specify the app ID based on the following, after the application has been created:

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FjfXP2oUeXjWUVhD2Fs1O%2Fimage-20191106-154615.png?alt=media&#x26;token=9781e40b-cb2a-4287-bdbf-0207a03fab1d" alt=""><figcaption></figcaption></figure>

3. The following Private Key is to be downloaded and placed in the same folder as the TaskRunner agent:

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FfEsPaEffGjiDe9ZC3EVs%2Fimage-20191106-154702.png?alt=media&#x26;token=0c8f8196-3b3a-4490-9c0e-b674af42e039" alt=""><figcaption></figcaption></figure>

4. Then, navigate to Install App, and choose an account to install the SeaLights app on:

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FFGGkfAlqQqvS6fi1aMkl%2Fimage-20191106-155030.png?alt=media&#x26;token=160012fb-b707-4d8a-833d-22f181f1b773" alt=""><figcaption></figcaption></figure>

5. Select “All Repositories” in the following screen

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FxcERl3hRK7Mli2WP9VXh%2Fimage-20191106-155154.png?alt=media&#x26;token=dc3f4950-15e1-4cb3-9c62-07e3d9266cce" alt=""><figcaption></figcaption></figure>

## SeaLights Task Runner App Configuration <a href="#sealights-task-runner-app-configuration" id="sealights-task-runner-app-configuration"></a>

To report the Pull Request data to SeaLights, the **Task Runner must be installed** locally on the GitHub server, or on a server with access to the GitHub Enterprise instance:

1. **Download the Task Runner** from the following link: <https://agents.sealights.co/sl_task_runner/sl_task_runner-4.0.2397.zip>
2. Prepare a **configuration file** to be used by the Task Runner in JSON format:
   * The GitHub Enterprise server properties in this configuration file should be defined within json property "`github`" as follows:

**sl-taskrunner-cfg.json example:**

{% code overflow="wrap" lineNumbers="true" %}

```
{
    "tokenFile": "config/sltoken.txt",
	"github":
        {
            "url": "https://github.internal.net:443/api/v3",
            "owner":"repo-owner",
            "repo":"reponame",
            "appId":1,
            "privateKeyFile":"config/github-private-key"
        }
}
```

{% endcode %}

* The token to be used should be an [Agent token](https://docs.sealights.io/knowledgebase/setup-and-configuration/getting-started/steps-for-successful-onboarding/generating-a-token#agent-tokens)
* The value of the URL should be the on prem Github API url
* Once the above steps have been completed, it’s time to run the task runner .jar file, specifying the configuration file created in the previous step:

{% code overflow="wrap" lineNumbers="true" %}

```
java -Dsl.config.file=config/sl-taskrunner-cfg.json -jar sl_task_runner.jar
```

{% endcode %}

{% hint style="info" %}
It is also possible to pass the same parameters as Java properties, like in the example below

{% code overflow="wrap" lineNumbers="true" %}

```
java -Dsl.tokenFile=/path/to/sltoken.txt -Dsl.github.url=http://github.internal.net:443/api/v3 -Dsl.github.appId=<app ID assigned to SL app> -Dsl.github.privateKeyFile=</path/to/private-key-file> -jar sl_task_runner.jar
```

{% endcode %}
{% endhint %}

{% hint style="info" %}
See [task-runner-agent-command-reference](https://docs.sealights.io/knowledgebase/setup-and-configuration/integrations/pull-request-integration/legacy-integration/task-runner-agent-command-reference "mention") for full list of parameters.
{% endhint %}

## Configuring the pull request job <a href="#configuring-the-pull-request-job" id="configuring-the-pull-request-job"></a>

The pull request job needs to run the SeaLights build scan and test listener for the test stages you want the analysis on. These results will be compared to the latest build you reported to SeaLights for the branch you are merging the Pull Request to.

{% hint style="warning" %}
The difference between the pull request job and standard jobs is in how the **session ID is created** **using** Pull Request **specific parameters**.
{% endhint %}

### Generating a session ID <a href="#generating-a-session-id" id="generating-a-session-id"></a>

You create the Pull Request build session ID by using the SeaLights Java Build Scanner (See: [downloading-the-java-agent](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/default-usage-cli/downloading-the-java-agent "mention") ) with the **prConfig** option:

{% code overflow="wrap" lineNumbers="true" %}

```
java -jar sl-build-scanner.jar -prConfig {-token <arg> | -tokenfile <arg>} -appname <arg> -targetBranch <arg> -latestCommit <arg> -pullRequestNumber <arg> -repoUrl <arg> [-pi <arg>] [-pe <arg>]
```

{% endcode %}

For Java applications, the packages included and excluded should be exactly the same as what was defined to SeaLights for the merged branch so that the compared results will be the same

See [prconfig-command-reference](https://docs.sealights.io/knowledgebase/setup-and-configuration/integrations/pull-request-integration/prconfig-command-reference "mention") for full parameter details in **Java agent, node agent** or via the Sealights **Jenkins plugin**.

### Pull Request parameters explanation as seen in GitHub <a href="#pull-request-parameters-explanation-as-seen-in-github.com" id="pull-request-parameters-explanation-as-seen-in-github.com"></a>

You can easily identify the relevant values to pass to the Build Scanner based on the illustration below. The screenshot is from [GitHub.com](http://github.com/), but is relevant for On Premise solutions as well.

<figure><img src="https://sealights.atlassian.net/wiki/download/thumbnails/559611905/image2019-2-18_13-33-24.png?version=1&#x26;modificationDate=1550489606712&#x26;cacheVersion=1&#x26;api=v2&#x26;height=400" alt=""><figcaption></figcaption></figure>

## Sample of Results on GitHub's Pull Request page <a href="#sample-of-results-on-githubs-pull-request-page" id="sample-of-results-on-githubs-pull-request-page"></a>

At the completion of the analysis, Sealights' App will appear as part of the "Checks" of your Pull Request. Result will appear similar to the one below:

<figure><img src="https://sealights.atlassian.net/wiki/download/thumbnails/559611905/image2019-2-18_14-10-17.png?version=1&#x26;modificationDate=1550491819706&#x26;cacheVersion=1&#x26;api=v2&#x26;height=400" alt=""><figcaption></figcaption></figure>
