Difference between revisions of "GitHub Pull Requests"

From Lingoport Wiki
Jump to: navigation, search
(Pull Request Analysis Configuration)
(How to Configure Pull Request Analysis)
(32 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
Files can be committed in a Git branch or directly in Master. When committing files in a branch, pull requests let you know what changes you've made to a repository before they are committed to the repository's master branch. Once a pull request is sent, interested parties can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.
 
Files can be committed in a Git branch or directly in Master. When committing files in a branch, pull requests let you know what changes you've made to a repository before they are committed to the repository's master branch. Once a pull request is sent, interested parties can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.
   
You can configure Globalyzer to scan the files that changed between the two branches of the pull request, and post a Globalyzer Analysis Summary on the pull request in Github.
+
You can configure Globalyzer to scan the files that changed between the two branches of a pull request, and post a Globalyzer Analysis Summary on the pull request in Github.
   
 
== Example of a Pull Request Analyzed with Globalyzer ==
 
== Example of a Pull Request Analyzed with Globalyzer ==
   
[[File:PrSummaryAnalysis.png]]
+
[[File:PrNewSummaryAnalysis.png]]
   
This is pull request <b>#44</b>. The change to the code in the pull request was to add multiple embedded strings and a locale-sensitive method to the files <code>ExampleMain.java</code> & <code>ExamplePanel.java</code>. This pull request is reporting 25 different issues, however since the <code>sonar-project.properties</code> attribute is set to <code>sonar.github.disableInlineComments=true</code>, the top ten issues (sorted by severity, by component, then by line) are put into a summary analysis as a pull request comment.
+
This is pull request <b>#8</b>. The change to the code in the pull request was to add a file containing one embedded string, one locale-sensitive method, one general pattern, and one static file reference to illustrate the different sections of the analysis summary. At the top of the analysis, are issue totals. Then the issues are displayed by type, with the top (up to) ten issues displayed.
   
Globalyzer analysis flagged these lines as critical issues. Clicking on the link next to the issue number will send the user to the line of code in that respective file.
+
Clicking on the file#line link will send the user to the line of code in that respective file. If an issue has associated help, as in the case for most locale-sensitive methods, the issue will appear as a link and clicking the issue will display the associated help.
   
Before merging the code back to master, the developer would typically externalize these strings, fix the locale-sensitive method issue, and re-submit the changed code / resource files for further analysis.
+
Before merging the code back to master, the developer would typically externalize embedded strings, fix locale-sensitive method issues, general pattern issues, and static file references and re-submit the changed code for further analysis.
   
  +
==How to Configure Pull Request Analysis==
 
  +
<ol>
== Pull Request Analysis Configuration ==
 
  +
<li><b>Configure github.properties</b></li>
 
1. Configure github.properties
 
   
 
You must create the file <code>/var/lib/jenkins/Lingoport_Data/Dashboard/github.properties</code> with the following contents:
 
You must create the file <code>/var/lib/jenkins/Lingoport_Data/Dashboard/github.properties</code> with the following contents:
* github.login=<your github login>
+
github.login=<your github login>
* github.oauth=<your github token>
+
github.oauth=<your github token>
  +
<b>Note:</b> To create a token for yourself on Github, navigate to https://github.com, select '''Settings''' from login dropdown, select '''Developer settings''' on left, select '''Personal access tokens''', click the '''Generate new token''' button. Also note that your access token must have the repo scope selected.
   
  +
[[File:PullRequestRepos.png|600px]]
To create a token for yourself on Github:
 
* browse to https://github.com
 
* select <b>Settings</b> from login dropdown
 
* select <b>Developer Settings</b> on left
 
* select <b>Personal access tokens</b>
 
* click <b>Generate new token</b>
 
* fill out token information
 
* click <b>Generate token</b>
 
   
===Create a Pull Request Jenkins Job for Your Github Repository===
+
<li><b>Create a Pull Request Jenkins Job</b></li>
Create a new Jenkins job named <b><YourRepo>-PullRequest</b> by copying the existing job RepoName-PullRequest.
 
   
  +
Create a new Jenkins job named <b><YourRepoName>-PullRequest</b> by copying the template '''RepoName-PullRequest''' job.<br>
You do not need to configure this job, just create it.
 
  +
Look at the configuration for your new job and verify that <b>Trigger builds remotely</b> is checked and then set the authentication token; the default is HOOK. The token is the only item you need to configure for your new job.
   
  +
<b>Note:</b> Your Jenkins user must have special permissions to configure the PullRequest job. If your job does not have the <b>Trigger builds remotely</b> option, it is likely that your Jenkins user does not have the necessary permissions. Please see [[LRM_Jenkins_Configure_System#Configure_Global_Security|here]] for information on Jenkins Global Security Configuration.
===Create Web Hook for Github Repository===
 
   
  +
<li><b>Create a Webhook for your Github Repository</b></li>
Globalyzer Dashboard uses the SonarQube sonar-project.properties file for configuration. This file should be in your repositories base directory. For the i18n analysis of the pull request, the sonar-project.properties file needs the following attributes:
 
   
  +
The Pull Request on GitHub needs to trigger a Webhook back to Lingoport's Jenkins instance. To do so:
* <code> sonar.analysis.mode=preview</code>
 
** It is imperative this attribute is set to preview to work. If not set, it defaults to publish mode, and could create future issues for analysis on this pull request.
 
* <code> sonar.github.login= </code>
 
** Your GitHub login name
 
* <code> sonar.github.oauth= </code>
 
** GitHub oauth is your unique GitHub personal access token: created @ https://github.com/settings/tokens
 
* <code> sonar.github.repository= </code>
 
** The repository you are working in. If repository link is https://github.com/ursulaLingoport/indexing2, this attribute should be set to <code> sonar.github.repository=ursulaLingoport/indexing2 </code>
 
* <code> sonar.github.pullRequest= </code>
 
** The number of the pull request you plan to run an i18n analysis on.
 
* <code> sonar.github.disableInlineComments= </code>
 
** If set to true (highly recommended), issues will not be reported as inline comments but only in the global analysis summary in sorted order. False by default.
 
** This Wiki page is based around this attribute being set to '''true'''. [https://github.com/ecrawfordLingoport/LiteDemo/pull/44 Here is an example of a Pull Request when this attribute is set to '''false''' (issues appear as individual inline comments within the pull request).]
 
 
===GitHub Personal Access Token Security===
 
Since the sonar-project.properties file includes a personal access token (OAuth), this file cannot be pushed to a remote repository. This exposes the users personal access token to the public, and therefore will void the token. If this happens, you should receive an email from GitHub acknowledging the user of the exposure and the token's decommission. In order to avoid this, the user must avoid staging the sonar-project.properties file for commit. In order to do this, you can create a <code>.gitignore</code> file in your repository's root directory to ignore all files with the <code>.properties</code> extension. It is recommended to do this in your <code>master</code> branch, so all forked and branched repositories will not face this issue.
 
 
Here is an example <code>.gitignore</code> file that will prevent this issue from occurring:
 
 
[[File:GitIgnore.png]]
 
 
=== GitHub WebHook ===
 
The Pull Request on GitHub needs to trigger a Web hook back to Lingoport's Jenkins instance. To do so:
 
 
* Navigate to the GitHub repository as an '''Admin''' account
 
* Navigate to the GitHub repository as an '''Admin''' account
* In Settings tab for the GitHub repository (available if the account has '''Admin''' permissions), add a Webhook
+
* In '''Settings''' tab for the GitHub repository (available if the account has '''Admin''' permissions), select '''Webhooks''' and the '''Add webhook''' button.
* The Web hook should follow this pattern:
+
* The Webhook should follow this pattern:
   
Payload URL: http(s)://JENKINS_URL/jenkins/buildByToken/buildWithParameters/build?job=RepoName-PullRequest&token=HOOK
+
Payload URL: http(s)://<b>JENKINS_URL</b>/jenkins/buildByToken/buildWithParameters/build?job=<b>YourRepoName</b>-PullRequest&token=<b>YourToken</b>
   
 
Content type: application/x-www-form-urlencoded
 
Content type: application/x-www-form-urlencoded
Line 83: Line 54:
 
[[File:GitHubWebhook.png|500px]]
 
[[File:GitHubWebhook.png|500px]]
   
* Test the Web hook and especially check for firewall issues going back to the Jenkins system
+
* Test the Webhook and especially check for firewall issues going back to the Jenkins system
  +
  +
</ol>

Revision as of 17:52, 4 December 2019

GitHub

GitHub is a Web-based Git repository hosting service. It offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.

Git Pull Requests

Files can be committed in a Git branch or directly in Master. When committing files in a branch, pull requests let you know what changes you've made to a repository before they are committed to the repository's master branch. Once a pull request is sent, interested parties can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.

You can configure Globalyzer to scan the files that changed between the two branches of a pull request, and post a Globalyzer Analysis Summary on the pull request in Github.

Example of a Pull Request Analyzed with Globalyzer

PrNewSummaryAnalysis.png

This is pull request #8. The change to the code in the pull request was to add a file containing one embedded string, one locale-sensitive method, one general pattern, and one static file reference to illustrate the different sections of the analysis summary. At the top of the analysis, are issue totals. Then the issues are displayed by type, with the top (up to) ten issues displayed.

Clicking on the file#line link will send the user to the line of code in that respective file. If an issue has associated help, as in the case for most locale-sensitive methods, the issue will appear as a link and clicking the issue will display the associated help.

Before merging the code back to master, the developer would typically externalize embedded strings, fix locale-sensitive method issues, general pattern issues, and static file references and re-submit the changed code for further analysis.

How to Configure Pull Request Analysis

  1. Configure github.properties
  2. You must create the file /var/lib/jenkins/Lingoport_Data/Dashboard/github.properties with the following contents:

      github.login=<your github login>
      github.oauth=<your github token>
    

    Note: To create a token for yourself on Github, navigate to https://github.com, select Settings from login dropdown, select Developer settings on left, select Personal access tokens, click the Generate new token button. Also note that your access token must have the repo scope selected.

    PullRequestRepos.png

  3. Create a Pull Request Jenkins Job
  4. Create a new Jenkins job named <YourRepoName>-PullRequest by copying the template RepoName-PullRequest job.
    Look at the configuration for your new job and verify that Trigger builds remotely is checked and then set the authentication token; the default is HOOK. The token is the only item you need to configure for your new job.

    Note: Your Jenkins user must have special permissions to configure the PullRequest job. If your job does not have the Trigger builds remotely option, it is likely that your Jenkins user does not have the necessary permissions. Please see here for information on Jenkins Global Security Configuration.

  5. Create a Webhook for your Github Repository
  6. The Pull Request on GitHub needs to trigger a Webhook back to Lingoport's Jenkins instance. To do so:

    • Navigate to the GitHub repository as an Admin account
    • In Settings tab for the GitHub repository (available if the account has Admin permissions), select Webhooks and the Add webhook button.
    • The Webhook should follow this pattern:
      Payload URL: http(s)://JENKINS_URL/jenkins/buildByToken/buildWithParameters/build?job=YourRepoName-PullRequest&token=YourToken
    
      Content type: application/x-www-form-urlencoded
    
      Pull Request event selected
    
      Active
    

    For example:

    GitHubWebhook.png

    • Test the Webhook and especially check for firewall issues going back to the Jenkins system