Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Philzen opened this issue Jan 27, 2022 · 1 comment
Open

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

Philzen opened this issue Jan 27, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@Philzen
Copy link
Contributor

Philzen commented Jan 27, 2022

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 😉

@Philzen Philzen added the bug Something isn't working label Jan 27, 2022
@thordy
Copy link

thordy commented Apr 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants