Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Jul 10, 2023
1 parent 39332df commit c916756
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 5 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ jobs:
- name: Configure Build
run: python3 ./configure.py --cc=clang

- name: Does this work?
run: echo ${{ github.event.after }} ${{ github.event.before }}

- name: Does this work?
run: cat ${{ github.event_path }}
- name: Get the changed file list
run: ./src/scripts/ci/gh_get_changes_in_pr.py ${{ github.event.after }} --api-token=${{ secrets.GITHUB_TOKEN }}

- name: Run Clang Tidy
run: python3 ./src/scripts/dev_tools/run_clang_tidy.py --verbose --only-changed-files --fast-checks-only
Expand Down
80 changes: 80 additions & 0 deletions src/scripts/ci/gh_get_changes_in_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3

import argparse
import gzip
import http.client
import json
import re
import sys

def main(args = None):
if args is None:
args = sys.argv

re_git_sha = re.compile('[0-9A-Fa-f]{20}')

parser = argparse.ArgumentParser()

parser.add_argument('--base-commit', default='master', metavar='BRANCH')
parser.add_argument('--api-host', default='api.github.com', metavar='HOST')
parser.add_argument('--api-token', default=None)
parser.add_argument('this_commit')

args = vars(parser.parse_args())

gh_api = args['api_host']
this_commit = args['this_commit']
base_commit = args['base_commit']

if re_git_sha.match(this_commit) is None:
print("The argument '%s' does not look like a git commit id" % (this_commit))
return 1

headers = {
"Accept": "application/vnd.github+json",
"Accept-Encoding": "gzip",
"X-GitHub-Api-Version": "2022-11-28",
"Host": gh_api,
"User-Agent": "Botan gh_get_changes_in_pr.py",
}

if args.get('api_token'):
headers['Authorization'] = 'Bearer %s' % (args['api_token'])

api_req = "/repos/randombit/botan/compare/%s...%s?per_page=0" % (base_commit, this_commit)

gh = http.client.HTTPSConnection(gh_api)
gh.request('GET', api_req, headers=headers)
resp = gh.getresponse()

if resp.status != 200:
print("GH API call returned unexpected status %d" % (resp.status))
return 1

is_gzip = False
content_encoding = resp.getheader('Content-Encoding')
if content_encoding:
if content_encoding == 'gzip':
is_gzip = True
else:
print("Unexpected Content-Encoding %s" % (content_encoding))
return 1

body = resp.read()

if is_gzip:
body = gzip.decompress(body)

j = json.loads(body)

if 'files' not in j:
return 0

for f in j['files']:
print(f['filename'])

return 0

if __name__ == '__main__':
sys.exit(main())

0 comments on commit c916756

Please sign in to comment.