mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
84 lines
2.8 KiB
Go
84 lines
2.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package commitstatus
|
|
|
|
// CommitStatusState holds the state of a CommitStatus
|
|
// swagger:enum CommitStatusState
|
|
type CommitStatusState string //nolint:revive // export stutter
|
|
|
|
const (
|
|
// CommitStatusPending is for when the CommitStatus is Pending
|
|
CommitStatusPending CommitStatusState = "pending"
|
|
// CommitStatusSuccess is for when the CommitStatus is Success
|
|
CommitStatusSuccess CommitStatusState = "success"
|
|
// CommitStatusError is for when the CommitStatus is Error
|
|
CommitStatusError CommitStatusState = "error"
|
|
// CommitStatusFailure is for when the CommitStatus is Failure
|
|
CommitStatusFailure CommitStatusState = "failure"
|
|
// CommitStatusWarning is for when the CommitStatus is Warning
|
|
CommitStatusWarning CommitStatusState = "warning"
|
|
// CommitStatusSkipped is for when CommitStatus is Skipped
|
|
CommitStatusSkipped CommitStatusState = "skipped"
|
|
)
|
|
|
|
func (css CommitStatusState) String() string {
|
|
return string(css)
|
|
}
|
|
|
|
// IsPending represents if commit status state is pending
|
|
func (css CommitStatusState) IsPending() bool {
|
|
return css == CommitStatusPending
|
|
}
|
|
|
|
// IsSuccess represents if commit status state is success
|
|
func (css CommitStatusState) IsSuccess() bool {
|
|
return css == CommitStatusSuccess
|
|
}
|
|
|
|
// IsError represents if commit status state is error
|
|
func (css CommitStatusState) IsError() bool {
|
|
return css == CommitStatusError
|
|
}
|
|
|
|
// IsFailure represents if commit status state is failure
|
|
func (css CommitStatusState) IsFailure() bool {
|
|
return css == CommitStatusFailure
|
|
}
|
|
|
|
// IsWarning represents if commit status state is warning
|
|
func (css CommitStatusState) IsWarning() bool {
|
|
return css == CommitStatusWarning
|
|
}
|
|
|
|
// IsSkipped represents if commit status state is skipped
|
|
func (css CommitStatusState) IsSkipped() bool {
|
|
return css == CommitStatusSkipped
|
|
}
|
|
|
|
type CommitStatusStates []CommitStatusState //nolint:revive // export stutter
|
|
|
|
// 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
|
|
// > failure if any of the contexts report as warning (Gitea specific behavior)
|
|
// > pending if there are no statuses or a context is pending
|
|
// > success if the latest status for all contexts is success
|
|
func (css CommitStatusStates) Combine() CommitStatusState {
|
|
successCnt := 0
|
|
for _, state := range css {
|
|
switch {
|
|
case state.IsError() || state.IsFailure() || state.IsWarning():
|
|
return CommitStatusFailure
|
|
case state.IsPending():
|
|
case state.IsSuccess() || state.IsSkipped():
|
|
successCnt++
|
|
}
|
|
}
|
|
if successCnt > 0 && successCnt == len(css) {
|
|
return CommitStatusSuccess
|
|
}
|
|
return CommitStatusPending
|
|
}
|