Best practice to automatically modify a merge request after it's created
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Please look at gitlab-ce#42570 for background, specifically my comment on what I require - reproduced here (and slightly expanded on) for posterity:
Our project uses JIRA for issue tracking and our standard is that merge requests must be titled with the JIRA ticket number to which the MR refers, while the link to that issue must be in the body of the MR. Currently, when devs submit a merge request, they have to copy the JIRA ticket heading and URL into the title and description of the MR respectively, which is a pain.
However, our project standard also has us name our feature branches starting with a number. That number is the JIRA ticket that the branch refers to. Using Atlassian's JIRA API, it's possible to retrieve the metadata about the issue that that branch refers to.
Thus, if GitLab exposed an API that allowed merge requests to be modified (not just inspected) after submission, we could automatically populate the title and description of our MRs.
I originally thought that a new webhook would cover this scenario, but then realised that webhooks are currently one-way broadcast events that don't allow for modification. My new theory is that I would instead need to do the following:
- listen to the current MR webhook for a "created" or "updated" event
- invoke the JIRA issue API with the integer portion of the branch name from the MR to get the issue metadata
- if the MR data has changed, invoke the GitLab MR API to update the MR with the metadata from the previous step
Is there any better/simpler/recommended way to do this? I'm aware of JIRA's Smart Commit functionality, but would prefer this to be driven from within the GitLab UI.
(Note: I'm aware that GitLab's JIRA integration allows for JIRA issue links to be embedded directly in MR descriptions, but that still requires the submitter to type <projectName>-<issueNumber> in the "Description" field when creating the MR; I want to avoid that entirely.)