thomvaill/log4brains

"View link in Gitlab" is hard-coded to master-branch

Philzen opened this issue · 1 comments

Bug Report

Description

When viewing ADRs in the log4brains web presentation (preview or live on gitlab / github pages), clicking on the "View in gitlab button" (grafik) leads to a 404 page.

This is due to the fact that my repository's default branch (such as any recent new repos on gitlab/github) is called main and there exists no master-branch.

Steps to Reproduce

  1. Initialize a repository whose default branch is not named master
  2. Set up ADR management with log4brains
  3. Start up the preview server and/or publish via gitlab / github pages
  4. Call up the knowledge base in the browser and click the aforementioned button in the right upper corner of any ADR

Expected Behavior

It should not lead to a 404 page and instead show the ADR as commited into the repository.

Environment

  • Log4brains version: 1.0.0-beta.11
  • Node.js version: v17.3.0.
  • OS and its version: Manjaro linux / whatever gitlab.com uses
  • Browser information: Firefox

Possible Solution

There is already a TODO comment in adr-transformers.ts. Making it configurable would be a nice-to-have feature addition, however it may not be needed to fix this bug for now. For instance, i do not have any repository url configured in .log4brains.yml – nevertheless log4brains correctly guesses the repository origin (pretty impressive btw 👏). I assume this magic happens somewhere in guessGitRepositoryConfig.ts.

Dirty fix

The details in guessGitRepositoryConfig.ts are currently a bit over my head, however it could simply check if a master branch exists at all, and if it doesn't, check for main. Having said that, as the whole industry is shifting towards calling the default branch main, so that should be checked first i guess.

Better fix

As far as my research and quick tests show, git remote show origin should reliably print the default HEAD branch .

Using git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 in the extracts the name straightaway, though that cryptic foo is better of done in clean coded type script 😉

I also ran into this issue, but solved it by adding the following to my .log4brains.yml configuration file

  repository:
    viewFileUriPattern: /blob/main/%path

which seems to open links in the correct branch