From 3da769f6650283f864fd5dc1a27d77367d92cbd9 Mon Sep 17 00:00:00 2001 From: nrew225 Date: Sat, 10 Dec 2016 07:46:24 -0600 Subject: [PATCH 01/11] Initial Commit --- .travis.yml | 15 ++++++ Dangerfile | 36 ++++++++++++++ test.js | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 .travis.yml create mode 100644 Dangerfile create mode 100644 test.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..fde40658 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: node_js + +node_js: + - "node" + +before_install: + - rvm install 2.2 + - gem install awesome_bot + - gem install danger + +script: + - git diff master.. -U0 README.md | grep -Po "(?<=^\+).*" >> temp.md + - node test.js temp.md + - awesome_bot temp.md --allow-redirect + - danger --verbose diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 00000000..8124c31b --- /dev/null +++ b/Dangerfile @@ -0,0 +1,36 @@ +#Check for changes to README.md +has_readme_changes = git.modified_files.include?("README.md") + +# Ensure there is a summary for a pull request +fail 'Please provide a summary in the Pull Request description' if github.pr_body.length < 5 + +# Warn if PR guideline boxes are not checked. +warn 'Please check PR guidelines and check the boxes.' if github.pr_body.include? '- [ ]' + +# Warn if pull request is not updated +warn 'Please update the Pull Request title to contain the script name' if github.pr_title.include? 'Update README.md' + +# Warn when there are merge commits in the diff +warn 'Please rebase to get rid of the merge commits in this Pull Request' if git.commits.any? { |c| c.message =~ /^Merge branch 'master'/ } + +# Check links +if has_readme_changes + require 'json' + results = File.read 'ab-results-temp.md-markdown-table.json' + j = JSON.parse results + if j['error']==true + fail j['title'] + markdown j['message'] + end +end + +# Check syntax +if has_readme_changes + require 'json' + syntaxresults = File.read 'syntaxcheck.json' + sj = JSON.parse syntaxresults + if sj['error']==true + fail sj['title'] + markdown sj['message'] + end +end diff --git a/test.js b/test.js new file mode 100644 index 00000000..98d2ccd2 --- /dev/null +++ b/test.js @@ -0,0 +1,132 @@ +const fs = require('fs') +var log = '{\n' +var issuelog = ' "message": "#### Syntax Issues\\n\\n Name | Entry\\n----|----------------------\\n' + +var file = fs.readFileSync(process.argv[2], 'utf8') +entryErrorCheck(file) + +function entryErrorCheck (md) { + var namepatt = /\*\s\[(.*?)\]/ + var entries = split(md) + var totalFail = 0 + var totalPass = 0 + var total = 0 + var entryArray = [] + for (var i = 0, len = entries.length; i < len; i++) { + entryArray[i] = new Object; + entryArray[i].raw = entries[i] + if (entryFilter(entries[i]) === true) { + total += 1 + entryArray[i].name = namepatt.exec(entries[i])[1] + entryArray[i].pass = findPattern(entries[i]) + if (entryArray[i].pass === true) { + totalPass += 1 + } else { + console.log(entryArray[i].name + 'Failed.') + // entryArray[i].error = findError(entries[i]) //WIP + totalFail += 1 + issuelog += entryArray[i].name + ' | ' + entries[i] + '\\n' + } + } + } + if (totalFail > 0) { + console.log(totalFail + ' Failed, ' + totalPass + ' Passed, of ' + total) + log += ' "error": true,\n "title": "Found ' + totalFail + ' entries with syntax error(s).",\n' + fs.writeFileSync('syntaxcheck.json', log + issuelog + '"\n}') + process.exit(1) + } else { + console.log(totalFail + ' Failed, ' + totalPass + ' Passed, of ' + total + '\n') + log += ' "error": false\n}' + fs.writeFileSync('syntaxcheck.json', log) + process.exit(0) + } +}; + +function entryFilter (md) { + var linepatt = /^\s{0,4}\*\s\[.*`/ + return linepatt.test(md) +} + +function split (text) { + return text.split(/\r?\n/) +} + +// function parseMD(md) { + // return split(md).filter(entryFilter); +// } + +function findPattern (text) { + var nodnospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)`(.*?)`\s`(.*?)`/ // Regex for entries with no demo and no source code + var slpatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\b\]\((.*?)\),\s\[Source Code\b\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with demo and source code + var nodpatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with no demo + var nospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with no source code + var pnodnospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s`(⚠)`\s\-\s(.{0,249}?\.\s)`(.*?)`\s`(.*?)`/ // Regex for entries with proprietary with no demo and no source code + var pslpatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s`(⚠)`\s\-\s(.{0,249}?\.\s)\(\[Demo\b\]\((.*?)\),\s\[Source Code\b\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with proprietary with demo and source code + var pnodpatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s`(⚠)`\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with proprietary with no demo + var pnospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s`(⚠)`\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with proprietary with no source code + if (nodnospatt.test(text) === true) { + return true + } else if (slpatt.test(text) === true) { + return true + } else if (nodpatt.test(text) === true) { + return true + } else if (nospatt.test(text) === true) { + return true + } else if (pnodnospatt.test(text) === true) { + return true + } else if (pslpatt.test(text) === true) { + return true + } else if (pnodpatt.test(text) === true) { + return true + } else if (pnospatt.test(text) === true) { + return true + } else { + return false + } +}; +// WIP +function findError (entry) { + var fixedEntry = entry + if (/\s{0,4}\*\s\[.*?\]\(http.*?\)/.test(entry) === false) { // Fix * site name/URL + console.log('marker2') + entry.replace(/^(\s*)\**\s*\[*([^()\[\]]*?)\]*\s*\(*(https*:\/\/[^ )]{1,})(\)*\s*`*⚠`*\s*-*\s*|\)*\s*-*\s*)(.*)/gi, function (match, p1, p2, p3, p4, p5) { + console.log('Error in [Name](URL)') + if (/⚠/.test(entry) === true) { + fixedEntry = p1 + '* [' + p2 + '](' + p3 + ') `⚠` - ' + p5 + } else { + fixedEntry = p1 + '* [' + p2 + '](' + p3 + ') - ' + p5 + } + console.log('Fixed: ' + fixedEntry) + }) + } + if (/\s-\s/.test(entry) === false) { + console.log('marker3') + entry.replace(/(\s{0,3}\*\s\[.*?\]\(.*?\))(\s*`*⚠`*\s*-*\s*|\s*`*⚠`*\s*-*|`*⚠`*\s*-*\s*|`*⚠`*-*|\s*|\s*-*\s*|\s*-*|-*\s*|-*|\s*)(.{0,249}?\.)(.*)/gi, function (match, p1, p2, p3, p4) { // Fix space - space between link and descrition + console.log('Missing ` - ` between Site link and description.') + if (/⚠/.test(entry) === true) { + fixedEntry = p1 + ' `⚠` - ' + p3 + p4 + } else { + fixedEntry = p1 + ' - ' + p3 + p4 + } + console.log('Fixed: ' + fixedEntry) + }) + } + if (/^\s{0,4}\*\s\[.*?\]\(.*?\).*?(\s\.|\)\)\s)`.*?`\s`.*?`/.test(entry) === false) { + console.log('marker4') + entry.replace(/^(\s*\*\s.*?\)\)|.*?\s\-\s.*?\.)(\s*`*\s*)(.*?)(\s*`\s*`\s*|\s*`\s*`*\s*|\s*`*\s*`\s*|\s)(.*?)`/gi, function (match, p1, p2, p3, p4, p5) { // Fix License and Language + console.log('Issue in Language or License') + fixedEntry = p1 + ' `' + p3 + '` `' + p5 + '`' + console.log('Fixed: ' + fixedEntry) + }) + } else if (/demo/i.test(entry) === true) { + + } else if (/source/i.test(entry) === true) { + + } + console.log(findPattern(fixedEntry)) + // if (findPattern(fixedEntry) === false) { + // findError(fixedEntry) // If it's not fixed let's try again. + // } +} + +// else if (/source/i.test(entry) === true && /demo/i.test(entry) === true) { From 6a3d1074ed624e0b45c47a6e13887b0cec76ff8b Mon Sep 17 00:00:00 2001 From: nrew225 Date: Sat, 10 Dec 2016 08:00:55 -0600 Subject: [PATCH 02/11] update travis file --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fde40658..1e9345ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,11 @@ before_install: - rvm install 2.2 - gem install awesome_bot - gem install danger - -script: + +before_script: - git diff master.. -U0 README.md | grep -Po "(?<=^\+).*" >> temp.md + +script: - node test.js temp.md - awesome_bot temp.md --allow-redirect - danger --verbose From adc7d8b672e10019bfc93f59766292f177b7c5e4 Mon Sep 17 00:00:00 2001 From: nrew225 Date: Sat, 10 Dec 2016 08:04:47 -0600 Subject: [PATCH 03/11] update travis.yml --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1e9345ca..5aa60f2f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,10 @@ before_install: - gem install danger before_script: - - git diff master.. -U0 README.md | grep -Po "(?<=^\+).*" >> temp.md - + script: + allow_failures: + - git diff master.. -U0 README.md | grep -Po "(?<=^\+).*" >> temp.md - node test.js temp.md - awesome_bot temp.md --allow-redirect - danger --verbose From ab4e7355cf3b9d166d7ef9545b7d65d7d407b493 Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 10 Dec 2016 09:42:49 -0600 Subject: [PATCH 04/11] Update .travis.yml --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5aa60f2f..9fb1a550 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,7 @@ before_install: before_script: script: - allow_failures: - - git diff master.. -U0 README.md | grep -Po "(?<=^\+).*" >> temp.md + - git diff master.. -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md - node test.js temp.md - awesome_bot temp.md --allow-redirect - danger --verbose From 0df51de70901d1ef11ecdc20e3f7813429b8546b Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 10 Dec 2016 09:54:11 -0600 Subject: [PATCH 05/11] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9fb1a550..a6284c10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_install: before_script: script: - - git diff master.. -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md + - git diff master.. -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md || (exit 0) - node test.js temp.md - awesome_bot temp.md --allow-redirect - danger --verbose From d02f359fdc814c55f5a749f9398d5379623d0fe2 Mon Sep 17 00:00:00 2001 From: n8225 Date: Fri, 16 Dec 2016 18:18:34 -0600 Subject: [PATCH 06/11] allow ssl errors --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a6284c10..567fe850 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,5 +13,5 @@ before_script: script: - git diff master.. -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md || (exit 0) - node test.js temp.md - - awesome_bot temp.md --allow-redirect + - awesome_bot temp.md --allow-redirect --allow-ssl - danger --verbose From f584b1502ed30edbbd371414364a86d7b7f6c5f4 Mon Sep 17 00:00:00 2001 From: n8225 Date: Fri, 16 Dec 2016 18:32:06 -0600 Subject: [PATCH 07/11] turn off emails --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 567fe850..8876fd5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,3 +15,6 @@ script: - node test.js temp.md - awesome_bot temp.md --allow-redirect --allow-ssl - danger --verbose + +notifications: + email: false From 08ef1288a8b798141c6ea3d7de2c7b0efb57482c Mon Sep 17 00:00:00 2001 From: nrew225 Date: Fri, 16 Dec 2016 18:54:22 -0600 Subject: [PATCH 08/11] Warn on awesomebot fails --- .travis.yml | 1 - Dangerfile | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8876fd5a..2cc8d9c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ before_script: script: - git diff master.. -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md || (exit 0) - node test.js temp.md - - awesome_bot temp.md --allow-redirect --allow-ssl - danger --verbose notifications: diff --git a/Dangerfile b/Dangerfile index 8124c31b..bb8fd0e0 100644 --- a/Dangerfile +++ b/Dangerfile @@ -26,11 +26,12 @@ end # Check syntax if has_readme_changes + awesome_bot temp.md --allow-redirect --allow-ssl require 'json' syntaxresults = File.read 'syntaxcheck.json' sj = JSON.parse syntaxresults if sj['error']==true - fail sj['title'] + warn sj['title'] markdown sj['message'] end end From 6b25d7f2a55816cc68d5a7f6c137ddfa34415bd3 Mon Sep 17 00:00:00 2001 From: nrew225 Date: Fri, 16 Dec 2016 19:01:54 -0600 Subject: [PATCH 09/11] Warn on awesomebot fails --- .travis.yml | 1 + Dangerfile | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2cc8d9c2..0269051c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ before_script: script: - git diff master.. -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md || (exit 0) - node test.js temp.md + - awesome_bot temp.md --allow-redirect --allow-ssl || (exit 0) - danger --verbose notifications: diff --git a/Dangerfile b/Dangerfile index bb8fd0e0..de8e3f2a 100644 --- a/Dangerfile +++ b/Dangerfile @@ -26,7 +26,6 @@ end # Check syntax if has_readme_changes - awesome_bot temp.md --allow-redirect --allow-ssl require 'json' syntaxresults = File.read 'syntaxcheck.json' sj = JSON.parse syntaxresults From 27c69ae1fd81aa7b3ab11e1b56585ed107d44118 Mon Sep 17 00:00:00 2001 From: nrew225 Date: Fri, 16 Dec 2016 19:16:11 -0600 Subject: [PATCH 10/11] Warn on awesomebot fails --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0269051c..a6c8cbd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_script: script: - git diff master.. -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md || (exit 0) - node test.js temp.md - - awesome_bot temp.md --allow-redirect --allow-ssl || (exit 0) + - awesome_bot temp.md --allow-redirect || (exit 0) - danger --verbose notifications: From e921ece095b765198e87b02a2df1dacc18f3e649 Mon Sep 17 00:00:00 2001 From: nrew225 Date: Fri, 16 Dec 2016 19:27:29 -0600 Subject: [PATCH 11/11] warn only on awesomebot fail --- Dangerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dangerfile b/Dangerfile index de8e3f2a..86adae6c 100644 --- a/Dangerfile +++ b/Dangerfile @@ -19,7 +19,7 @@ if has_readme_changes results = File.read 'ab-results-temp.md-markdown-table.json' j = JSON.parse results if j['error']==true - fail j['title'] + warn j['title'] markdown j['message'] end end @@ -30,7 +30,7 @@ if has_readme_changes syntaxresults = File.read 'syntaxcheck.json' sj = JSON.parse syntaxresults if sj['error']==true - warn sj['title'] + fail sj['title'] markdown sj['message'] end end