mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Update branch API endpoint to show effective branch protection. (#9031)
* Add API endpoint for displaying effective branch protection. * Add status checks.
This commit is contained in:
		
				
					committed by
					
						
						zeripath
					
				
			
			
				
	
			
			
			
						parent
						
							3dfe9190b0
						
					
				
				
					commit
					86cff86b46
				
			@@ -30,10 +30,28 @@ func ToEmail(email *models.EmailAddress) *api.Email {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ToBranch convert a git.Commit and git.Branch to an api.Branch
 | 
			
		||||
func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit) *api.Branch {
 | 
			
		||||
func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *models.User) *api.Branch {
 | 
			
		||||
	if bp == nil {
 | 
			
		||||
		return &api.Branch{
 | 
			
		||||
			Name:                b.Name,
 | 
			
		||||
			Commit:              ToCommit(repo, c),
 | 
			
		||||
			Protected:           false,
 | 
			
		||||
			RequiredApprovals:   0,
 | 
			
		||||
			EnableStatusCheck:   false,
 | 
			
		||||
			StatusCheckContexts: []string{},
 | 
			
		||||
			UserCanPush:         true,
 | 
			
		||||
			UserCanMerge:        true,
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return &api.Branch{
 | 
			
		||||
		Name:   b.Name,
 | 
			
		||||
		Commit: ToCommit(repo, c),
 | 
			
		||||
		Name:                b.Name,
 | 
			
		||||
		Commit:              ToCommit(repo, c),
 | 
			
		||||
		Protected:           true,
 | 
			
		||||
		RequiredApprovals:   bp.RequiredApprovals,
 | 
			
		||||
		EnableStatusCheck:   bp.EnableStatusCheck,
 | 
			
		||||
		StatusCheckContexts: bp.StatusCheckContexts,
 | 
			
		||||
		UserCanPush:         bp.CanUserPush(user.ID),
 | 
			
		||||
		UserCanMerge:        bp.CanUserMerge(user.ID),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,12 @@ package structs
 | 
			
		||||
 | 
			
		||||
// Branch represents a repository branch
 | 
			
		||||
type Branch struct {
 | 
			
		||||
	Name   string         `json:"name"`
 | 
			
		||||
	Commit *PayloadCommit `json:"commit"`
 | 
			
		||||
	Name                string         `json:"name"`
 | 
			
		||||
	Commit              *PayloadCommit `json:"commit"`
 | 
			
		||||
	Protected           bool           `json:"protected"`
 | 
			
		||||
	RequiredApprovals   int64          `json:"required_approvals"`
 | 
			
		||||
	EnableStatusCheck   bool           `json:"enable_status_check"`
 | 
			
		||||
	StatusCheckContexts []string       `json:"status_check_contexts"`
 | 
			
		||||
	UserCanPush         bool           `json:"user_can_push"`
 | 
			
		||||
	UserCanMerge        bool           `json:"user_can_merge"`
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user