Last active
August 1, 2016 19:11
-
-
Save gcmurphy/eb0526b226407862a3bdb3f3ac54c4c9 to your computer and use it in GitHub Desktop.
Run gas over the top Go repositories in Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
import subprocess | |
import tempfile | |
def _top_repositories(url=None): | |
if not url: | |
url = "https://api.github.com/search/repositories?q=language:go&sort=stars&order=desc" | |
r = requests.get(url) | |
results = r.json() | |
for repo in results['items']: | |
yield repo['name'], repo['clone_url'] | |
def _clone_repository(directory, url, name): | |
with open("/dev/null", "w") as out: | |
subprocess.call(["git", "clone", url, name, "--depth=1"], | |
stdout=out, stderr=out, cwd=directory) | |
def _run_gas(gas, directory, logfile): | |
rules = ["-rule=sql", | |
"-rule=rsa", | |
"-rule=crypto", | |
"-rule=tls_good", | |
"-rule=templates" | |
] | |
cmd = [gas] | |
cmd.extend(rules) | |
cmd.append("./...") | |
with open(logfile, "w") as log: | |
subprocess.call(cmd, stdout=log, stderr=log, cwd=directory) | |
def run(): | |
gopath = os.environ['GOPATH'] | |
if not gopath: | |
print("Please set GOPATH environment variable") | |
os.exit(1) | |
gas = os.path.join(gopath, "bin", "gas") | |
if not os.path.exists(gas): | |
print("Please run 'go install' github.com/HewlettPackard/gas") | |
os.exit(1) | |
tmp = tempfile.mkdtemp(suffix="-gas", dir=".") | |
for name, url in _top_repositories(): | |
print("Cloning: {}".format(url)) | |
_clone_repository(tmp, url, name) | |
repo = os.path.join(tmp, name) | |
_run_gas(gas, repo, "{}.log".format(repo)) | |
print("Results located in: {}/*.log".format(tmp)) | |
if __name__ == "__main__": | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment