This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitag.py
executable file
·71 lines (54 loc) · 2.23 KB
/
gitag.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
#!/usr/bin/env python
import json
import sys
from controller import files_controller
from controller.files_controller import FilesController
from git.git_repo import GitRepo
from mapper.file_mapper import FileMapper
from report import html_reporter
from util import file_utils
def main():
try:
validate_args(sys.argv)
project_path = sys.argv[1]
branch_1 = sys.argv[2]
branch_2 = sys.argv[3]
config = sys.argv[4]
git_repo = GitRepo(project_path)
is_stashed = git_repo.stash()
current_branch = git_repo.get_current_branch()
git_repo.checkout_to_branch(branch_2)
diff = git_repo.diff_versions(branch_1, branch_2)
file_mapper = FileMapper(diff)
files = file_mapper.map_files(project_path, file_utils.get_file_content)
tags = {}
deleted_files = []
none_tagged_files = []
config = json.load(open(config))
languages = config['languages']
for language in languages:
controller = FilesController(project_path, files, language)
controller.parse(file_utils.is_file_exists, files_controller.get_tags_from_file)
files_controller.add_tags_to_existing_map(tags, controller.tags)
deleted_files += controller.deleted_files
none_tagged_files += controller.none_tagged_files
html_reporter.generate_tag_report(project_path,
files_controller.sort(tags, True),
deleted_files,
none_tagged_files,
branch_1,
branch_2)
git_repo.checkout_to_branch(current_branch)
if is_stashed:
git_repo.stash_pop()
if none_tagged_files.__len__() != 0:
for file in none_tagged_files:
print file.file_path
sys.exit('Untagged files! Build Failed')
except IndexError:
print ''
def validate_args(args):
if args.__len__() != 5:
sys.exit('You need to provide 4 arguments: [GIT_PROJECT_PATH] [branch_without_changes] [branch_with_changes] [config_file]')
if __name__ == '__main__':
main()