mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 17:14:06 +01:00
fix commit_status
This commit is contained in:
parent
2536c2db89
commit
3b7b899afa
5 changed files with 23 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -65,7 +65,7 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
|
|||
if status != nil {
|
||||
return status.State
|
||||
}
|
||||
return structs.CommitStatusSuccess
|
||||
return ""
|
||||
}
|
||||
|
||||
return returnedStatus
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
|||
<svg-icon name="octicon-archive" :size="16"/>
|
||||
</div>
|
||||
</a>
|
||||
<a class="gt-df gt-ac" v-if="repo.latest_commit_status_state" :href="repo.latest_commit_status_state_link" :data-tooltip-content="repo.locale_latest_commit_status_state">
|
||||
<a class="gt-df gt-ac" v-if="repo.latest_commit_status" :href="repo.latest_commit_status.TargetLink" :data-tooltip-content="repo.locale_latest_commit_status.State">
|
||||
<!-- the commit status icon logic is taken from templates/repo/commit_status.tmpl -->
|
||||
<svg-icon :name="statusIcon(repo.latest_commit_status_state)" :class-name="'gt-ml-3 commit-status icon text ' + statusColor(repo.latest_commit_status_state)" :size="16"/>
|
||||
<svg-icon :name="statusIcon(repo.latest_commit_status.State)" :class-name="'gt-ml-3 commit-status icon text ' + statusColor(repo.latest_commit_status.State)" :size="16"/>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue