• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fedora-llvm-team / llvm-snapshots / 14795010914

02 May 2025 12:16PM UTC coverage: 58.86% (+0.02%) from 58.84%
14795010914

push

github

web-flow
Add mypy, autoflake and ruff pre-commit checks (#1331)

* Add mypy pre-commit hook

This adds mypy, autoflake, and ruff as a pre-commit check and addresses all the complaints it
has. This solved a lot of real issues plus some boilerplate.

* Add autoflake pre-commit hook

This adds autoflake as a pre-commit check and addresses all the complaints it has.

* Add ruff pre-commit hook

This adds ruff as a pre-commit check and addresses all the complaints it has. This solved a lot of real issues plus some boilerplate.

Other commits:

* Provide tests with secret
* Remove unused kwargs
* Deal with cases in which the XML attribute lookup is None
* [pre-commit] autoupdate
* Fix: [WARNING] Unexpected key(s) present on https://github.com/psf/black-pre-commit-mirror => black: force-exclude
* Annotate test fixtures
* Remove premature github label cache
* Add annotation to load-tests protocol
* Add comment about munch.Munch not being typed https://github.com/Infinidat/munch/issues/84
* Annotate subparsers parameters
* Remove unused session_headers property from GithubGraphQL

176 of 234 new or added lines in 21 files covered. (75.21%)

18 existing lines in 7 files now uncovered.

1239 of 2105 relevant lines covered (58.86%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/scripts/get-good-commit.py
1
#!/bin/env python3
2

3
import argparse
1✔
4
import logging
1✔
5

6
from github import Github
1✔
7

8

9
def get_good_commit(
1✔
10
    token: str,
11
    project: str,
12
    start_ref: str,
13
    max_tries: int,
14
    required_checks: list[str],
15
) -> str:
16
    """
17
    Takes a github project and walks up the chain of commits beginning with
18
    `start_ref`. All the checks in `required_checks` must have run for the commit to
19
    be considered the best of the `max_tries` commits.
20

21
    :param str token: to be used for github token authentication
22
    :param str project: the github project to work with
23
    :param str start_ref: the git ref to check first (can be a SHA, a branch name, or a tag name)
24
    :param int max_tries: the number of parents that the algorithm tries before giving up and returning an empty string
25
    :param list[str] required_checks: the list of checks that must exist for a commit to be classified as "good"
26
    """
27
    g = Github(login_or_token=token)
×
28
    repo = g.get_repo(project)
×
29
    next_sha = start_ref
×
30
    logging.basicConfig(level=logging.INFO)
×
31
    logging.info(
×
32
        f"""
33
Scanning for best of commit
34
Project:         {project}
35
Start ref:       {start_ref}
36
Max tries:       {max_tries}
37
Required checks: {required_checks}
38
"""
39
    )
40

NEW
41
    required_checks_set = {(check, "success") for check in required_checks}
×
42
    for i in range(0, max_tries):
×
43
        commit = repo.get_commit(sha=next_sha)
×
44
        commit_url = f"https://github.com/{project}/commit/{commit.sha}"
×
45
        next_sha = commit.parents[0].sha
×
46

47
        logging.info(
×
48
            f"{i}. Checking commit {commit_url} (Date: {commit.commit.committer.date}, Combined status: {commit.get_combined_status().state})"
49
        )
50
        # Makes sure the required checks are among the ones that have been run
51
        # on the commit.
52
        actual_checks = {
×
53
            (status.context, status.state) for status in commit.get_statuses()
54
        }
NEW
55
        if not required_checks_set.issubset(actual_checks):
×
56
            logging.warning(
×
57
                f"- Ignoring commit because of missing or failed check(s): {required_checks_set - actual_checks}"
58
            )
59
            continue
×
60

61
        logging.info(f"Found good commit: {commit_url}")
×
NEW
62
        return str(commit.sha)
×
63

64
    sha = repo.get_commit(sha=start_ref).sha
×
65
    logging.info(f"No good commit found, using the initial one: {start_ref}, aka {sha}")
×
NEW
66
    return str(sha)
×
67

68

69
def main() -> None:
1✔
70
    parser = argparse.ArgumentParser(
×
71
        description="Find the latest commit that passed tests or return the start-ref commit sha"
72
    )
73
    parser.add_argument(
×
74
        "--token",
75
        dest="token",
76
        type=str,
77
        default="YOUR-TOKEN-HERE",
78
        help="your github token",
79
    )
80
    parser.add_argument(
×
81
        "--project",
82
        dest="project",
83
        type=str,
84
        default="llvm/llvm-project",
85
        help="github project to use (default: llvm/llvm-project)",
86
    )
87
    parser.add_argument(
×
88
        "--start-ref",
89
        dest="start_ref",
90
        type=str,
91
        default="main",
92
        help="git reference (e.g. branch name or sha1) to check first (default: main)",
93
    )
94
    parser.add_argument(
×
95
        "--max-tries",
96
        dest="max_tries",
97
        type=int,
98
        default="20",
99
        help="how many commit to try before giving up (default: 20)",
100
    )
101
    parser.add_argument(
×
102
        "--required-checks",
103
        dest="required_checks",
104
        metavar="CHECK",
105
        nargs="+",
106
        default=["clang-x86_64-debian-fast"],
107
        type=str,
108
        help="list check names that must have run (default: clang-x86_64-debian-fast)",
109
    )
110
    args = parser.parse_args()
×
111

112
    sha = get_good_commit(
×
113
        token=args.token,
114
        project=args.project,
115
        start_ref=args.start_ref,
116
        required_checks=args.required_checks,
117
        max_tries=args.max_tries,
118
    )
119

120
    print(sha)
×
121

122

123
if __name__ == "__main__":
1✔
124
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc