gnag


Source link: https://github.com/btkelly/gnag

Gnag

A Gradle plugin that helps facilitate GitHub PR checking and automatic commenting of violations for Android projects.

The name is a portmanteau of the words "Gradle" and "nag". The first "g" is silent!

Usage

Requires JDK 8

Gnag is meant to be simple to use and easy to drop in to any Android project. Shown below is the simplest Gnag setup that will report violations to GitHub. By default this config will report PMD, Findbugs, Checkstyle and Android Lint to GitHub.

buildscript {

  repositories {

jcenter()
  
}

  dependencies {

classpath 'com.btkelly:gnag:{
current version
}
'
  
}
 
}
  apply plugin: 'gnag'  gnag {

  github {

repoName 'btkelly/repo'

authToken '0000000000000'

issueNumber '1'
  
}
 
}

This is the simplest way to add automatic PR checking and commenting to your project. The options defined in the github closure can be overridden by passing command line parameters with the same name to your build. This is helpful when using in conjunction with a CI system to allow automated builds.

Tasks

You can use the gnagCheck gradle task to run Gnag locally and generate an HTML report in the build directory.

./gradlew clean gnagCheck

You can use the gnagReport task which will first run gnagCheck and then report detected violations to the GitHub issue specified. In this example the issue number and authtoken for the comment user are passed as commandline arguments.

./gradlew clean gnagReport -PissueNumber=11 -PauthToken=iu2n3iu2nfjknfjk23nfkj23nk

Customization

gnag {

  enabled true
  failOnError true
  checkstyle {

enabled true

reporterConfig project.file('config/checkstyle.xml')
  
}

  pmd {

enabled true

reporterConfig project.file('config/pmd.xml')
  
}

  findbugs {

enabled true

reporterConfig project.file('config/findbugs.xml')
  
}

  androidLint {

enabled true

severity 'Error'
  
}

  github {

rootUrl 'https://my.githubinstall.com/repos/'

repoName 'btkelly/repo'

authToken '0000000000000'

issueNumber '1'
  
}
 
}
  • enabled - easily disable Gnag in specific situations
  • failOnError - should violations cause the build to fail or just generate a report
  • checkstyle - block to customize the checkstyle reporter
    • enabled - set if checkstyle should execute
    • reporterConfig - provide a custom checkstyle config
  • pmd - block to customize the pmd reporter
    • enabled - set if pmd should execute
    • reporterConfig - provide a custom pmd config
  • findbugs - block to customize the findbugs reporter
    • enabled - set if findbugs should execute
    • reporterConfig - provide a custom findbugs config
  • androidLint - block to customize the android lint reporter
    • enabled - set if the android lint reporter should look for a lint report
    • severity - can be 'Error' or 'Warning' depending on which severity you want Gnag to check
  • github - block to customize GitHub reporting (only used during the gnagReport task
    • rootUrl - root URL to use when communicating with the GitHub API (must include trailing slash), if not provided will default to " https://api.github.com/repos/"
    • repoName - account and repo name to report violations to
    • authToken - a GitHub token for a user that has access to comment on issues to the specified repo
    • issueNumber - the issue or PR number currently being built

Example Output

Below are examples of output posted to a GitHub PR on a project using Gnag to enforce quality checks.

Inline Comments

Violations associated with a specific line in your PR will be posted as comments on that line:

Aggregated Comments

Violations that cannot be associated with a specific line in your PR will be aggregated and posted in a single top-level PR comment. This will include:

  • violations associated with entire files or projects;
  • violations detected by individual reporters with invalid file location information.

Example Travis CI Usage

Travis is a continuous integration service and is free for open source projects. Below is an example of how to configure Gnag to run on Travis.

You must set an environment variable on your Travis instance for the PR_BOT_AUTH_TOKEN used to post comments back to GitHub.

.travis.yml

language: android android:
components:
- platform-tools
- tools
- build-tools-25.0.3
- android-25 jdk:
- oraclejdk8 branches:
only:
- master script: "./travis-build.sh"

travis-build.sh

#!/bin/bash set -ev  if [ "${
TRAVIS_PULL_REQUEST
}
" = "false" ]; then  ./gradlew clean gnagCheck else  ./gradlew clean gnagReport -PauthToken="${
PR_BOT_AUTH_TOKEN
}
" -PissueNumber="${
TRAVIS_PULL_REQUEST
}
" fi

License

Copyright 2016 Bryan Kelly  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

InkPageIndicator created by Nick Butcher for Plaid and back-ported for API 16+.

This plugin helps you to easily handle variant specific settings with yaml format.

Simple progress indicator helper.

HallScheme is a lightweight simple library for creating rectangle halls.

An android custom view which allows you to have an arc style-menu on your pages.

RxJava style camera API for android, it is based on android.hardware.camera.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes