Skip to content

Commit f6e7798

Browse files
authored
Add link to job details and tooltip to commit status in repo list in dashboard (#26326)
Tooltip: ![image](https://github.com/go-gitea/gitea/assets/18380374/237cb545-7844-424b-b995-1008eaaaedec) Link to the target job: ![image](https://github.com/go-gitea/gitea/assets/18380374/0c11a97f-6517-47f2-8773-f381488c084e)
1 parent 3be80a8 commit f6e7798

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

models/git/commit_status.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"code.gitea.io/gitea/modules/setting"
2323
api "code.gitea.io/gitea/modules/structs"
2424
"code.gitea.io/gitea/modules/timeutil"
25+
"code.gitea.io/gitea/modules/translation"
2526

2627
"xorm.io/builder"
2728
"xorm.io/xorm"
@@ -191,6 +192,11 @@ func (status *CommitStatus) APIURL(ctx context.Context) string {
191192
return status.Repo.APIURL() + "/statuses/" + url.PathEscape(status.SHA)
192193
}
193194

195+
// LocaleString returns the locale string name of the Status
196+
func (status *CommitStatus) LocaleString(lang translation.Locale) string {
197+
return lang.Tr("repo.commitstatus." + status.State.String())
198+
}
199+
194200
// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
195201
func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus {
196202
var lastStatus *CommitStatus

modules/structs/commit_status.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var commitStatusPriorities = map[CommitStatusState]int{
2525
CommitStatusSuccess: 3,
2626
}
2727

28+
func (css CommitStatusState) String() string {
29+
return string(css)
30+
}
31+
2832
// NoBetterThan returns true if this State is no better than the given State
2933
// This function only handles the states defined in CommitStatusPriorities
3034
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {

options/locale/locale_en-US.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,11 @@ commit.cherry-pick = Cherry-pick
12801280
commit.cherry-pick-header = Cherry-pick: %s
12811281
commit.cherry-pick-content = Select branch to cherry-pick onto:
12821282
1283+
commitstatus.error = Error
1284+
commitstatus.failure = Failure
1285+
commitstatus.pending = Pending
1286+
commitstatus.success = Success
1287+
12831288
ext_issues = Access to External Issues
12841289
ext_issues.desc = Link to an external issue tracker.
12851290

routers/web/repo/repo.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ func SearchRepo(ctx *context.Context) {
600600

601601
results := make([]*repo_service.WebSearchRepository, len(repos))
602602
for i, repo := range repos {
603+
latestCommitStatus := git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
604+
603605
results[i] = &repo_service.WebSearchRepository{
604606
Repository: &api.Repository{
605607
ID: repo.ID,
@@ -613,7 +615,8 @@ func SearchRepo(ctx *context.Context) {
613615
Link: repo.Link(),
614616
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
615617
},
616-
LatestCommitStatus: git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID]),
618+
LatestCommitStatus: latestCommitStatus,
619+
LocaleLatestCommitStatus: latestCommitStatus.LocaleString(ctx.Locale),
617620
}
618621
}
619622

services/repository/repository.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ import (
2828

2929
// WebSearchRepository represents a repository returned by web search
3030
type WebSearchRepository struct {
31-
Repository *structs.Repository `json:"repository"`
32-
LatestCommitStatus *git.CommitStatus `json:"latest_commit_status"`
31+
Repository *structs.Repository `json:"repository"`
32+
LatestCommitStatus *git.CommitStatus `json:"latest_commit_status"`
33+
LocaleLatestCommitStatus string `json:"locale_latest_commit_status"`
3334
}
3435

3536
// WebSearchResults results of a successful web search

web_src/js/components/DashboardRepoList.vue

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,18 @@
6969
</div>
7070
<div v-if="repos.length" class="ui attached table segment gt-rounded-bottom">
7171
<ul class="repo-owner-name-list">
72-
<li class="gt-df gt-ac" v-for="repo, index in repos" :class="{'active': index === activeIndex}" :key="repo.id">
73-
<a class="repo-list-link muted gt-df gt-ac gt-f1" :href="repo.link">
72+
<li class="gt-df gt-ac gt-py-3" v-for="repo, index in repos" :class="{'active': index === activeIndex}" :key="repo.id">
73+
<a class="repo-list-link muted gt-df gt-ac gt-f1 gt-gap-3" :href="repo.link">
7474
<svg-icon :name="repoIcon(repo)" :size="16" class-name="repo-list-icon"/>
7575
<div class="text truncate">{{ repo.full_name }}</div>
7676
<div v-if="repo.archived">
7777
<svg-icon name="octicon-archive" :size="16"/>
7878
</div>
7979
</a>
80-
<!-- the commit status icon logic is taken from templates/repo/commit_status.tmpl -->
81-
<svg-icon v-if="repo.latest_commit_status_state" :name="statusIcon(repo.latest_commit_status_state)" :class-name="'gt-ml-3 commit-status icon text ' + statusColor(repo.latest_commit_status_state)" :size="16"/>
80+
<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">
81+
<!-- the commit status icon logic is taken from templates/repo/commit_status.tmpl -->
82+
<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"/>
83+
</a>
8284
</li>
8385
</ul>
8486
<div v-if="showMoreReposLink" class="center gt-py-3 gt-border-secondary-top">
@@ -394,7 +396,14 @@ const sfc = {
394396
}
395397
396398
if (searchedURL === this.searchURL) {
397-
this.repos = json.data.map((webSearchRepo) => {return {...webSearchRepo.repository, latest_commit_status_state: webSearchRepo.latest_commit_status.State}});
399+
this.repos = json.data.map((webSearchRepo) => {
400+
return {
401+
...webSearchRepo.repository,
402+
latest_commit_status_state: webSearchRepo.latest_commit_status.State,
403+
locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status,
404+
latest_commit_status_state_link: webSearchRepo.latest_commit_status.TargetURL
405+
};
406+
});
398407
const count = response.headers.get('X-Total-Count');
399408
if (searchedQuery === '' && searchedMode === '' && this.archivedFilter === 'both') {
400409
this.reposTotalCount = count;
@@ -494,8 +503,6 @@ ul li:not(:last-child) {
494503
}
495504
496505
.repo-list-link {
497-
padding: 6px 0;
498-
gap: 6px;
499506
min-width: 0; /* for text truncation */
500507
}
501508

0 commit comments

Comments
 (0)