-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Improve CommitStatus #26247
Closed
Closed
[WIP] Improve CommitStatus #26247
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b7fa387
improve
yp05327 cabff1e
Merge branch 'main' into improve-commitstatus
yp05327 cccd2ef
improve test
yp05327 f99fbaf
use CommitStatusState.IsXXXX
yp05327 1fad846
add IsValid
yp05327 302e583
fix lint
yp05327 4852352
fix
yp05327 ab6a8d5
improve
yp05327 ec1b8eb
improve
yp05327 30b5b18
fix lint
yp05327 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_21 //nolint | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/log" | ||
"xorm.io/xorm" | ||
) | ||
|
||
func ConvertCommitStatusStateIntoInt(x *xorm.Engine) error { | ||
// CommitStatusState holds the state of a CommitStatus | ||
// It can be "pending", "success", "error" and "failure" | ||
type CommitStatusState int | ||
|
||
const ( | ||
// CommitStatusError is for when the CommitStatus is Error | ||
CommitStatusError CommitStatusState = iota + 1 | ||
// CommitStatusFailure is for when the CommitStatus is Failure | ||
CommitStatusFailure | ||
// CommitStatusPending is for when the CommitStatus is Pending | ||
CommitStatusPending | ||
// CommitStatusSuccess is for when the CommitStatus is Success | ||
CommitStatusSuccess | ||
) | ||
|
||
// CommitStatus holds a single Status of a single Commit | ||
type CommitStatus struct { | ||
State CommitStatusState `xorm:"INDEX NOT NULL"` | ||
} | ||
|
||
var commitStatusConvertMap = map[string]CommitStatusState{ | ||
"error": CommitStatusError, | ||
"failure": CommitStatusFailure, | ||
"pending": CommitStatusPending, | ||
"success": CommitStatusSuccess, | ||
} | ||
|
||
sess := x.NewSession() | ||
defer sess.Close() | ||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
|
||
if err := sess.Sync2(new(CommitStatus)); err != nil { | ||
return err | ||
} | ||
|
||
for origin, target := range commitStatusConvertMap { | ||
count, err := sess.Where("`state` = ?", origin).Update(&CommitStatus{State: target}) | ||
if err != nil { | ||
return err | ||
} | ||
log.Debug("Updated %d commit status with %s status", count, origin) | ||
} | ||
|
||
return sess.Commit() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires checking for special values, enhancing the robustness of the function, and avoiding issues caused by incorrect usage by the caller, as seen in #26121.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, I want to remove this function.
It is only used in
MergeRequiredContextsCommitStatus
. But have no good idea about how to rewrite it now.Or maybe I will add
CommitStatusState.IsValid
which should be called before we compare them.