Skip to content

Add endpoint for prevent_merge_without_jira_issue

Ben King requested to merge benjaminking-jira-issue-api into master

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

  1. Ensure your GDK instance is licensed with Premium or Ultimate.
  2. 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.
  3. Go to Settings → Merge Requests, then under Merge checks locate the option Require an associated issue from Jira.

GET Request

  1. 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 return false.
  2. 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 as true, confirming the GET request properly retrieves the current state from the project.

PUT Request

  1. Make a curl request using PUT to set the value of prevent_merge_without_jira_issue to true or false: curl --request PUT --header "PRIVATE-TOKEN: <token>" --url "http://localhost:3000/api/v4/projects/<id>" --data "prevent_merge_without_jira_issue=true".
  2. 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) is true.
  • 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:

  1. Remove the subscription from the instance
  2. Attempt to GET or PUT the attribute via the API. A nil or null response should be returned for prevent_merge_without_jira_issue if checking with jq, otherwise it will not appear in the output at all.
  3. 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.

Edited by Ben King

Merge request reports