DAST on-demand: Select branch for on-demand scans
<!-- The first section "Release notes" is required if you want to have your release post blog MR auto generated. Currently in BETA, details on the **release post item generator** can be found in the handbook: https://about.gitlab.com/handbook/marketing/blog/release-posts/#release-post-item-generator and this video: https://www.youtube.com/watch?v=rfn9ebgTwKg. The next four sections: "Problem to solve", "Intended users", "User experience goal", and "Proposal", are strongly recommended in your first draft, while the rest of the sections can be filled out during the problem validation or breakdown phase. However, keep in mind that providing complete and relevant information early helps our product team validate the problem and start working on a solution. -->
### Release notes
<!-- What is the problem and solution you're proposing? This content sets the overall vision for the feature and serves as the release notes that will populate in various places, including the [release post blog](https://about.gitlab.com/releases/categories/releases/) and [Gitlab project releases](https://gitlab.com/gitlab-org/gitlab/-/releases). " -->
Currently, users are only able to scan the default branch with on-demand scans. This can cause problems, as the code that the user has deployed and is scanning might be on a feature or staging branch. It also causes accessibility problems in that default branches are protected by default, which does not allow for users with developer permissions to scan the branch. By allowing users to pick the branch that the scan is associated with, we will allow developers to scan their code that is deployed from feature or staging branches and not require that the default branch be unprotected or developer permissions elevated in order to conduct a successful on-demand DAST scan.
### Problem to solve
<!-- What problem do we solve? Try to define the who/what/why of the opportunity as a user story. For example, "As a (who), I want (what), so I can (why/value)." -->
As an on-demand DAST user, I would like to select the branch that my on-demand scans are associated with, so that I'm not constrained to only scanning the default branch.
Currently, users are only able to scan the default branch with on-demand scans. This can cause problems, as the code that the user has deployed and is scanning might be on a feature or staging branch. It also causes accessibility problems in that default branches are protected by default, which does not allow for users with developer permissions to scan the branch. In order to allow a wider range of users to use on-demand scans, we need to enable them to pick the branch that the scans are associated with.
### Proposal
<!-- How are we going to solve the problem? Try to include the user journey! https://about.gitlab.com/handbook/journeys/#user-journey -->
The user should be able to select the branch the scan is associated with when they select the profiles they want to run in the scan. The branch selection should not be a part of either profile, but part of the scan configuration itself. Once saved scans are implemented, this will allow users to save a scan with a branch, site profile, and scanner profile. The default branch will be selected as the default for this field.
### Documentation
<!-- See the Feature Change Documentation Workflow https://docs.gitlab.com/ee/development/documentation/workflow.html#for-a-product-change
* Add all known Documentation Requirements in this section. See https://docs.gitlab.com/ee/development/documentation/feature-change-workflow.html#documentation-requirements
* If this feature requires changing permissions, update the permissions document. See https://docs.gitlab.com/ee/user/permissions.html -->
The on-demand DAST scan documentation will need to be updated to reflect this ability to select the branch.
# Implementation Plan
* `dast_branch_selection` ~"feature flag" rollout issue: https://gitlab.com/gitlab-org/gitlab/-/issues/322672
| Task # | Issue | Description | Department |
| ------ | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | -------------- |
| 1 | https://gitlab.com/gitlab-org/gitlab/-/issues/322526 | Select branch for on-demand scans - Backend | ~backend |
| 2 | https://gitlab.com/gitlab-org/gitlab/-/issues/322890 | Enhance the `RefSelector` component as needed. | ~frontend |
| 3 | https://gitlab.com/gitlab-org/gitlab/-/issues/322872 | Leverage the `RefSelector` component to show available branches and update mutation to pass the selected branch. | ~frontend |
| 4 | https://gitlab.com/gitlab-org/gitlab/-/issues/323789 | Display branch information in the profiles library. | ~frontend |
| 5 | https://gitlab.com/gitlab-org/gitlab/-/issues/322673 | Select branch for on-demand scans - Documentation | ~documentation |
## Decisions
### GraphQL schemas
`DastProfile` will be extended with a new field of type `DastProfileBranch`.
```haskell
type DastProfile {
id: DastProfileID
name: String
description: String
dastSiteProfile: DastSiteProfile
dastScannerProfile: DastScannerProfile
branch: DastProfileBranch
editPath: String
}
type DastProfileBranch {
name: String
exists: Boolean
}
```
`dastProfileCreate` will be extended with a new optional input and new output.
```diff
1c1
< mutation dastProfileCreate($fullPath: ID!, $name: String!, $description: String, $dastSiteProfileId: DastSiteProfileID!, $dastProfilenerProfileID: DastProfilenerProfileID!, $runAfterCreate: Boolean) {
---
> mutation dastProfileCreate($fullPath: ID!, $name: String!, $description: String, $dastSiteProfileId: DastSiteProfileID!, $dastProfilenerProfileID: DastProfilenerProfileID!, $runAfterCreate: Boolean, $branch: String) {
9c9,10
< runAfterCreate: $runAfterCreate
---
> runAfterCreate: $runAfterCreate,
> branchName: $branch
23a25,27
> branch {
> name
> }
```
`dastProfileUpdate` will be extended with a new optional input and new output.
```diff
1c1
< mutation dastProfileUpdate($fullPath: ID!, $id: DastProfileID!, $name: String, $description: String, $dastSiteProfileId: DastSiteProfileID, $dastProfilenerProfileID: $DastProfilenerProfileID, $runAfterUpdate: Boolean) {
---
> mutation dastProfileUpdate($fullPath: ID!, $id: DastProfileID!, $name: String, $description: String, $dastSiteProfileId: DastSiteProfileID, $dastProfilenerProfileID: $DastProfilenerProfileID, $runAfterUpdate: Boolean, $branch: String) {
10c10,11
< runAfterUpdate: $runAfterUpdate
---
> runAfterUpdate: $runAfterUpdate,
> branchName: $branch
24a26,28
> branch {
> name
> }
```
`dastProfiles` will be extended with new fields.
#### `dastProfiles` query
```diff
15a16,19
> branch {
> name
> exists
> }
```
### Branch Selection
The existing ~backend and ~frontend functionality for selecting branches will be reused and adapted as necessary.
epic