This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
push.py
84 lines (73 loc) · 2.63 KB
/
push.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import argparse
import os.path
import subprocess
import sys
import tempfile
from typing import Tuple
def lang_pkg(lang: str, pkg: str) -> Tuple[str, ...]:
return (f'--language={lang}', f'--package-name={pkg}')
CSS = '--types=css'
JS = '--types=javascript'
PP = '--types=puppet'
PY = '--types=python'
RB = '--types=ruby'
SCSS = '--types=scss'
REPOS = (
('mirrors-autopep8', *lang_pkg('python', 'autopep8'), PY, '--args=-i'),
(
'mirrors-coffeelint',
*lang_pkg('node', 'coffeelint'), r'--files-regex=\.(js|coffee)$',
),
('mirrors-csslint', *lang_pkg('node', 'csslint'), CSS),
('mirrors-eslint', *lang_pkg('node', 'eslint'), JS),
('mirrors-fixmyjs', *lang_pkg('node', 'fixmyjs'), JS),
('mirrors-isort', *lang_pkg('python', 'isort'), PY),
('mirrors-jshint', *lang_pkg('node', 'jshint'), JS),
(
'mirrors-mypy',
*lang_pkg('python', 'mypy'), PY,
'--args=--ignore-missing-imports,--scripts-are-modules',
'--require-serial',
),
('mirrors-puppet-lint', *lang_pkg('ruby', 'puppet-lint'), PP),
('mirrors-pylint', *lang_pkg('python', 'pylint'), PY),
('mirrors-ruby-lint', *lang_pkg('ruby', 'ruby-lint'), RB),
(
'mirrors-scss-lint',
*lang_pkg('ruby', 'scss_lint'), SCSS, '--entry=scss-lint',
),
('mirrors-yapf', *lang_pkg('python', 'yapf'), PY, '--args=-i'),
)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--dry-run', action='store_true')
args = parser.parse_args()
if os.environ.get('TRAVIS_PULL_REQUEST') == 'true':
print('PR: skipping')
return 0
token = os.environ['GH_TOKEN']
os.environ['GIT_AUTHOR_NAME'] = 'pre-commit'
os.environ['GIT_AUTHOR_EMAIL'] = '[email protected]'
os.environ['GIT_COMMITTER_NAME'] = 'pre-commit'
os.environ['GIT_COMMITTER_EMAIL'] = '[email protected]'
with tempfile.TemporaryDirectory() as tmpdir:
for repo in REPOS:
repo_name, *cmd_args = repo
repodir = os.path.join(tmpdir, repo_name)
subprocess.check_call((
'git', 'clone',
f'https://{token}@github.com/pre-commit/{repo_name}', repodir,
))
subprocess.check_call((
sys.executable, '-m', 'pre_commit_mirror_maker.main',
repodir, *cmd_args,
))
if not args.dry_run:
subprocess.check_call((
'git', '-C', repodir, 'push', 'origin', 'HEAD', '--tags',
))
else:
print('Skipping push due to dry run...')
return 0
if __name__ == '__main__':
exit(main())