-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_manifest.py
More file actions
51 lines (38 loc) · 1.27 KB
/
get_manifest.py
File metadata and controls
51 lines (38 loc) · 1.27 KB
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
#!/usr/bin/env python
import os
import re
import sys
from typing import List
from slack_cli_hooks.error import CliError
from slack_cli_hooks.protocol import Protocol, build_protocol
PROTOCOL: Protocol
EXCLUDED_DIRECTORIES = [
"lib",
"bin",
"include",
"node_modules",
"packages",
"logs",
"build",
"coverage",
"target",
"tmp",
"test",
"tests",
]
DIRECTORY_IGNORE_REGEX = re.compile(r"(^\.|^\_|^{}$)".format("$|^".join(EXCLUDED_DIRECTORIES)), re.IGNORECASE)
def filter_directories(directories: List[str]) -> List[str]:
return [directory for directory in directories if not DIRECTORY_IGNORE_REGEX.match(directory)]
def find_file_path(path: str, file_name: str) -> str:
for root, dirs, files in os.walk(path, topdown=True, followlinks=False):
dirs[:] = filter_directories(dirs)
if file_name in files:
return os.path.join(root, file_name)
raise CliError(f"Could not find a {file_name} file")
def get_manifest(working_directory: str) -> str:
file_path = find_file_path(working_directory, "manifest.json")
with open(file_path, "r") as manifest:
return manifest.read()
if __name__ == "__main__":
PROTOCOL = build_protocol(argv=sys.argv)
PROTOCOL.respond(get_manifest(os.getcwd()))