mirror of https://github.com/harness/drone.git
feat: [CODE-2297]: add dry run param for delete branch API (#2590)
* Merge branch 'main' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into CODE-2297 * updated comment * worked on review comments and added to openapi spec * return empty violations array when dry_run = true * feat: [CODE-2297]: add dry run param for delete branch APIpull/3545/head
parent
81b10ba01c
commit
55d2b1dee3
|
@ -294,7 +294,7 @@ func (c *Controller) Merge(
|
|||
BranchDeleted: ruleOut.DeleteSourceBranch,
|
||||
RuleViolations: violations,
|
||||
|
||||
// values only retured by dry run
|
||||
// values only returned by dry run
|
||||
DryRun: true,
|
||||
ConflictFiles: pr.MergeConflicts,
|
||||
AllowedMethods: ruleOut.AllowedMethods,
|
||||
|
|
|
@ -33,6 +33,7 @@ func (c *Controller) DeleteBranch(ctx context.Context,
|
|||
repoRef string,
|
||||
branchName string,
|
||||
bypassRules bool,
|
||||
dryRunRules bool,
|
||||
) ([]types.RuleViolations, error) {
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoPush)
|
||||
if err != nil {
|
||||
|
@ -68,6 +69,10 @@ func (c *Controller) DeleteBranch(ctx context.Context,
|
|||
return violations, nil
|
||||
}
|
||||
|
||||
if dryRunRules {
|
||||
return []types.RuleViolations{}, nil
|
||||
}
|
||||
|
||||
writeParams, err := controller.CreateRPCInternalWriteParams(ctx, c.urlProvider, session, repo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create RPC write params: %w", err)
|
||||
|
|
|
@ -46,7 +46,13 @@ func HandleDeleteBranch(repoCtrl *repo.Controller) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
violations, err := repoCtrl.DeleteBranch(ctx, session, repoRef, branchName, bypassRules)
|
||||
dryRunRules, err := request.ParseDryRunRulesFromQuery(r)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(ctx, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
violations, err := repoCtrl.DeleteBranch(ctx, session, repoRef, branchName, bypassRules, dryRunRules)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(ctx, w, err)
|
||||
}
|
||||
|
|
|
@ -527,6 +527,21 @@ var queryParameterBypassRules = openapi3.ParameterOrRef{
|
|||
},
|
||||
}
|
||||
|
||||
var queryParameterDryRunRules = openapi3.ParameterOrRef{
|
||||
Parameter: &openapi3.Parameter{
|
||||
Name: request.QueryParamDryRunRules,
|
||||
In: openapi3.ParameterInQuery,
|
||||
Description: ptr.String("Dry run rules for operations"),
|
||||
Required: ptr.Bool(false),
|
||||
Schema: &openapi3.SchemaOrRef{
|
||||
Schema: &openapi3.Schema{
|
||||
Type: ptrSchemaType(openapi3.SchemaTypeBoolean),
|
||||
Default: ptrptr(false),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var queryParameterDeletedAt = openapi3.ParameterOrRef{
|
||||
Parameter: &openapi3.Parameter{
|
||||
Name: request.QueryParamDeletedAt,
|
||||
|
@ -907,7 +922,7 @@ func repoOperations(reflector *openapi3.Reflector) {
|
|||
opDeleteBranch := openapi3.Operation{}
|
||||
opDeleteBranch.WithTags("repository")
|
||||
opDeleteBranch.WithMapOfAnything(map[string]interface{}{"operationId": "deleteBranch"})
|
||||
opDeleteBranch.WithParameters(queryParameterBypassRules)
|
||||
opDeleteBranch.WithParameters(queryParameterBypassRules, queryParameterDryRunRules)
|
||||
_ = reflector.SetRequest(&opDeleteBranch, new(deleteBranchRequest), http.MethodDelete)
|
||||
_ = reflector.SetJSONResponse(&opDeleteBranch, nil, http.StatusNoContent)
|
||||
_ = reflector.SetJSONResponse(&opDeleteBranch, new(usererror.Error), http.StatusInternalServerError)
|
||||
|
|
|
@ -25,6 +25,7 @@ const (
|
|||
PathParamRuleIdentifier = "rule_identifier"
|
||||
|
||||
QueryParamBypassRules = "bypass_rules"
|
||||
QueryParamDryRunRules = "dry_run_rules"
|
||||
)
|
||||
|
||||
// ParseRuleFilter extracts the protection rule query parameters from the url.
|
||||
|
@ -71,3 +72,8 @@ func parseRuleSort(r *http.Request) enum.RuleSort {
|
|||
func ParseBypassRulesFromQuery(r *http.Request) (bool, error) {
|
||||
return QueryParamAsBoolOrDefault(r, QueryParamBypassRules, false)
|
||||
}
|
||||
|
||||
// ParseDryRunRulesFromQuery extracts the dry run rules parameter from the URL query.
|
||||
func ParseDryRunRulesFromQuery(r *http.Request) (bool, error) {
|
||||
return QueryParamAsBoolOrDefault(r, QueryParamDryRunRules, false)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue