mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Extract from #34531 ## Move Commit status state to a standalone package Move the state from `structs` to `commitstatus` package. It also introduce `CommitStatusStates` so that the combine function could be used from UI and API logic. ## Combined commit status Changed This PR will follow Github's combined commit status. Before this PR, every commit status could be a combined one. According to https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#get-the-combined-status-for-a-specific-reference > Additionally, a combined state is returned. The state is one of: > failure if any of the contexts report as error or failure > pending if there are no statuses or a context is pending > success if the latest status for all contexts is success This PR will follow that rule and remove the `NoBetterThan` logic. This also fixes the inconsistent between UI and API. In the API convert package, it has implemented this which is different from the UI. It also fixed the missing `URL` and `CommitURL` in the API. ## `CalcCommitStatus` return nil if there is no commit statuses The behavior of `CalcCommitStatus` is changed. If the parameter commit statuses is empty, it will return nil. The reference places should check the returned value themselves.
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2017 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package structs
 | |
| 
 | |
| import (
 | |
| 	"time"
 | |
| 
 | |
| 	"code.gitea.io/gitea/modules/commitstatus"
 | |
| )
 | |
| 
 | |
| // CommitStatus holds a single status of a single Commit
 | |
| type CommitStatus struct {
 | |
| 	ID          int64                          `json:"id"`
 | |
| 	State       commitstatus.CommitStatusState `json:"status"`
 | |
| 	TargetURL   string                         `json:"target_url"`
 | |
| 	Description string                         `json:"description"`
 | |
| 	URL         string                         `json:"url"`
 | |
| 	Context     string                         `json:"context"`
 | |
| 	Creator     *User                          `json:"creator"`
 | |
| 	// swagger:strfmt date-time
 | |
| 	Created time.Time `json:"created_at"`
 | |
| 	// swagger:strfmt date-time
 | |
| 	Updated time.Time `json:"updated_at"`
 | |
| }
 | |
| 
 | |
| // CombinedStatus holds the combined state of several statuses for a single commit
 | |
| type CombinedStatus struct {
 | |
| 	State      commitstatus.CommitStatusState `json:"state"`
 | |
| 	SHA        string                         `json:"sha"`
 | |
| 	TotalCount int                            `json:"total_count"`
 | |
| 	Statuses   []*CommitStatus                `json:"statuses"`
 | |
| 	Repository *Repository                    `json:"repository"`
 | |
| 	CommitURL  string                         `json:"commit_url"`
 | |
| 	URL        string                         `json:"url"`
 | |
| }
 | |
| 
 | |
| // CreateStatusOption holds the information needed to create a new CommitStatus for a Commit
 | |
| type CreateStatusOption struct {
 | |
| 	State       commitstatus.CommitStatusState `json:"state"`
 | |
| 	TargetURL   string                         `json:"target_url"`
 | |
| 	Description string                         `json:"description"`
 | |
| 	Context     string                         `json:"context"`
 | |
| }
 |