Created
March 26, 2015 18:31
-
-
Save gdestuynder/9c4694b0fc91a96c74e8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# See also https://developer.github.com/v3/search/ | |
# First: | |
# git clone https://github.com/michaelliao/githubpy | |
import githubpy.github as github | |
import urllib | |
API_KEY="" | |
USERS=['gdestuynder', 'kangsterizer'] | |
ORGS=['mozilla-it'] | |
def parse_url(url): | |
'''Cleans up the URL to look like owner/reponame''' | |
return str.join('/', url.split('/')[3:5]).split('.git')[0] | |
def get_all_repos(g): | |
all_repos = [] | |
all_users = USERS | |
for org in ORGS: | |
for r in g.orgs(org).repos.get(): | |
all_repos += [parse_url(r['clone_url'])] | |
for r in g.orgs(org).members.get(): | |
all_users += [r['login']] | |
print("We have {} users!".format(len(all_users))) | |
for user in all_users: | |
for r in g.users(user).repos.get(): | |
all_repos += [parse_url(r['clone_url'])] | |
return all_repos | |
g = github.GitHub(access_token=API_KEY) | |
all_repos = get_all_repos(g) | |
print("Scanning {} repos...".format(len(all_repos))) | |
for repo in all_repos: | |
q = 'code?q={term}+repo:{repo}+in:file'.format(term='secret_access_key',repo=repo) | |
try: | |
res = g.search(q).get() | |
except urllib.error.HTTPError: | |
print("Could not search repo {}".format(repo)) | |
pass | |
if (res['total_count'] != 0): | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment