summaryrefslogtreecommitdiff
path: root/.github/workflows/run-clang-tidy.py
blob: 7efadbc07866d8514c04452532efeb94ba0644e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3

import requests
import os


def report_github_status(repo, token, sha, findings):
    url = "https://api.github.com/repos/{}/check-runs".format(repo)
    annotations = []
    for path, findings in findings.items():
        for f in findings:
            annotations.append({
                'path': path,
                'annotation_level': 'warning',
                'start_line': f.line,
                'end_line': f.line,
                'message': f.text
            })

    data = {
        'name': 'clang-tidy',
        'head_sha': sha,
        'status': 'completed',
        'conclusion': 'neutral',
        'output': {
            'title': 'clang-tidy',
            'summary': 'Found {} items'.format(len(annotations)),
            'annotations': annotations
        }
    }

    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/vnd.github.antiope-preview+json',
        'Authorization': 'Bearer {}'.format(token),
    }

    r = requests.post(url, json=data, headers=headers)
    print(r)
    print(r.text)


def main():
    findings = {
            'CMakeLists': {
                'line': 5,
                'text': 'foo'
            }
            }

    if 'GITHUB_TOKEN' in os.environ:
        repo = os.environ['GITHUB_REPOSITORY']
        sha = os.environ['GITHUB_SHA']
        token = os.environ['GITHUB_TOKEN']
        report_github_status(repo, token, sha, findings)


if __name__ == '__main__':
    main()
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback