mirror of
				https://github.com/awesome-selfhosted/awesome-selfhosted.git
				synced 2025-11-04 09:43:12 +00:00 
			
		
		
		
	Travis only test additions on PR
some fixes in test.js
This commit is contained in:
		@@ -8,6 +8,11 @@ before_install:
 | 
				
			|||||||
  - gem install awesome_bot
 | 
					  - gem install awesome_bot
 | 
				
			||||||
  - gem install danger
 | 
					  - gem install danger
 | 
				
			||||||
script:
 | 
					script:
 | 
				
			||||||
 | 
					  - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash git diff master.. -U0 README.md | grep -Po "(?<=^\+).*" >> temp.md && node test.js temp.md && awesome_bot temp.md --allow-redirect; fi'
 | 
				
			||||||
 | 
					  - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash node test.js temp.md && awesome_bot README.md --allow-dupe --allow-redirect --allow-ssl -w notepad.cc,www.invoiceplane.com,proxy.donttrustrobots.nl,demo.phproject.org,dev.webtrees.net; fi'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  - node test.js
 | 
					  - node test.js
 | 
				
			||||||
  - awesome_bot README.md --allow-dupe --allow-redirect --allow-ssl -w notepad.cc,www.invoiceplane.com,proxy.donttrustrobots.nl,demo.phproject.org,dev.webtrees.net
 | 
					  - awesome_bot README.md --allow-dupe --allow-redirect --allow-ssl -w notepad.cc,www.invoiceplane.com,proxy.donttrustrobots.nl,demo.phproject.org,dev.webtrees.net
 | 
				
			||||||
  - danger
 | 
					  - danger
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										213
									
								
								test.js
									
									
									
									
									
								
							
							
						
						
									
										213
									
								
								test.js
									
									
									
									
									
								
							@@ -1,105 +1,132 @@
 | 
				
			|||||||
const fs = require('fs');
 | 
					const fs = require('fs')
 | 
				
			||||||
var testStatus;
 | 
					var log = '{\n'
 | 
				
			||||||
var log = "{\n";
 | 
					var issuelog = '"message": "Title | Entry\\n----|----------------------\\n'
 | 
				
			||||||
var issuelog = '"message": "Line | Entry\\n----|----------------------\\n';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
var file = fs.readFileSync('README.md', 'utf8')
 | 
					var file = fs.readFileSync(process.argv[2], 'utf8')
 | 
				
			||||||
entryErrorCheck(file);
 | 
					entryErrorCheck(file)
 | 
				
			||||||
