aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Dangerfile39
-rwxr-xr-xtests/check-github-commit-dates.py60
-rw-r--r--tests/test.js85
3 files changed, 184 insertions, 0 deletions
diff --git a/tests/Dangerfile b/tests/Dangerfile
new file mode 100644
index 00000000..115931df
--- /dev/null
+++ b/tests/Dangerfile
@@ -0,0 +1,39 @@
+# Danger CI configuration file
+# https://danger.systems/guides/getting_started.html
+
+# 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 provide a descriptive title for the Pull Request' 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
+ warn 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/tests/check-github-commit-dates.py b/tests/check-github-commit-dates.py
new file mode 100755
index 00000000..f148bac2
--- /dev/null
+++ b/tests/check-github-commit-dates.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+
+""" A script to find github repo links and last commit dates in a markdown file
+
+Requirements:
+ - python3 github module (sudo apt install python3-github on Debian)
+ - A personal access token (https://github.com/settings/tokens)
+
+Usage:
+ - Run awesome_bot --allow-redirect -f README.md beforehand to detect any error(4xx, 5xx) that would
+ cause the script to abort
+ - Github API calls are limited to 5000 requests/hour https://developer.github.com/v3/#rate-limiting
+ - Put the token in your environment variables:
+ export GITHUB_TOKEN=18c45f8d8d556492d1d877998a5b311b368a76e4
+ - The output is unsorted, just pipe it through 'sort' or paste it in your editor and sort from there
+ - Put the script in your crontab or run it from time to time. It doesn't make sense to add this
+ script to the CI job that runs every time something is pushed.
+ - To detect no-commit related activity (repo metadata changes, wiki edits, ...), replace pushed_at
+ with updated_at
+
+"""
+
+from github import Github
+import sys
+import time
+import re
+import os
+
+__author__ = "nodiscc"
+__copyright__ = "Copyright 2019, nodiscc"
+__credits__ = ["https://github.com/kickball/awesome-selfhosted"]
+__license__ = "MIT"
+__version__ = "1.0"
+__maintainer__ = "nodiscc"
+__email__ = "nodiscc@gmail.com"
+__status__ = "Production"
+
+###############################################################################
+
+access_token = os.environ['GITHUB_TOKEN']
+
+""" find all URLs of the form https://github.com/owner/repo """
+with open('README.md', 'r') as readme:
+ data = readme.read()
+ project_urls = re.findall('https://github.com/[A-z]*/[A-z|0-9|\-|_|\.]+', data)
+
+urls = sorted(set(project_urls))
+
+""" Uncomment this to debug the list of matched URLs """
+# print(str(urls))
+# exit(0)
+
+""" login to github API """
+g = Github(access_token)
+
+""" load project metadata, output last commit date and URL """
+for url in urls:
+ project = re.sub('https://github.com/', '', url)
+ repo = g.get_repo(project)
+ print(str(repo.pushed_at) + ' https://github.com/' + project)
diff --git a/tests/test.js b/tests/test.js
new file mode 100644
index 00000000..94e7798c
--- /dev/null
+++ b/tests/test.js
@@ -0,0 +1,85 @@
+// Accepts input of any filename, ie. node test.js README.md
+
+const fs = require('fs');
+
+let log = '{\n';
+let issuelog = ' "message": "#### Syntax Issues\\n\\n Name | Entry\\n----|----------------------\\n';
+
+const file = fs.readFileSync(process.argv[2], 'utf8'); // Reads argv into var file
+
+function entryFilter(md) { // Function to find lines with entries
+ const linepatt = /^\s{0,2}-\s\[.*`/;
+ return linepatt.test(md);
+}
+
+function split(text) { // Function to split lines into array
+ return text.split(/\r?\n/);
+}
+
+function findPattern(text) { // Test entries against 8 patterns. If matches pattern returns true
+ const nodnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. `.*?` `.*?`/; // Regex for entries with no demo and no source code
+ const slpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Demo\b\]\(.*?\), \[Source Code\b\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with demo and source code
+ const nodpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Source Code\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with no demo
+ const nospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Demo\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with no source code
+ const pnodnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. `.*?` `.*?`/; // Regex for entries with proprietary with no demo and no source code
+ const pslpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Demo\b\]\(.*?\), \[Source Code\b\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with demo and source code
+ const pnodpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Source Code\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with no demo
+ const pnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Demo\]\(.*?\)\) `.*?` `.*?`/; // 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;
+ }
+ return false;
+}
+
+function entryErrorCheck(md) {
+ const namepatt = /^\s{0,2}-\s\[(.*?)\]/; // regex pattern to find name of entryArray
+ const entries = split(md); // Inserts each line into the entries array
+ let totalFail = 0;
+ let totalPass = 0;
+ let total = 0;
+ const entryArray = [];
+ for (let i = 0, len = entries.length; i < len; i += 1) { // Loop to create array of objects
+ entryArray[i] = new Object;
+ entryArray[i].raw = entries[i];
+ if (entryFilter(entries[i]) === true) { // filter out lines that don't with * [)
+ total += 1;
+ entryArray[i].name = namepatt.exec(entries[i])[1]; // Parses name of entry
+ entryArray[i].pass = findPattern(entries[i]); // Tests against known patterns
+ if (entryArray[i].pass === true) { // If entry passes increment totalPass counter
+ totalPass += 1;
+ } else {
+ console.log(`${entryArray[i].name} Failed.`); // If entry fails increment totalFail counter and append error to issuelog
+ // entryArray[i].error = findError(entries[i]) //WIP
+ totalFail += 1;
+ issuelog += `${entryArray[i].name} | ${entries[i]} \\n`;
+ }
+ }
+ }
+ if (totalFail > 0) { // Logs # passed & failed to console, and failures to syntaxcheck.json
+ 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 { // Logs # of entries passed to console and error: false to syntaxcheck.json
+ console.log(`${totalFail} Failed, ${totalPass} Passed, of ${total} \n`);
+ log += ' "error": false\n}';
+ fs.writeFileSync('syntaxcheck.json', log);
+ process.exit(0);
+ }
+}
+
+entryErrorCheck(file);