-
Notifications
You must be signed in to change notification settings - Fork 21
Add a script to upload reports to GitHub #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| import os | ||
| import shutil | ||
| import subprocess | ||
|
|
||
|
|
||
| def upload_to_github(reports_list, git_user_name, git_password): | ||
| # Clone the repository if doesn't exist | ||
| if not os.path.isdir('coverage-crawler-reports'): | ||
| subprocess.run(['git', 'clone', 'https://github.com/rhcu/coverage-crawler-reports']) | ||
| os.chdir('coverage-crawler-reports') | ||
|
|
||
| # Remove the content of repository except of README | ||
| prev_files = os.listdir(os.getcwd()) | ||
| for f in prev_files: | ||
| if os.path.isdir(f): | ||
| shutil.rmtree(f) | ||
| elif f.startswith('.') is False: | ||
| os.remove(f) | ||
| subprocess.run(['git', 'pull', 'https://github.com/rhcu/coverage-crawler-reports', 'master']) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of cloning and pulling, we can do like we do here: https://github.com/mozilla/release-services/blob/master/src/shipit_code_coverage/shipit_code_coverage/github.py#L74 and just always overwrite the contents of the repository.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So basically:
You won't even need to move the reports this way, as they are created directly in the right directory. |
||
|
|
||
| with open('index.html', 'w') as f: | ||
| f.write(""" | ||
| <html> | ||
| <head> | ||
| <title>Reports</title> | ||
| </head> | ||
| <body> | ||
| <h1>The list of available reports for websites:</h1> | ||
| <br> | ||
| """) | ||
| for website, report in reports_list.items(): | ||
| # Push the new content | ||
| shutil.move(report, os.getcwd()) | ||
| name_of_folder = report.rsplit('/', 1)[-1] | ||
| f.write('<a href="{}">{}</a>'.format(os.path.join(name_of_folder, 'report/index.html'), website)) | ||
| f.write('<br>') | ||
| f.write(""" | ||
| </body> | ||
| </html> | ||
| """) | ||
|
|
||
| # Commit the content | ||
| subprocess.run(['git', 'init']) | ||
| subprocess.run(['git', 'add', '*']) | ||
| subprocess.run(['git', 'commit', '-m', 'Coverage crawler reports upload']) | ||
| subprocess.run(['git', 'push', 'https://{}:{}@github.com/rhcu/coverage-crawler-reports'.format(git_user_name, git_password), 'master', '--force']) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from coverage_crawler import crawler | ||
| from coverage_crawler import github | ||
|
|
||
| reports = {} | ||
|
|
||
| with open('websites.txt') as f: | ||
| for website in f: | ||
| report = crawler.run(website) | ||
| reports[website] = report | ||
|
|
||
| github.upload_to_github(reports, 'GIT_ACCOUNT', 'GIT_PASSWORD') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the README too, the repository will only be accessed from https://rhcu.github.io/coverage-crawler-reports/, so the README is unneeded.