-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (65 loc) · 2.46 KB
/
Copy pathmain.py
File metadata and controls
86 lines (65 loc) · 2.46 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
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
85
86
from src.anchor.anchor import GitAnchor
from src.anchor.extractor import GitSourceType
from src.schema.git import TOOLS as GIT_TOOLS
from src.schema.code import TOOLS as CODE_TOOLS
from src.schema.issue import TOOLS as ISSUE_TOOLS
from src.schema.control import TOOLS as CONTROL_TOOLS
from src.term import Color
from src import term
import logging
import argparse
import os
def parse_arguments():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description="Git Anchor - Link issues to commits")
# Create a mutually exclusive group for repository source
repo_group = parser.add_mutually_exclusive_group(required=True)
repo_group.add_argument("--git", help="Link of the git repository", type=str)
repo_group.add_argument(
"--from-local", help="Path to local git repository", type=str
)
parser.add_argument("--issue", help="Link of the issue", type=str, required=True)
parser.add_argument("--debug", help="Enable debug mode", action="store_true")
parser.add_argument(
"--explain",
help="Show explaination through step by step description and advanced UI",
action="store_true",
)
return parser.parse_args()
def main():
args = parse_arguments()
# Configure logging based on debug flag
log_level = logging.INFO if args.debug else logging.WARNING
logging.basicConfig(
level=log_level,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
# silence httpx logging
logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
if args.debug:
logger.info("Debug mode enabled")
if args.explain:
os.environ["GIT_ANCHOR_INTERACTIVE"] = "TRUE"
logger.info("Interactive mode enabled")
if args.from_local:
ga = GitAnchor.from_urls(
args.issue, args.from_local, source_type=GitSourceType.LOCAL
)
else:
ga = GitAnchor.from_urls(args.issue, args.git, source_type=GitSourceType.REMOTE)
ga.register_tools(GIT_TOOLS)
ga.register_tools(CODE_TOOLS)
ga.register_tools(ISSUE_TOOLS)
ga.register_tools(CONTROL_TOOLS)
logger.info("Finding link between issue and code...")
(result, token_used) = ga.find_link()
if args.explain:
term.log(
Color.GREEN, f"found resolving commit: {result} with {token_used} tokens"
)
else:
print(result)
print(token_used)
if __name__ == "__main__":
main()