R4cOOn
R4cOOn

Reputation: 2555

How to display an issue title in markdown

We create release notes based on the issue number and title.
We can use #123 to get the issue referenced in the merge request description (that we then copy paste as the release notes).
However, what I'd like is to get the title of these issues as well.

Is there a markdown sequence or another way to get the title of the issues based on the issue number?

If there's a tool that parses the commits of the merge request and creates some output of issue numbers & titles that would be an acceptable solution as well.

Cheers.

Upvotes: 4

Views: 2074

Answers (2)

VonC
VonC

Reputation: 1323115

With GitLab 14.6 (December 2021), you have another (new) option:

Render the title of a referenced issue within markdown

When referencing issues, epics, or merge requests within markdown fields, there was previously no way to surface and display additional context other than the ID.

You can now append + to an issue, epic, or merge request reference to render the title.

https://about.gitlab.com/images/14_6/render_the_title_of_a_referenced_issue_within_markdown.gif -- Render the title of a referenced issue within markdown

See Documentation and Issue.

Upvotes: 6

sytech
sytech

Reputation: 40861

As I mentioned in the comments, I don't know of any existing tool or functionality for this.

Generate markdown

The closest thing for this may be to use a document generation tool like mkdocs or sphinx to generate markdown using a custom plugin. For example, a modified version of the mkdocs-gitlab-plugin could use the API to retrieve the title and render the title in the doc.

Tampermonkey

To get the effect you're looking for locally, a tampermonkey script can do this as well. However, this will only be a local effect.

// ==UserScript==
// @name         GitLab Ref changes
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  Change issue references hyperlinks from #123 to their title
// @author       Spencer Phillip Young
// @match        https://gitlab.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function gitlabRef() {
        const anchorElementList = Array.from(document.getElementsByTagName('a'));
        anchorElementList.forEach(function(elem) {
            if (elem.getAttribute('data-reference-type') == 'issue') {
                if (elem.getAttribute('title')) {
                    elem.innerHTML = elem.getAttribute('title');
                }
            }
        });
        setTimeout(() => {
            gitlabRef();
        }, 2000)
    }

    setTimeout(() => {
        gitlabRef();
    }, 1000)
})();

Before:

Before script

After: After script

Notice the link for #340125 changed to its current title: Usage quotas pagination jumps to "seats" page

Though, in principle a more intelligent monkey could probably make a tamper script that makes this change when authoring merge requests or other markdown. So, as long as you (or someone who also has such a script) authors your release notes, everyone will get the benefit of it.

Webhook to alter MR description

Last idea may be to have a webhook respond to MR create events and rewrite #123 to [issue title](link to issue) in the description.

Upvotes: 3

Related Questions