Skip to content

Commit 3596df5

Browse files
oliverpoollunny
andauthored
Fix hidden commit status on multiple checks (#22889)
Since #22632, when a commit status has multiple checks, no check is shown at all (hence no way to see the other checks). This PR fixes this by always adding a tag with the `.commit-statuses-trigger` to the DOM (the `.vm` is for vertical alignment). ![2023-02-13-120528](https://user-images.githubusercontent.com/3864879/218441846-1a79c169-2efd-46bb-9e75-d8b45d7cc8e3.png) --------- Co-authored-by: Lunny Xiao <[email protected]>
1 parent 1d64eaf commit 3596df5

File tree

7 files changed

+92
-47
lines changed

7 files changed

+92
-47
lines changed

templates/repo/commit_statuses.tmpl

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
{{if eq (len .Statuses) 1}}{{$status := index .Statuses 0}}{{if $status.TargetURL}}<a class="ui link commit-statuses-trigger gt-vm" href="{{$status.TargetURL}}">{{template "repo/commit_status" .Status}}</a>{{end}}{{end}}
2-
<div class="ui commit-statuses-popup commit-statuses tippy-target">
3-
<div class="ui relaxed list divided">
1+
{{if .Statuses}}
2+
{{if and (eq (len .Statuses) 1) .Status.TargetURL}}
3+
<a class="gt-vm gt-tdn" data-tippy="commit-statuses" href="{{.Status.TargetURL}}">
4+
{{template "repo/commit_status" .Status}}
5+
</a>
6+
{{else}}
7+
<span class="gt-vm" data-tippy="commit-statuses" tabindex="0">
8+
{{template "repo/commit_status" .Status}}
9+
</span>
10+
{{end}}
11+
<div class="tippy-target ui relaxed list divided">
412
{{range .Statuses}}
513
<div class="ui item singular-status gt-df">
614
{{template "repo/commit_status" .}}
@@ -11,4 +19,4 @@
1119
</div>
1220
{{end}}
1321
</div>
14-
</div>
22+
{{end}}

tests/integration/git_test.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,17 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
630630

631631
commitID := path.Base(commitURL)
632632

633+
addCommitStatus := func(status api.CommitStatusState) func(*testing.T) {
634+
return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{
635+
State: status,
636+
TargetURL: "http://test.ci/",
637+
Description: "",
638+
Context: "testci",
639+
})
640+
}
641+
633642
// Call API to add Pending status for commit
634-
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusPending))
643+
t.Run("CreateStatus", addCommitStatus(api.CommitStatusPending))
635644

636645
// Cancel not existing auto merge
637646
ctx.ExpectedCode = http.StatusNotFound
@@ -660,15 +669,15 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
660669
assert.False(t, pr.HasMerged)
661670

662671
// Call API to add Failure status for commit
663-
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusFailure))
672+
t.Run("CreateStatus", addCommitStatus(api.CommitStatusFailure))
664673

665674
// Check pr status
666675
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
667676
assert.NoError(t, err)
668677
assert.False(t, pr.HasMerged)
669678

670679
// Call API to add Success status for commit
671-
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusSuccess))
680+
t.Run("CreateStatus", addCommitStatus(api.CommitStatusSuccess))
672681

673682
// wait to let gitea merge stuff
674683
time.Sleep(time.Second)

tests/integration/pull_status_test.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ func TestPullCreate_CommitStatus(t *testing.T) {
7070
for _, status := range statusList {
7171

7272
// Call API to add status for commit
73-
t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, status))
73+
t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, api.CreateStatusOption{
74+
State: status,
75+
TargetURL: "http://test.ci/",
76+
Description: "",
77+
Context: "testci",
78+
}))
7479

7580
req = NewRequestf(t, "GET", "/user1/repo1/pulls/1/commits")
7681
resp = session.MakeRequest(t, req, http.StatusOK)
@@ -88,15 +93,13 @@ func TestPullCreate_CommitStatus(t *testing.T) {
8893
})
8994
}
9095

91-
func doAPICreateCommitStatus(ctx APITestContext, commitID string, status api.CommitStatusState) func(*testing.T) {
96+
func doAPICreateCommitStatus(ctx APITestContext, commitID string, data api.CreateStatusOption) func(*testing.T) {
9297
return func(t *testing.T) {
93-
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token),
94-
api.CreateStatusOption{
95-
State: status,
96-
TargetURL: "http://test.ci/",
97-
Description: "",
98-
Context: "testci",
99-
},
98+
req := NewRequestWithJSON(
99+
t,
100+
http.MethodPost,
101+
fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token),
102+
data,
100103
)
101104
if ctx.ExpectedCode != 0 {
102105
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)

tests/integration/repo_commits_test.go

+54-4
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
5252

5353
// Call API to add status for commit
5454
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo)
55-
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState(state)))
55+
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
56+
State: api.CommitStatusState(state),
57+
TargetURL: "http://test.ci/",
58+
Description: "",
59+
Context: "testci",
60+
}))
5661