return testStatus;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function entryErrorCheck(md) {
 | 
					function entryErrorCheck (md) {
 | 
				
			||||||
    var namepatt = /\*\s\[(.*?)\]/;
 | 
					  var namepatt = /\*\s\[(.*?)\]/
 | 
				
			||||||
    var entries = split(md);
 | 
					  var entries = split(md)
 | 
				
			||||||
    var totalFail = 0;
 | 
					  var totalFail = 0
 | 
				
			||||||
    var totalPass = 0;
 | 
					  var totalPass = 0
 | 
				
			||||||
    var total = 0;
 | 
					  var total = 0
 | 
				
			||||||
    var entryArray = [];
 | 
					  var entryArray = []
 | 
				
			||||||
  for (var i = 0, len = entries.length; i < len; i++) {
 | 
					  for (var i = 0, len = entries.length; i < len; i++) {
 | 
				
			||||||
    entryArray[i] = new Object;
 | 
					    entryArray[i] = new Object;
 | 
				
			||||||
        entryArray[i].raw = entries[i];
 | 
					    entryArray[i].raw = entries[i]
 | 
				
			||||||
        //console.log(entries[i]);
 | 
					    if (entryFilter(entries[i]) === true) {
 | 
				
			||||||
        //console.log(entryArray[i].raw);
 | 
					      total += 1
 | 
				
			||||||
        //console.log(entryFilter(entries[i]));
 | 
					      entryArray[i].name = namepatt.exec(entries[i])[1]
 | 
				
			||||||
        if (entryFilter(entries[i]) === true){
 | 
					      entryArray[i].pass = findPattern(entries[i])
 | 
				
			||||||
            total += 1;
 | 
					      if (entryArray[i].pass === true) {
 | 
				
			||||||
            entryArray[i].name = namepatt.exec(entries[i])[1];
 | 
					        totalPass += 1
 | 
				
			||||||
            //console.log('name' + entryArray[i].name);
 | 
					 | 
				
			||||||
            //entryArray[i].error = "";
 | 
					 | 
				
			||||||
            entryArray[i].pass = findPattern(entries[i], i);
 | 
					 | 
				
			||||||
            if (entryArray[i].pass == true) {
 | 
					 | 
				
			||||||
                totalPass += 1;
 | 
					 | 
				
			||||||
                //console.log(i + 1 + ". Pass: " + entryArray[i].name);
 | 
					 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
                console.log("Line #" + (i + 1) + ". Fail: " + entryArray[i].name + "\\n");
 | 
					        console.log(entryArray[i].name + 'Failed.')
 | 
				
			||||||
                //console.log(entries[i]);
 | 
					        // entryArray[i].error = findError(entries[i]) //WIP
 | 
				
			||||||
                totalFail += 1;
 | 
					        totalFail += 1
 | 
				
			||||||
                issuelog += (i + 1) + " | " + entryArray[i].name;
 | 
					        issuelog += entryArray[i].name + ' | ' + entries[i] + '\\n'
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (totalFail > 0) {
 | 
					  if (totalFail > 0) {
 | 
				
			||||||
                console.log(totalFail + " Failed, " + totalPass + " Passed, of " + total);
 | 
					    console.log(totalFail + ' Failed, ' + totalPass + ' Passed, of ' + total)
 | 
				
			||||||
                log += '"error": "true",\n"title": "Found ' + totalFail + ' syntax error(s).",\n';
 | 
					    log += '"error": "true",\n"title": "Found ' + totalFail + ' syntax error(s).",\n'
 | 
				
			||||||
                fs.writeFileSync('syntaxcheck.json', log + issuelog + '"\n}');
 | 
					    fs.writeFileSync('syntaxcheck.json', log + issuelog + '"\n}')
 | 
				
			||||||
                process.exit(1);
 | 
					    process.exit(1)
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
                console.log(totalFail + " Failed, " + totalPass + " Passed, of " + total + "\n");
 | 
					    console.log(totalFail + ' Failed, ' + totalPass + ' Passed, of ' + total + '\n')
 | 
				
			||||||
                log += '"error": false,\n"title": "No errors found!"\n}';
 | 
					    log += '"error": false,\n"title": "No errors found!"\n}'
 | 
				
			||||||
                fs.writeFileSync('syntaxcheck.json', log);
 | 
					    fs.writeFileSync('syntaxcheck.json', log)
 | 
				
			||||||
                process.exit(0);      
 | 
					    process.exit(0)
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        //console.log(entries[i])
 | 
					 | 
				
			||||||
        //console.log(totalPass + "|" + totalFail);
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function entryFilter(md) {
 | 
					 | 
				
			||||||
    var linepatt = /^\s{0,4}\*\s\[.*\`/;
 | 
					 | 
				
			||||||
    return linepatt.test(md);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function split(text){
 | 
					 | 
				
			||||||
        //cutOne = text.split("<!-- BEGIN SOFTWARE LIST -->");
 | 
					 | 
				
			||||||
        //cutTwo = cutOne[1].split("<!-- END SOFTWARE LIST -->");
 | 
					 | 
				
			||||||
        //cutThree = cutTwo[0].replace(/^\#.*$|^\_.*$|^See.*$|^Some.*$|^\*.*\*$|^\s\*.*\*$|^CMS.*$|^\*\*\[.*$/mg, "");
 | 
					 | 
				
			||||||
        return text.split(/\r?\n/);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function parseMD(md) {
 | 
					 | 
				
			||||||
    return split(md).filter(entryFilter);
 | 
					 | 
				
			||||||
    //console.log(entries);
 | 
					 | 
				
			||||||
    //console.log (entries.length);
 | 
					 | 
				
			||||||
    //console.log(entries[0]);
 | 
					 | 
				
			||||||
    //console.log(entries[entries.length - 1]);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function findPattern(text, i) {
 | 
					 | 
				
			||||||
    var nodnospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no demo and no source code
 | 
					 | 
				
			||||||
    var slpatt = /\s{0,3}\*\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,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no demo
 | 
					 | 
				
			||||||
    var nospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no source code
 | 
					 | 
				
			||||||
    var pnodnospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with no demo and no source code
 | 
					 | 
				
			||||||
    var pslpatt = /\s{0,3}\*\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,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with no demo
 | 
					 | 
				
			||||||
    var pnospatt = /\s{0,3}\*\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 {
 | 
					 | 
				
			||||||
        //document.getElementById("alert").innerHTML = "Error(s) Found, check your syntax!";
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user