mirror of
https://github.com/go-gitea/gitea
synced 2024-09-21 19:26:06 +00:00
Fix backend dup code lint err and generate swagger
This commit is contained in:
parent
2d2bbf28f9
commit
f28ecbe420
@ -518,50 +518,58 @@ func DeleteProtectedBranch(ctx context.Context, repo *repo_model.Repository, id
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveUserIDFromProtectedBranch remove all user ids from protected branch options
|
// removeIDsFromProtectedBranch is a helper function to remove IDs from protected branch options
|
||||||
func RemoveUserIDFromProtectedBranch(ctx context.Context, p *ProtectedBranch, userID int64) error {
|
func removeIDsFromProtectedBranch(ctx context.Context, p *ProtectedBranch, userID, teamID int64, columnNames []string) error {
|
||||||
lenIDs, lenForcePushIDs, lenApprovalIDs, lenMergeIDs := len(p.WhitelistUserIDs), len(p.ForcePushWhitelistUserIDs), len(p.ApprovalsWhitelistUserIDs), len(p.MergeWhitelistUserIDs)
|
lenUserIDs, lenForcePushIDs, lenApprovalIDs, lenMergeIDs := len(p.WhitelistUserIDs), len(p.ForcePushWhitelistUserIDs), len(p.ApprovalsWhitelistUserIDs), len(p.MergeWhitelistUserIDs)
|
||||||
p.WhitelistUserIDs = util.SliceRemoveAll(p.WhitelistUserIDs, userID)
|
lenTeamIDs, lenForcePushTeamIDs, lenApprovalTeamIDs, lenMergeTeamIDs := len(p.WhitelistTeamIDs), len(p.ForcePushWhitelistTeamIDs), len(p.ApprovalsWhitelistTeamIDs), len(p.MergeWhitelistTeamIDs)
|
||||||
p.ForcePushWhitelistUserIDs = util.SliceRemoveAll(p.ForcePushWhitelistUserIDs, userID)
|
|
||||||
p.ApprovalsWhitelistUserIDs = util.SliceRemoveAll(p.ApprovalsWhitelistUserIDs, userID)
|
|
||||||
p.MergeWhitelistUserIDs = util.SliceRemoveAll(p.MergeWhitelistUserIDs, userID)
|
|
||||||
|
|
||||||
if lenIDs != len(p.WhitelistUserIDs) ||
|
if userID > 0 {
|
||||||
|
p.WhitelistUserIDs = util.SliceRemoveAll(p.WhitelistUserIDs, userID)
|
||||||
|
p.ForcePushWhitelistUserIDs = util.SliceRemoveAll(p.ForcePushWhitelistUserIDs, userID)
|
||||||
|
p.ApprovalsWhitelistUserIDs = util.SliceRemoveAll(p.ApprovalsWhitelistUserIDs, userID)
|
||||||
|
p.MergeWhitelistUserIDs = util.SliceRemoveAll(p.MergeWhitelistUserIDs, userID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if teamID > 0 {
|
||||||
|
p.WhitelistTeamIDs = util.SliceRemoveAll(p.WhitelistTeamIDs, teamID)
|
||||||
|
p.ForcePushWhitelistTeamIDs = util.SliceRemoveAll(p.ForcePushWhitelistTeamIDs, teamID)
|
||||||
|
p.ApprovalsWhitelistTeamIDs = util.SliceRemoveAll(p.ApprovalsWhitelistTeamIDs, teamID)
|
||||||
|
p.MergeWhitelistTeamIDs = util.SliceRemoveAll(p.MergeWhitelistTeamIDs, teamID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lenUserIDs != len(p.WhitelistUserIDs) ||
|
||||||
lenForcePushIDs != len(p.ForcePushWhitelistUserIDs) ||
|
lenForcePushIDs != len(p.ForcePushWhitelistUserIDs) ||
|
||||||
lenApprovalIDs != len(p.ApprovalsWhitelistUserIDs) ||
|
lenApprovalIDs != len(p.ApprovalsWhitelistUserIDs) ||
|
||||||
lenMergeIDs != len(p.MergeWhitelistUserIDs) {
|
lenMergeIDs != len(p.MergeWhitelistUserIDs)) ||
|
||||||
if _, err := db.GetEngine(ctx).ID(p.ID).Cols(
|
(lenTeamIDs != len(p.WhitelistTeamIDs) ||
|
||||||
"whitelist_user_i_ds",
|
lenForcePushTeamIDs != len(p.ForcePushWhitelistTeamIDs) ||
|
||||||
"force_push_whitelist_user_i_ds",
|
lenApprovalTeamIDs != len(p.ApprovalsWhitelistTeamIDs) ||
|
||||||
"merge_whitelist_user_i_ds",
|
lenMergeTeamIDs != len(p.MergeWhitelistTeamIDs)) {
|
||||||
"approvals_whitelist_user_i_ds",
|
if _, err := db.GetEngine(ctx).ID(p.ID).Cols(columnNames...).Update(p); err != nil {
|
||||||
).Update(p); err != nil {
|
|
||||||
return fmt.Errorf("updateProtectedBranches: %v", err)
|
return fmt.Errorf("updateProtectedBranches: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveTeamIDFromProtectedBranch remove all team ids from protected branch options
|
// RemoveUserIDFromProtectedBranch removes all user ids from protected branch options
|
||||||
|
func RemoveUserIDFromProtectedBranch(ctx context.Context, p *ProtectedBranch, userID int64) error {
|
||||||
|
columnNames := []string{
|
||||||
|
"whitelist_user_i_ds",
|
||||||
|
"force_push_whitelist_user_i_ds",
|
||||||
|
"merge_whitelist_user_i_ds",
|
||||||
|
"approvals_whitelist_user_i_ds",
|
||||||
|
}
|
||||||
|
return removeIDsFromProtectedBranch(ctx, p, userID, 0, columnNames)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveTeamIDFromProtectedBranch removes all team ids from protected branch options
|
||||||
func RemoveTeamIDFromProtectedBranch(ctx context.Context, p *ProtectedBranch, teamID int64) error {
|
func RemoveTeamIDFromProtectedBranch(ctx context.Context, p *ProtectedBranch, teamID int64) error {
|
||||||
lenIDs, lenForcePushIDs, lenApprovalIDs, lenMergeIDs := len(p.WhitelistTeamIDs), len(p.ForcePushWhitelistTeamIDs), len(p.ApprovalsWhitelistTeamIDs), len(p.MergeWhitelistTeamIDs)
|
columnNames := []string{
|
||||||
p.WhitelistTeamIDs = util.SliceRemoveAll(p.WhitelistTeamIDs, teamID)
|
"whitelist_team_i_ds",
|
||||||
p.ForcePushWhitelistTeamIDs = util.SliceRemoveAll(p.ForcePushWhitelistTeamIDs, teamID)
|
"force_push_whitelist_team_i_ds",
|
||||||
p.ApprovalsWhitelistTeamIDs = util.SliceRemoveAll(p.ApprovalsWhitelistTeamIDs, teamID)
|
"merge_whitelist_team_i_ds",
|
||||||
p.MergeWhitelistTeamIDs = util.SliceRemoveAll(p.MergeWhitelistTeamIDs, teamID)
|
"approvals_whitelist_team_i_ds",
|
||||||
|
|
||||||
if lenIDs != len(p.WhitelistTeamIDs) ||
|
|
||||||
lenForcePushIDs != len(p.ForcePushWhitelistTeamIDs) ||
|
|
||||||
lenApprovalIDs != len(p.ApprovalsWhitelistTeamIDs) ||
|
|
||||||
lenMergeIDs != len(p.MergeWhitelistTeamIDs) {
|
|
||||||
if _, err := db.GetEngine(ctx).ID(p.ID).Cols(
|
|
||||||
"whitelist_team_i_ds",
|
|
||||||
"force_push_whitelist_team_i_ds",
|
|
||||||
"merge_whitelist_team_i_ds",
|
|
||||||
"approvals_whitelist_team_i_ds",
|
|
||||||
).Update(p); err != nil {
|
|
||||||
return fmt.Errorf("updateProtectedBranches: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return removeIDsFromProtectedBranch(ctx, p, 0, teamID, columnNames)
|
||||||
}
|
}
|
||||||
|
156
templates/swagger/v1_json.tmpl
generated
156
templates/swagger/v1_json.tmpl
generated
@ -16914,6 +16914,14 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableApprovalsWhitelist"
|
"x-go-name": "EnableApprovalsWhitelist"
|
||||||
},
|
},
|
||||||
|
"enable_force_push": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "EnableForcePush"
|
||||||
|
},
|
||||||
|
"enable_force_push_whitelist": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "EnableForcePushWhitelist"
|
||||||
|
},
|
||||||
"enable_merge_whitelist": {
|
"enable_merge_whitelist": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableMergeWhitelist"
|
"x-go-name": "EnableMergeWhitelist"
|
||||||
@ -16926,18 +16934,28 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnablePushWhitelist"
|
"x-go-name": "EnablePushWhitelist"
|
||||||
},
|
},
|
||||||
"enable_force_push": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "EnableForcePush"
|
|
||||||
},
|
|
||||||
"enable_force_push_whitelist": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "EnableForcePushWhitelist"
|
|
||||||
},
|
|
||||||
"enable_status_check": {
|
"enable_status_check": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableStatusCheck"
|
"x-go-name": "EnableStatusCheck"
|
||||||
},
|
},
|
||||||
|
"force_push_whitelist_deploy_keys": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "ForcePushWhitelistDeployKeys"
|
||||||
|
},
|
||||||
|
"force_push_whitelist_teams": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"x-go-name": "ForcePushWhitelistTeams"
|
||||||
|
},
|
||||||
|
"force_push_whitelist_usernames": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"x-go-name": "ForcePushWhitelistUsernames"
|
||||||
|
},
|
||||||
"merge_whitelist_teams": {
|
"merge_whitelist_teams": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
@ -16974,24 +16992,6 @@
|
|||||||
},
|
},
|
||||||
"x-go-name": "PushWhitelistUsernames"
|
"x-go-name": "PushWhitelistUsernames"
|
||||||
},
|
},
|
||||||
"force_push_whitelist_deploy_keys": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "ForcePushWhitelistDeployKeys"
|
|
||||||
},
|
|
||||||
"force_push_whitelist_teams": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"x-go-name": "ForcePushWhitelistTeams"
|
|
||||||
},
|
|
||||||
"force_push_whitelist_usernames": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"x-go-name": "ForcePushWhitelistUsernames"
|
|
||||||
},
|
|
||||||
"require_signed_commits": {
|
"require_signed_commits": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "RequireSignedCommits"
|
"x-go-name": "RequireSignedCommits"
|
||||||
@ -17581,6 +17581,14 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableApprovalsWhitelist"
|
"x-go-name": "EnableApprovalsWhitelist"
|
||||||
},
|
},
|
||||||
|
"enable_force_push": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "EnableForcePush"
|
||||||
|
},
|
||||||
|
"enable_force_push_whitelist": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "EnableForcePushWhitelist"
|
||||||
|
},
|
||||||
"enable_merge_whitelist": {
|
"enable_merge_whitelist": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableMergeWhitelist"
|
"x-go-name": "EnableMergeWhitelist"
|
||||||
@ -17593,18 +17601,28 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnablePushWhitelist"
|
"x-go-name": "EnablePushWhitelist"
|
||||||
},
|
},
|
||||||
"enable_force_push": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "EnableForcePush"
|
|
||||||
},
|
|
||||||
"enable_force_push_whitelist": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "EnableForcePushWhitelist"
|
|
||||||
},
|
|
||||||
"enable_status_check": {
|
"enable_status_check": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableStatusCheck"
|
"x-go-name": "EnableStatusCheck"
|
||||||
},
|
},
|
||||||
|
"force_push_whitelist_deploy_keys": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "ForcePushWhitelistDeployKeys"
|
||||||
|
},
|
||||||
|
"force_push_whitelist_teams": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"x-go-name": "ForcePushWhitelistTeams"
|
||||||
|
},
|
||||||
|
"force_push_whitelist_usernames": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"x-go-name": "ForcePushWhitelistUsernames"
|
||||||
|
},
|
||||||
"merge_whitelist_teams": {
|
"merge_whitelist_teams": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
@ -17641,24 +17659,6 @@
|
|||||||
},
|
},
|
||||||
"x-go-name": "PushWhitelistUsernames"
|
"x-go-name": "PushWhitelistUsernames"
|
||||||
},
|
},
|
||||||
"force_push_whitelist_deploy_keys": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "ForcePushWhitelistDeployKeys"
|
|
||||||
},
|
|
||||||
"force_push_whitelist_teams": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"x-go-name": "ForcePushWhitelistTeams"
|
|
||||||
},
|
|
||||||
"force_push_whitelist_usernames": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"x-go-name": "ForcePushWhitelistUsernames"
|
|
||||||
},
|
|
||||||
"require_signed_commits": {
|
"require_signed_commits": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "RequireSignedCommits"
|
"x-go-name": "RequireSignedCommits"
|
||||||
@ -18739,6 +18739,14 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableApprovalsWhitelist"
|
"x-go-name": "EnableApprovalsWhitelist"
|
||||||
},
|
},
|
||||||
|
"enable_force_push": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "EnableForcePush"
|
||||||
|
},
|
||||||
|
"enable_force_push_whitelist": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "EnableForcePushWhitelist"
|
||||||
|
},
|
||||||
"enable_merge_whitelist": {
|
"enable_merge_whitelist": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableMergeWhitelist"
|
"x-go-name": "EnableMergeWhitelist"
|
||||||
@ -18751,18 +18759,28 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnablePushWhitelist"
|
"x-go-name": "EnablePushWhitelist"
|
||||||
},
|
},
|
||||||
"enable_force_push": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "EnableForcePush"
|
|
||||||
},
|
|
||||||
"enable_force_push_whitelist": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "EnableForcePushWhitelist"
|
|
||||||
},
|
|
||||||
"enable_status_check": {
|
"enable_status_check": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnableStatusCheck"
|
"x-go-name": "EnableStatusCheck"
|
||||||
},
|
},
|
||||||
|
"force_push_whitelist_deploy_keys": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "ForcePushWhitelistDeployKeys"
|
||||||
|
},
|
||||||
|
"force_push_whitelist_teams": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"x-go-name": "ForcePushWhitelistTeams"
|
||||||
|
},
|
||||||
|
"force_push_whitelist_usernames": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"x-go-name": "ForcePushWhitelistUsernames"
|
||||||
|
},
|
||||||
"merge_whitelist_teams": {
|
"merge_whitelist_teams": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
@ -18799,24 +18817,6 @@
|
|||||||
},
|
},
|
||||||
"x-go-name": "PushWhitelistUsernames"
|
"x-go-name": "PushWhitelistUsernames"
|
||||||
},
|
},
|
||||||
"force_push_whitelist_deploy_keys": {
|
|
||||||
"type": "boolean",
|
|
||||||
"x-go-name": "ForcePushWhitelistDeployKeys"
|
|
||||||
},
|
|
||||||
"force_push_whitelist_teams": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"x-go-name": "ForcePushWhitelistTeams"
|
|
||||||
},
|
|
||||||
"force_push_whitelist_usernames": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"x-go-name": "ForcePushWhitelistUsernames"
|
|
||||||
},
|
|
||||||
"require_signed_commits": {
|
"require_signed_commits": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "RequireSignedCommits"
|
"x-go-name": "RequireSignedCommits"
|
||||||
|
Loading…
Reference in New Issue
Block a user