2424
2525# Version and repository configuration
2626VERSION = os .getenv ("VERSION" , "unknown" )
27- REPOSITORY_URL = os .getenv ("REPOSITORY_URL" , "https://github.com/coderamp-labs/gitingest" )
28-
29- # Minimum number of parts expected in branch-commit format (e.g., "main-abc1234")
30- MIN_BRANCH_COMMIT_PARTS = 2
31-
32- # Minimum length for a git commit hash
33- MIN_COMMIT_HASH_LENGTH = 6
34-
35- # Minimum number of parts in PR format to include commit hash (pr-number-commit)
36- MIN_PR_PARTS_WITH_COMMIT = 2
27+ APP_REPOSITORY = os .getenv ("APP_REPOSITORY" , "https://github.com/coderamp-labs/gitingest" )
28+ APP_VERSION = os .getenv ("APP_VERSION" , "unknown" )
29+ APP_VERSION_URL = os .getenv ("APP_VERSION_URL" , "https://github.com/coderamp-labs/gitingest" )
3730
3831
3932def get_version_info () -> dict [str , str ]:
@@ -45,59 +38,13 @@ def get_version_info() -> dict[str, str]:
4538 Dictionary containing 'version' and 'version_link' keys.
4639
4740 """
48- version = VERSION
49- repo_url = REPOSITORY_URL .rstrip ("/" )
50- display_version = version
51- version_link = f"{ repo_url } /tree/main" # Default fallback
52-
53- def _looks_like_commit_hash (text : str ) -> bool :
54- """Check if text looks like a git commit hash (alphanumeric, 6+ chars)."""
55- return len (text ) >= MIN_COMMIT_HASH_LENGTH and text .isalnum () and any (c .isalpha () for c in text )
56-
57- # Check if version contains dashes
58- if version != "unknown" and ("-" in version ):
59- parts = version .split ("-" )
60- if len (parts ) >= MIN_BRANCH_COMMIT_PARTS :
61- # Check if first part indicates a PR
62- if parts [0 ].lower () in ("pr" , "pull" ):
63- # Extract PR number and commit hash from the parts
64- try :
65- pr_number = int (parts [1 ])
66- display_version = f"pr-{ pr_number } "
67- # If there's a commit hash after the PR number, link to the commit in the PR
68- if len (parts ) > MIN_PR_PARTS_WITH_COMMIT :
69- commit_hash = parts [- 1 ]
70- version_link = f"{ repo_url } /pull/{ pr_number } /commits/{ commit_hash } "
71- else :
72- # No commit hash, link to the PR page
73- version_link = f"{ repo_url } /pull/{ pr_number } "
74- except (ValueError , IndexError ):
75- # If PR number is invalid, fallback to main branch
76- display_version = version
77- version_link = f"{ repo_url } /tree/main"
78- elif _looks_like_commit_hash (parts [- 1 ]):
79- # This looks like branch-commit format (e.g., "main-abc1234")
80- # Display only the branch name, link to the commit
81- branch_name = parts [0 ]
82- commit_hash = parts [- 1 ]
83- display_version = branch_name
84- version_link = f"{ repo_url } /commit/{ commit_hash } "
85- else :
86- # This looks like a tag version with dashes (e.g., "release-2.1.0")
87- display_version = version
88- version_link = f"{ repo_url } /releases/tag/{ version } "
89- else :
90- # Fallback to main branch
91- display_version = version
92- version_link = f"{ repo_url } /tree/main"
93- elif version != "unknown" :
94- # This looks like a tag version
95- display_version = version
96- version_link = f"{ repo_url } /releases/tag/{ version } "
97- else :
98- # Unknown version, link to main branch
99- display_version = "unknown"
100- version_link = f"{ repo_url } /tree/main"
41+ # Use pre-computed values from GitHub Actions
42+ display_version = APP_VERSION
43+ version_link = APP_VERSION_URL
44+
45+ # Fallback to repository root if no URL is provided
46+ if version_link == APP_REPOSITORY or not version_link :
47+ version_link = f"{ APP_REPOSITORY .rstrip ('/' )} /tree/main"
10148
10249 return {
10350 "version" : display_version ,
0 commit comments