Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pr-description/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions rubocop-annotate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Annotate RuboCop GitHub Action

GitHub Action for creating annotations from RuboCop results. Forked from https://github.com/duderman/rubocop-annotate-action

## Usage

```yml
name: Rubocop

on: push

jobs:
rubocop:
name: Rubocop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.7'
- run: gem install rubocop --no-doc
- run: rubocop --format progress --format json --out rubocop.json
id: rubocop
- uses: duderman/rubocop-annotate-action@v0.1.0
with:
path: rubocop.json
defaultLevel: warning
levels:
info: notice
refactor: warning
convention: warning
if: ${{ always() }}
```
20 changes: 20 additions & 0 deletions rubocop-annotate/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: RuboCop Annotate Action
description: GitHub Action for creating annotations from RuboCop results (forked from https://github.com/duderman/rubocop-annotate-action)
author: tyok
branding:
icon: alert-triangle
color: purple
inputs:
path:
required: false
description: path to RuboCop results JSON file
default: rubocop.json
defaultLevel:
required: true
description: default annotation level
levels:
required: true
description: mapping from rubocop severity to annotation level
runs:
using: node14
main: index.js
34 changes: 34 additions & 0 deletions rubocop-annotate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const core = require("@actions/core");
const command = require("@actions/core/lib/command")
const github = require("@actions/github");
const core = require("@actions/core");
const path = require("path");
const fs = require("fs");

try {
const defaultAnnotationLevel = core.getInput("path");
const annotationLevel = core.getInput("levels");
const fullPath = path.resolve(core.getInput("path"));
const json = JSON.parse(fs.readFileSync(fullPath, "utf8"));

for (const file of json.files) {
for (const offense of file.offenses) {
const level = annotationLevel[offense.severity] || defaultAnnotationLevel;
const properties = {
file: file.path,
col: offense.location.column,
line: offense.location.line,
};
const message = `[${offense.cop_name}] ${offense.message}`;

command.issueCommand(level, properties, message);
}
}

} catch (error) {
if (error.code === "ENOENT") {
core.setFailed(`File '${fullPath}' doesn't exist`)
} else {
core.setFailed(error.message);
}
}
172 changes: 172 additions & 0 deletions rubocop-annotate/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions rubocop-annotate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "rubocop-annotate",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0"
}
}