1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-22 08:42:32 -05:00

fix commit_status

This commit is contained in:
oliverpool 2024-03-19 14:03:28 +01:00
parent 2536c2db89
commit 3b7b899afa
5 changed files with 23 additions and 21 deletions

View file

@ -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 // CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus { func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus {
var lastStatus *CommitStatus if len(statuses) == 0 {
state := api.CommitStatusSuccess return nil
for _, status := range statuses { }
if status.State.NoBetterThan(state) {
state = status.State latestWorstStatus := statuses[0]
lastStatus = status for _, status := range statuses[1:] {
if status.State.NoBetterThan(latestWorstStatus.State) {
latestWorstStatus = status
} }
} }
if lastStatus == nil { return latestWorstStatus
if len(statuses) > 0 {
lastStatus = statuses[0]
} else {
lastStatus = &CommitStatus{}
}
}
return lastStatus
} }
// CommitStatusOptions holds the options for query commit statuses // CommitStatusOptions holds the options for query commit statuses

View file

@ -141,16 +141,20 @@ func Test_CalcCommitStatus(t *testing.T) {
statuses: []*git_model.CommitStatus{ statuses: []*git_model.CommitStatus{
{ {
State: structs.CommitStatusSuccess, State: structs.CommitStatusSuccess,
ID: 1,
}, },
{ {
State: structs.CommitStatusSuccess, State: structs.CommitStatusSuccess,
ID: 2,
}, },
{ {
State: structs.CommitStatusSuccess, State: structs.CommitStatusSuccess,
ID: 3,
}, },
}, },
expected: &git_model.CommitStatus{ expected: &git_model.CommitStatus{
State: structs.CommitStatusSuccess, State: structs.CommitStatusSuccess,
ID: 3,
}, },
}, },
{ {
@ -169,6 +173,10 @@ func Test_CalcCommitStatus(t *testing.T) {
State: structs.CommitStatusError, State: structs.CommitStatusError,
}, },
}, },
{
statuses: []*git_model.CommitStatus{},
expected: nil,
},
} }
for _, kase := range kases { for _, kase := range kases {

View file

@ -65,7 +65,7 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
if status != nil { if status != nil {
return status.State return status.State
} }
return structs.CommitStatusSuccess return ""
} }
return returnedStatus return returnedStatus

View file

@ -123,7 +123,7 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep
for i, repo := range repos { for i, repo := range repos {
if results[i] == nil { if results[i] == nil {
results[i] = git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID]) 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 { 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) log.Error("updateCommitStatusCache[%d:%s] failed: %v", repo.ID, repo.DefaultBranch, err)
} }

View file

@ -251,9 +251,8 @@ const sfc = {
this.repos = json.data.map((webSearchRepo) => { this.repos = json.data.map((webSearchRepo) => {
return { return {
...webSearchRepo.repository, ...webSearchRepo.repository,
latest_commit_status_state: webSearchRepo.latest_commit_status.State, latest_commit_status: webSearchRepo.latest_commit_status,
locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status, locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status
latest_commit_status_state_link: webSearchRepo.latest_commit_status.TargetURL
}; };
}); });
const count = response.headers.get('X-Total-Count'); 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"/> <svg-icon name="octicon-archive" :size="16"/>
</div> </div>
</a> </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 --> <!-- 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> </a>
</li> </li>
</ul> </ul>