|
21 | 21 | # THE SOFTWARE.
|
22 | 22 |
|
23 | 23 | from adabot import github_requests as github
|
| 24 | +from adabot import travis_requests as travis |
24 | 25 | import sys
|
25 | 26 |
|
26 | 27 | def list_repos():
|
27 |
| - result = github.get("/search/repositories?q=Adafruit_CircuitPython+in%3Aname") |
28 |
| - return result.json()["items"] |
| 28 | + result = github.get("/search/repositories", |
| 29 | + params={"q":"Adafruit_CircuitPython in:name", |
| 30 | + "per_page": 100}) |
| 31 | + result = result.json() |
| 32 | + if result["total_count"] > len(result["items"]): |
| 33 | + print("Implement pagination of results!!!") |
| 34 | + return result["items"] |
29 | 35 |
|
30 |
| -def validate_teams(repo): |
31 |
| - if repo["owner"]["login"] != "adafruit": |
| 36 | +def validate_repo(repo): |
| 37 | + if not (repo["owner"]["login"] == "adafruit" and |
| 38 | + repo["name"].startswith("Adafruit_CircuitPython")): |
32 | 39 | return True
|
33 |
| - result = github.get(repo["teams_url"]) |
34 |
| - ok = False |
35 |
| - for team in result.json(): |
36 |
| - ok = ok or team["name"] == "CircuitPythonLibrarians" |
37 |
| - if not ok: |
38 |
| - print(repo["full_name"], "missing CircuitPythonLibrarians team.") |
| 40 | + full_repo = github.get("/repos/" + repo["full_name"]) |
| 41 | + if not full_repo.ok: |
| 42 | + print("Unable to pull repo details") |
| 43 | + return False |
| 44 | + ok = True |
| 45 | + if repo["has_wiki"]: |
| 46 | + print("Wiki should be disabled " + repo["full_name"]) |
| 47 | + ok = False |
| 48 | + if not repo["license"]: |
| 49 | + print(repo["full_name"], "missing license.") |
| 50 | + ok = False |
| 51 | + if not repo["permissions"]["push"]: |
| 52 | + print(repo["full_name"], "likely missing CircuitPythonLibrarians team.") |
| 53 | + ok = False |
39 | 54 | return ok
|
40 | 55 |
|
41 |
| -validators = [validate_teams] |
| 56 | +def validate_travis(repo): |
| 57 | + if not (repo["owner"]["login"] == "adafruit" and |
| 58 | + repo["name"].startswith("Adafruit_CircuitPython")): |
| 59 | + return True |
| 60 | + repo_url = "/repo/" + repo["owner"]["login"] + "%2F" + repo["name"] |
| 61 | + result = travis.get(repo_url) |
| 62 | + if not result.ok: |
| 63 | + print(result, result.request.url, result.request.headers) |
| 64 | + print(result.text) |
| 65 | + print("Travis error with repo:", repo["full_name"]) |
| 66 | + return False |
| 67 | + result = result.json() |
| 68 | + if not result["active"]: |
| 69 | + activate = travis.post(repo_url + "/activate") |
| 70 | + if not activate.ok: |
| 71 | + print(activate, activate.text) |
| 72 | + print("Unable to enable Travis build for " + repo["full_name"]) |
| 73 | + return False |
| 74 | + |
| 75 | + env_variables = travis.get(repo_url + "/env_vars") |
| 76 | + if not env_variables.ok: |
| 77 | + print(env_variables, env_variables.text) |
| 78 | + print(env_variables.request.headers) |
| 79 | + print("Unable to read Travis env variables for " + repo["full_name"]) |
| 80 | + return False |
| 81 | + env_variables = env_variables.json() |
| 82 | + found_token = False |
| 83 | + for var in env_variables["env_vars"]: |
| 84 | + found_token = found_token or var["name"] == "GITHUB_TOKEN" |
| 85 | + if not found_token: |
| 86 | + print("Unable to find GITHUB_TOKEN env variable for " + repo["full_name"]) |
| 87 | + return False |
| 88 | + |
| 89 | +validators = [validate_repo, validate_travis] |
42 | 90 |
|
43 | 91 | def validate_repo(repo):
|
| 92 | + ok = True |
44 | 93 | for validator in validators:
|
45 |
| - validator(repo) |
| 94 | + ok = validator(repo) and ok |
| 95 | + return ok |
46 | 96 |
|
47 | 97 | if __name__ == "__main__":
|
48 |
| - for repo in list_repos(): |
49 |
| - validate_repo(repo) |
| 98 | + repos = list_repos() |
| 99 | + print("Found {} repos to check.".format(len(repos))) |
| 100 | + github_user = github.get("/user").json() |
| 101 | + print("Running GitHub checks as " + github_user["login"]) |
| 102 | + travis_user = travis.get("/user").json() |
| 103 | + print("Running Travis checks as " + travis_user["login"]) |
| 104 | + need_work = 0 |
| 105 | + for repo in repos: |
| 106 | + if not validate_repo(repo): |
| 107 | + need_work += 1 |
| 108 | + print() |
| 109 | + print("{} out of {} repos need work.".format(need_work, len(repos))) |
0 commit comments