5762
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
5863
resp = session.MakeRequest(t, req, http.StatusOK)
5964

6065
doc = NewHTMLParser(t, resp.Body)
61-
// Check if commit status is displayed in message column
62-
sel := doc.doc.Find("#commits-table tbody tr td.message a.commit-statuses-trigger .commit-status")
66+
// Check if commit status is displayed in message column (.tippy-target to ignore the tippy trigger)
67+
sel := doc.doc.Find("#commits-table tbody tr td.message .tippy-target .commit-status")
6368
assert.Equal(t, 1, sel.Length())
6469
for _, class := range classes {
6570
assert.True(t, sel.HasClass(class))
@@ -145,11 +150,56 @@ func TestRepoCommitsStatusParallel(t *testing.T) {
145150
go func(parentT *testing.T, i int) {
146151
parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) {
147152
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepoStatus)
148-
runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState("pending"))
153+
runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
154+
State: api.CommitStatusPending,
155+
TargetURL: "http://test.ci/",
156+
Description: "",
157+
Context: "testci",
158+
})
149159
runBody(t)
150160
wg.Done()
151161
})
152162
}(t, i)
153163
}
154164
wg.Wait()
155165
}
166+
167+
func TestRepoCommitsStatusMultiple(t *testing.T) {
168+
defer tests.PrepareTestEnv(t)()
169+
170+
session := loginUser(t, "user2")
171+
172+
// Request repository commits page
173+
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
174+
resp := session.MakeRequest(t, req, http.StatusOK)
175+
176+
doc := NewHTMLParser(t, resp.Body)
177+
// Get first commit URL
178+
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
179+
assert.True(t, exists)
180+
assert.NotEmpty(t, commitURL)
181+
182+
// Call API to add status for commit
183+
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo)
184+
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
185+
State: api.CommitStatusSuccess,
186+
TargetURL: "http://test.ci/",
187+
Description: "",
188+
Context: "testci",
189+
}))
190+
191+
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
192+
State: api.CommitStatusSuccess,
193+
TargetURL: "http://test.ci/",
194+
Description: "",
195+
Context: "other_context",
196+
}))
197+
198+
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
199+
resp = session.MakeRequest(t, req, http.StatusOK)
200+
201+
doc = NewHTMLParser(t, resp.Body)
202+
// Check that the data-tippy="commit-statuses" (for trigger) and commit-status (svg) are present
203+
sel := doc.doc.Find("#commits-table tbody tr td.message [data-tippy=\"commit-statuses\"] .commit-status")
204+
assert.Equal(t, 1, sel.Length())
205+
}

web_src/js/features/repo-commit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function initRepoCommitLastCommitLoader() {
5858
}
5959

6060
export function initCommitStatuses() {
61-
$('.commit-statuses-trigger').each(function () {
61+
$('[data-tippy="commit-statuses"]').each(function () {
6262
const top = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0;
6363

6464
createTippy(this, {

web_src/less/_base.less

+1-2
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ a.label,
340340
.ui.search .results a,
341341
.ui .menu a,
342342
.ui.cards a.card,
343-
.issue-keyword a,
344-
a.commit-statuses-trigger {
343+
.issue-keyword a {
345344
text-decoration: none !important;
346345
}
347346

web_src/less/_repository.less

-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,4 @@
11
.repository {
2-
.popup.commit-statuses {
3-
// we had better limit the max size of the popup, and add scroll bars if the content size is too large.
4-
// otherwise some part of the popup will be hidden by viewport boundary
5-
max-height: 45vh;
6-
max-width: 60vw;
7-
8-
&.ui.right {
9-
// Override `.ui.attached.header .right:not(.dropdown) height: 30px;` which would otherwise lead to
10-
// the status popup box having its height fixed at 30px. See https://github.com/go-gitea/gitea/issues/18498
11-
height: auto;
12-
}
13-
14-
overflow: auto;
15-
padding: 0;
16-
17-
.list {
18-
padding: .8em; // to make the scrollbar align to the border, we move the padding from outer `.popup` to this inside `.list`
19-
20-
> .item {
21-
line-height: 2;
22-
}
23-
}
24-
}
25-
262
.repo-header {
273
.ui.compact.menu {
284
margin-left: 1rem;

0 commit comments

Comments
 (0)