Skip to content

Commit

Permalink
More robust and configurable commit url creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lovec741 committed Nov 18, 2024
1 parent dcf50c7 commit c4a41ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/repos.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# specified by [reponame] with listed config values.
#

[common]
gitea_url='https://git.fykos.cz' # url for accessing gitea in a browser

[fykos37] # reponame
git_path='[email protected]:FYKOS/fykos37.git' # ssh address of git repository, string
allowed_roles=['fksdb-fykos'] # array of allowed users, array of strings
Expand Down
5 changes: 3 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@

# load repos
with open('/data/config/repos.toml', 'rb') as file:
reposConfig = tomllib.load(file)
repos_config = tomllib.load(file)

repos = {repo: Repository(repo, '/data/repos/', reposConfig[repo]) for repo in reposConfig}
common_repo_config = repos_config.pop("common")
repos = {repo: Repository(repo, '/data/repos/', {**common_repo_config, **repos_config[repo]}) for repo in repos_config}

def repo_required(f):
@wraps(f)
Expand Down
8 changes: 7 additions & 1 deletion src/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,19 @@ def _format_time_ago(time_str):
except ValueError:
return time_str # orig if parse fails

def _git_remote_ssh_to_url(self, remote: str) -> str:
parts = remote.split(':')[1].split('/')
org_name = parts[0]
repo_name = parts[1].replace('.git', '')
return f"{self.config['gitea_url'].strip('/')}/{org_name}/{repo_name}/"

def get_commit_info(self, commit_hash):
localpath = os.path.join(self.repodir, self.name)
repo = Repo(localpath)
commit = repo.commit(commit_hash)
commit_msg = commit.message.strip().split('\n')[0]
commit_author = commit.author.name
commit_url = f"https://git.fykos.cz/FYKOS/{self.name}/commit/{commit.hexsha}"
commit_url = self._git_remote_ssh_to_url(repo.remote().url) + 'commit/' + commit_hash
return commit_msg, commit_author, commit_url

def get_current_build_status(self):
Expand Down

0 comments on commit c4a41ac

Please sign in to comment.