Skip to content

Commit

Permalink
New features (#6)
Browse files Browse the repository at this point in the history
* New features

* Updating version package.json
  • Loading branch information
danitico authored Mar 16, 2020
1 parent a2adbcf commit 4fb7016
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
18 changes: 17 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
name: 'danger-action-tnp'
author: 'The Neon Project'
description: 'A danger action to add to your CI'
inputs:
JiraTag:
jira-tag:
description: 'Your repo tag in JIRA'
required: false
default: ''

jira-url:
description: 'Your JIRA url'
required: false
default: 'https://www.example.atlassian.net/browse'

coverage:
description: 'Enable coverage. That implies having tests'
required: false
default: false

eslint:
description: 'Enable eslint errors'
required: false
default: false
runs:
using: 'node12'
main: 'dist/index.js'
Expand Down
90 changes: 88 additions & 2 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,89 @@
import { markdown } from "danger";
import { danger, fail, markdown, message } from 'danger'
import { istanbulCoverage } from 'danger-plugin-istanbul-coverage'
import jiraIssue from 'danger-plugin-jira-issue'
import * as fs from 'fs'
import * as path from 'path'

markdown(process.env['JIRA_TAG'])
const getEslintMarkdown = (eslintOutput, newFiles, modifiedFiles) => {
let eslintMarkdown = '## ESlint Issues:\n'
let warnings = false

eslintOutput.map(record => {
const file = path.parse(record.filePath).base

if (modifiedFiles.includes(file) || newFiles.includes(file)) {
if (record.messages.length > 0) {
warnings = true
eslintMarkdown = eslintMarkdown.concat(file).concat('\n')
record.messages.map(error => {
eslintMarkdown = eslintMarkdown.concat(
`* ${error.ruleId} - ${error.message} Line ${error.line} \n`
)
})
}
eslintMarkdown = eslintMarkdown.concat('\n')
}
})

if (warnings) {
return eslintMarkdown
} else {
return ''
}
}

const existsChangelog = fs.existsSync('CHANGELOG.md')

if (!existsChangelog) {
fail('Create a changelog file following the instructions of [KeepaChangelog](https://keepachangelog.com/en/1.0.0/)')
} else {
const hasChangelogModified = danger.git.modified_files.includes('CHANGELOG.md')

if (!hasChangelogModified) {
fail('Please add a changelog entry for your changes and follow the instructions of [KeepaChangelog](https://keepachangelog.com/en/1.0.0/)')
}
}


if (process.env['COVERAGE']) {
istanbulCoverage({
customSuccessMessage: 'Congrats, coverage is good',
customFailureMessage: 'Coverage is a little low, take a look',
coveragePath: 'coverage/coverage-summary.json',
reportFileSet: 'createdOrModified',
reportMode: 'warn'
})
}


if (process.env['JIRA_TAG'] !== '') {
jiraIssue({
key: process.env['JIRA_TAG'],
url: process.env['JIRA_URL'],
emoji: ':paperclip:',
location: 'title'
})
}


if (process.env['ESLINT']) {
const eslintOutput = JSON.parse(fs.readFileSync('eslint.json', 'utf8'))

if (danger.git.modified_files.length > 0 || danger.git.created_files.length > 0) {
const modifiedFiles = danger.git.modified_files.map(pathname => {
return path.parse(pathname).base
})

const newFiles = danger.git.created_files.map(pathname => {
return path.parse(pathname).base
})

const messageToSend = getEslintMarkdown(eslintOutput, newFiles, modifiedFiles)

if (messageToSend !== '') {
markdown(messageToSend)
} else {
message('There aren\'t eslint errors in your code :rocket:')
}
}
}
16 changes: 14 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,20 @@ __webpack_require__.r(__webpack_exports__);

async function run() {
try {
process.env['JIRA_TAG'] = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('JiraTag')
child_process__WEBPACK_IMPORTED_MODULE_1__.execSync("npm run danger")
process.env['JIRA_TAG'] = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('jira-tag')
process.env['JIRA_URL'] = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('jira-url')
process.env['COVERAGE'] = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('coverage')
process.env['ESLINT'] = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('eslint')

if (process.env['COVERAGE']) {
child_process__WEBPACK_IMPORTED_MODULE_1__.execSync('npm run coverage')
}

if (process.env['ESLINT']) {
child_process__WEBPACK_IMPORTED_MODULE_1__.execSync('npm run eslint')
}

child_process__WEBPACK_IMPORTED_MODULE_1__.execSync('npm run danger')

} catch (error) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(error.message);
Expand Down
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ import * as cp from 'child_process'

async function run() {
try {
process.env['JIRA_TAG'] = core.getInput('JiraTag')
cp.execSync("npm run danger")
process.env['JIRA_TAG'] = core.getInput('jira-tag')
process.env['JIRA_URL'] = core.getInput('jira-url')
process.env['COVERAGE'] = core.getInput('coverage')
process.env['ESLINT'] = core.getInput('eslint')

if (process.env['COVERAGE']) {
cp.execSync('npm run coverage')
}

if (process.env['ESLINT']) {
cp.execSync('npm run eslint')
}

cp.execSync('npm run danger')

} catch (error) {
core.setFailed(error.message);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger-action",
"version": "1.0.0",
"version": "0.1.4",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
"danger": "npx danger ci"
},
"keywords": [],
"author": "",
"author": "The Neon Project",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.2.3",
Expand Down

0 comments on commit 4fb7016

Please sign in to comment.