diff --git a/models/git/commit_status.go b/models/git/commit_status.go
index 2d1d1bcb06..d204d11c28 100644
--- a/models/git/commit_status.go
+++ b/models/git/commit_status.go
@@ -199,22 +199,17 @@ func (status *CommitStatus) LocaleString(lang translation.Locale) string {
// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus {
- var lastStatus *CommitStatus
- state := api.CommitStatusSuccess
- for _, status := range statuses {
- if status.State.NoBetterThan(state) {
- state = status.State
- lastStatus = status
+ if len(statuses) == 0 {
+ return nil
+ }
+
+ latestWorstStatus := statuses[0]
+ for _, status := range statuses[1:] {
+ if status.State.NoBetterThan(latestWorstStatus.State) {
+ latestWorstStatus = status
}
}
- if lastStatus == nil {
- if len(statuses) > 0 {
- lastStatus = statuses[0]
- } else {
- lastStatus = &CommitStatus{}
- }
- }
- return lastStatus
+ return latestWorstStatus
}
// CommitStatusOptions holds the options for query commit statuses
diff --git a/models/git/commit_status_test.go b/models/git/commit_status_test.go
index 74ba4a1006..94c8d3776c 100644
--- a/models/git/commit_status_test.go
+++ b/models/git/commit_status_test.go
@@ -141,16 +141,20 @@ func Test_CalcCommitStatus(t *testing.T) {
statuses: []*git_model.CommitStatus{
{
State: structs.CommitStatusSuccess,
+ ID: 1,
},
{
State: structs.CommitStatusSuccess,
+ ID: 2,
},
{
State: structs.CommitStatusSuccess,
+ ID: 3,
},
},
expected: &git_model.CommitStatus{
State: structs.CommitStatusSuccess,
+ ID: 3,
},
},
{
@@ -169,6 +173,10 @@ func Test_CalcCommitStatus(t *testing.T) {
State: structs.CommitStatusError,
},
},
+ {
+ statuses: []*git_model.CommitStatus{},
+ expected: nil,
+ },
}
for _, kase := range kases {
diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go
index 514bcee8f1..cb63123463 100644
--- a/services/pull/commit_status.go
+++ b/services/pull/commit_status.go
@@ -65,7 +65,7 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
if status != nil {
return status.State
}
- return structs.CommitStatusSuccess
+ return ""
}
return returnedStatus
diff --git a/services/repository/commitstatus/commitstatus.go b/services/repository/commitstatus/commitstatus.go
index 145fc7d53c..0bb738e2ad 100644
--- a/services/repository/commitstatus/commitstatus.go
+++ b/services/repository/commitstatus/commitstatus.go
@@ -123,7 +123,7 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep
for i, repo := range repos {
if results[i] == nil {
results[i] = git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
- if results[i].State != "" {
+ if results[i] != nil {
if err := updateCommitStatusCache(ctx, repo.ID, repo.DefaultBranch, results[i].State); err != nil {
log.Error("updateCommitStatusCache[%d:%s] failed: %v", repo.ID, repo.DefaultBranch, err)
}
diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue
index d6b7d6c96f..825803d939 100644
--- a/web_src/js/components/DashboardRepoList.vue
+++ b/web_src/js/components/DashboardRepoList.vue
@@ -251,9 +251,8 @@ const sfc = {
this.repos = json.data.map((webSearchRepo) => {
return {
...webSearchRepo.repository,
- latest_commit_status_state: webSearchRepo.latest_commit_status.State,
- locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status,
- latest_commit_status_state_link: webSearchRepo.latest_commit_status.TargetURL
+ latest_commit_status: webSearchRepo.latest_commit_status,
+ locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status
};
});
const count = response.headers.get('X-Total-Count');
@@ -416,9 +415,9 @@ export default sfc; // activate the IDE's Vue plugin
-
+
-
+