gitlabgitlab-apigitlab-ce

Creating a new GitLab issue and assigning a label to it automatically


I am working on designing webpage UI where some experimental data is stored. This data could be inaccurate sometimes so I'm providing a button at the bottom of the page which redirects the user to the new issue webpage in GitLab. Look at the sample below.

enter image description here

And this button will take the user to somewhere like this: enter image description here

The URL behind the button is simply

<full-path-to-some-gitlab-repo>/issues/new?issue[title]=Issue%20with%20experiment%20%201

which was taken from GitLab official documentation.

As you can see here, there's an option to automatically fill the Title section directly from URL but I couldn't figure out how to do the same for Labels. Is there any way to do it this way?

For internal requirements, there must be a label automatically selected and the users can't be relied on to select it by themselves. For each webpage, a new label is assigned which makes it possible to extract all the issues related to that webpage later just by extracting all issues with that label. This might not be an optimal way to do this so if you have any other suggestions, please put them in comments. Thanks.


Solution

  • You can put the /label in the description, with /-slash-commands aka GitLab quick actions you can do all kinds of stuff, really. If your issue description looks like this

    experiment failed
    
    /assign @betelgeuse
    /label ~"experiment-failed"
    

    you only have to urlencode and put it all together:

    https://gitlab.example.com/group/project/-/issues/new?issue[title]=Experiment+failed&issue[description]=experiment+failed%0d%0a%0d%0a%2fassign+%40betelgeuse%0d%0a%2flabel+%7e%22experiment-failed%22
    

    Alternatively, you may want to use a (versioned) issue template and reference that in the url.