Add endpoint for prevent_merge_without_jira_issue
What does this MR do and why?
Tied to Issue: #431964
This merge request adds an accessible API endpoint for configuring prevent_merge_without_jira_issue
. In the UI, this is a checkbox value shown as: Require an associated issue from Jira
.
How to set up and validate locally
- Ensure your GDK instance is licensed with Premium or Ultimate.
- Enable a 'fake' Jira integration in a project by going to Settings → Integrations → Jira. Configure a fake Web URL, Email and Password, then select Save changes.
- Go to Settings → Merge Requests, then under Merge checks locate the option
Require an associated issue from Jira
.
GET Request
- Create a personal access token for your account, then make a GET query against the project with:
curl --header "PRIVATE-TOKEN: <token>" --url "http://localhost:3000/api/v4/projects/<id>" | jq .prevent_merge_without_jira_issue
. This should returnfalse
. - In the UI, click the checkbox
Require an associated issue from Jira
, then scroll down and select Save Changes. Make another API query, which should now show astrue
, confirming the GET request properly retrieves the current state from the project.
PUT Request
- Make a curl request using
PUT
to set the value ofprevent_merge_without_jira_issue
totrue
orfalse
:curl --request PUT --header "PRIVATE-TOKEN: <token>" --url "http://localhost:3000/api/v4/projects/<id>" --data "prevent_merge_without_jira_issue=true"
. - Confirm that the UI has updated to reflect the same state based on what the Boolean was set to.
Testing without a Subscription
As Jira issue integration is locked behind a Premium or Ultimate subscription, we limit access by:
- Only exposing the attribute in the API when
project.feature_available?(:jira_issue_association_enforcement)
istrue
. - Don't accept the attribute in an API PUT request if the License (Free) doesn't support the associated feature:
unless ::License.feature_available?(:jira_issue_association_enforcement)
attrs.delete(:prevent_merge_without_jira_issue)
end
To test this behaviour:
- Remove the subscription from the instance
- Attempt to GET or PUT the attribute via the API. A
nil
ornull
response should be returned forprevent_merge_without_jira_issue
if checking withjq
, otherwise it will not appear in the output at all. - Load a Rails console and use the following commands to confirm that the setting hasn't changed. Even without a subscription we retain the last state of the feature against the project:
p = Project.find_by(id: <id>)
p.project_setting.prevent_merge_without_jira_issue
Subsequent testing of changing the value with PUT
actions should show that this has not updated the value without a subscription present.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Ben King