11

I know GitLab stores wiki pages in a separate Git repository. How can we create a merge request for the wiki project of my project? Is it possible?

I found a similar question about GitHub: How can I make a pull request for a wiki page on GitHub?, but nothing about GitLab.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fernando Costa
  • 669
  • 1
  • 9
  • 31
  • 1
    Note there is a 2022 workaround. See [my edited answer below](https://stackoverflow.com/a/38537453/6309). – VonC Jun 26 '22 at 18:01

2 Answers2

7

2016: Creating a MR (Merge Request) requires the name of a project, not of its wiki.

The workaround would then be similar to the one described in your linked answer

  • having a dedicated repo "project" being a fork/clone of the wiki
  • making your MR to this wiki project/fork
  • pushing from this fork back to the original wiki repo

2022: this is followed by Epic 7107, which refers to this workaround:

Accepting merge requests on wikis

It's possible to work around the limitation of Wiki permissions by creating a mirror of the git wiki backing the wikis.
This way more users can suggest changes to the wiki by submitting merge requests.

It's not as easy as editing the wiki, but at least provides a way for outside contributors to participate.

To do this, you'll need to create project access tokens in the Wiki and use the repository mirror feature to replicate the wiki into a separate project.

  1. In the Wiki project, head for the Settings: Access Tokens page and create a new token with write_repository access

  2. optionally, create a new project for the wiki, for example called wiki-replica.
    You can also use the same project as the wiki if you do not plan to host other source code specific to that project there.
    We'll call this the "wiki replica" in either case

  3. In the wiki replica, head for the Settings: Mirroring repositories section and fill in the details for the wiki HTTPS clone URL:

    • Git repository URL: the HTTPS URL of the Git repository (which you can find in the Clone repository page on the top-right of the wiki)
      Important: Make sure you add a username to the HTTPS URL, otherwise mirroring will fail.
      For example, this wiki URL:

      https://gitlab.torproject.org/tpo/tpa/team.wiki.git
      

      should actually be:

      https://wiki-replica@gitlab.torproject.org/tpo/tpa/team.wiki.git
      
    • Mirror direction: push (only "free" option, pull is non-free)

    • Authentication method: Password (default)

    • Password: the Access token you created in the first step

    • Keep divergent refs: checked (optional, should make sure sync works in some edge cases)

    • Mirror only protected branches: checked (to keep merge requests from being needlessly mirrored to the wiki)

When you click the Mirror repository button, a sync will be triggered.
Refresh the page to see status, you should see the Last successful update column updated.
When you push to the replica, the wiki should be updated.

Naturally, because of limitations of GitLab, you cannot pull changes from the wiki to the replica.
But considering only a limited set of users have access to the wiki in the first place, this shouldn't be a problem as long as everyone pushes to the replica.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • There is a Gitlab issue for that: https://gitlab.com/gitlab-org/gitlab/-/issues/15504 – geek-merlin Jan 06 '21 at 21:10
  • @geek-merlin Thank you. I will follow this issue and will update the answer if it is resolved. – VonC Jan 06 '21 at 21:11
  • @geek-merlin Note there is a 2022 workaround. See [my edited answer above](https://stackoverflow.com/a/38537453/6309). – VonC Jun 26 '22 at 18:02
0

I have a more decent approach to accomplish this.

you can utilize git subtree, submit merge request like normal files, and review your code and doc together. let's say you have a repo tree like this:

repo -> doc -> your_markdown_file.md
     -> src

use a gitlab runner to do the push job every time you merge your code and doc:

stages:          # List of stages for jobs, and their order of execution
  - build
  
build-doc:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - echo "update doc"
    - git status
    - git checkout main
    - git pull
    - git push git@example.com:test/test.wiki.git `git subtree split -P doc main`:main --force
  only:
    changes:
      - doc/**/*
hyphen
  • 369
  • 3
  • 4