From 9b1da2eb6c35a0643d54b9377d0af80da5db4c8e Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 13 Feb 2023 12:01:21 +0100 Subject: [PATCH 01/11] Fix hidden commit status on multiple checks --- templates/repo/commit_statuses.tmpl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 4fe644ff0a4a6..19ea2ce8f41da 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,4 +1,15 @@ -{{if eq (len .Statuses) 1}}{{$status := index .Statuses 0}}{{if $status.TargetURL}}{{template "repo/commit_status" .Status}}{{end}}{{end}} + + {{if eq (len .Statuses) 1}} + {{$status := index .Statuses 0}} + {{if $status.TargetURL}} + {{template "repo/commit_status" .Status}} + {{else}} + {{template "repo/commit_status" .Status}} + {{end}} + {{else}} + {{template "repo/commit_status" .Status}} + {{end}} +
{{range .Statuses}} From 6b77ac5f4ac227513a868476a84315c765ff9c16 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 13 Feb 2023 13:11:11 +0100 Subject: [PATCH 02/11] fix test --- tests/integration/repo_commits_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index cbd83c6deb174..f0ada47bdd49b 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -59,7 +59,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { doc = NewHTMLParser(t, resp.Body) // Check if commit status is displayed in message column - sel := doc.doc.Find("#commits-table tbody tr td.message a.commit-statuses-trigger .commit-status") + sel := doc.doc.Find("#commits-table tbody tr td.message .commit-statuses-trigger .commit-status") assert.Equal(t, 1, sel.Length()) for _, class := range classes { assert.True(t, sel.HasClass(class)) From 14ae6fc9291b17b1612087f4a5a415681dd7f288 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 13 Feb 2023 13:26:25 +0100 Subject: [PATCH 03/11] add test for multiple statuses --- tests/integration/git_test.go | 15 +++++-- tests/integration/pull_status_test.go | 30 +++++++++----- tests/integration/repo_commits_test.go | 54 +++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go index 420a8676b9ed6..d21f3994a1d98 100644 --- a/tests/integration/git_test.go +++ b/tests/integration/git_test.go @@ -630,8 +630,17 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { commitID := path.Base(commitURL) + addCommitStatus := func(status api.CommitStatusState) func(*testing.T) { + return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{ + State: status, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + }) + } + // Call API to add Pending status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusPending)) + t.Run("CreateStatus", addCommitStatus(api.CommitStatusPending)) // Cancel not existing auto merge ctx.ExpectedCode = http.StatusNotFound @@ -660,7 +669,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { assert.False(t, pr.HasMerged) // Call API to add Failure status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusFailure)) + t.Run("CreateStatus", addCommitStatus(api.CommitStatusFailure)) // Check pr status pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t) @@ -668,7 +677,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { assert.False(t, pr.HasMerged) // Call API to add Success status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusSuccess)) + t.Run("CreateStatus", addCommitStatus(api.CommitStatusSuccess)) // wait to let gitea merge stuff time.Sleep(time.Second) diff --git a/tests/integration/pull_status_test.go b/tests/integration/pull_status_test.go index e60d17edc02ca..b493fdb72ae11 100644 --- a/tests/integration/pull_status_test.go +++ b/tests/integration/pull_status_test.go @@ -70,7 +70,12 @@ func TestPullCreate_CommitStatus(t *testing.T) { for _, status := range statusList { // Call API to add status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, status)) + t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, api.CreateStatusOption{ + State: status, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + })) req = NewRequestf(t, "GET", "/user1/repo1/pulls/1/commits") resp = session.MakeRequest(t, req, http.StatusOK) @@ -88,15 +93,22 @@ func TestPullCreate_CommitStatus(t *testing.T) { }) } -func doAPICreateCommitStatus(ctx APITestContext, commitID string, status api.CommitStatusState) func(*testing.T) { +func doAPICreateCommitStatusDefault(ctx APITestContext, commitID string, status api.CommitStatusState) func(*testing.T) { + return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{ + State: status, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + }) +} + +func doAPICreateCommitStatus(ctx APITestContext, commitID string, data api.CreateStatusOption) func(*testing.T) { return func(t *testing.T) { - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token), - api.CreateStatusOption{ - State: status, - TargetURL: "http://test.ci/", - Description: "", - Context: "testci", - }, + req := NewRequestWithJSON( + t, + http.MethodPost, + fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token), + data, ) if ctx.ExpectedCode != 0 { ctx.Session.MakeRequest(t, req, ctx.ExpectedCode) diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index f0ada47bdd49b..0ebef9c7ced61 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -52,7 +52,12 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { // Call API to add status for commit ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo) - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState(state))) + t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusState(state), + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + })) req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master") resp = session.MakeRequest(t, req, http.StatusOK) @@ -145,7 +150,12 @@ func TestRepoCommitsStatusParallel(t *testing.T) { go func(parentT *testing.T, i int) { parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) { ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepoStatus) - runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState("pending")) + runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusPending, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + }) runBody(t) wg.Done() }) @@ -153,3 +163,43 @@ func TestRepoCommitsStatusParallel(t *testing.T) { } wg.Wait() } + +func TestRepoCommitsStatusMultiple(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + + // Request repository commits page + req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master") + resp := session.MakeRequest(t, req, http.StatusOK) + + doc := NewHTMLParser(t, resp.Body) + // Get first commit URL + commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href") + assert.True(t, exists) + assert.NotEmpty(t, commitURL) + + // Call API to add status for commit + ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo) + t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusSuccess, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + })) + + t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusSuccess, + TargetURL: "http://test.ci/", + Description: "", + Context: "other_context", + })) + + req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master") + resp = session.MakeRequest(t, req, http.StatusOK) + + doc = NewHTMLParser(t, resp.Body) + // Check that the commit-statuses-trigger (for tooltip) and commit-status (svg) are present + sel := doc.doc.Find("#commits-table tbody tr td.message .commit-statuses-trigger .commit-status") + assert.Equal(t, 1, sel.Length()) +} From bcee39d75d6915591656c5f06d62794a256edb61 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 13 Feb 2023 13:27:31 +0100 Subject: [PATCH 04/11] remove useless function --- tests/integration/pull_status_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/integration/pull_status_test.go b/tests/integration/pull_status_test.go index b493fdb72ae11..736d1ee4f0eec 100644 --- a/tests/integration/pull_status_test.go +++ b/tests/integration/pull_status_test.go @@ -93,15 +93,6 @@ func TestPullCreate_CommitStatus(t *testing.T) { }) } -func doAPICreateCommitStatusDefault(ctx APITestContext, commitID string, status api.CommitStatusState) func(*testing.T) { - return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{ - State: status, - TargetURL: "http://test.ci/", - Description: "", - Context: "testci", - }) -} - func doAPICreateCommitStatus(ctx APITestContext, commitID string, data api.CreateStatusOption) func(*testing.T) { return func(t *testing.T) { req := NewRequestWithJSON( From c0cdb1b93c12591d72096ba5cf90c033c810c060 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 13 Feb 2023 13:32:40 +0100 Subject: [PATCH 05/11] skip status HTML when no status is present --- templates/repo/commit_statuses.tmpl | 44 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 19ea2ce8f41da..2c873b33562ef 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,25 +1,27 @@ - - {{if eq (len .Statuses) 1}} - {{$status := index .Statuses 0}} - {{if $status.TargetURL}} - {{template "repo/commit_status" .Status}} +{{ if .Statuses }} + + {{if eq (len .Statuses) 1}} + {{$status := index .Statuses 0}} + {{if $status.TargetURL}} + {{template "repo/commit_status" .Status}} + {{else}} + {{template "repo/commit_status" .Status}} + {{end}} {{else}} {{template "repo/commit_status" .Status}} {{end}} - {{else}} - {{template "repo/commit_status" .Status}} - {{end}} - -
-
- {{range .Statuses}} -
- {{template "repo/commit_status" .}} - {{.Context}} {{.Description}} - {{if .TargetURL}} - {{$.root.locale.Tr "repo.pulls.status_checks_details"}} - {{end}} -
- {{end}} + +
+
+ {{range .Statuses}} +
+ {{template "repo/commit_status" .}} + {{.Context}} {{.Description}} + {{if .TargetURL}} + {{$.root.locale.Tr "repo.pulls.status_checks_details"}} + {{end}} +
+ {{end}} +
-
+{{ end }} \ No newline at end of file From e473192a388e97b6db6e399d26e39df0ac108b75 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 13 Feb 2023 13:55:38 +0100 Subject: [PATCH 06/11] make fmt --- templates/repo/commit_statuses.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 2c873b33562ef..008505dafcd1c 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,4 +1,4 @@ -{{ if .Statuses }} +{{if .Statuses}} {{if eq (len .Statuses) 1}} {{$status := index .Statuses 0}} @@ -24,4 +24,4 @@ {{end}}
-{{ end }} \ No newline at end of file +{{end}} \ No newline at end of file From 21f7f2c37fc60b2919cc0a96e8b5c91a7434a826 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 13 Feb 2023 14:01:29 +0100 Subject: [PATCH 07/11] add endline --- templates/repo/commit_statuses.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 008505dafcd1c..9906ab5f54ae1 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -24,4 +24,4 @@ {{end}}
-{{end}} \ No newline at end of file +{{end}} From 6db8fb37400c14131235c27f7aaad36455600501 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Fri, 17 Feb 2023 10:31:25 +0100 Subject: [PATCH 08/11] tippy: use data attr for commit-status --- templates/repo/commit_statuses.tmpl | 26 ++++++++++++-------------- tests/integration/repo_commits_test.go | 8 ++++---- web_src/js/features/repo-commit.js | 2 +- web_src/less/_base.less | 3 +-- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index f1c50aef60efb..820f39598eda5 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,9 +1,9 @@ {{if .Statuses}} - + {{if eq (len .Statuses) 1}} {{$status := index .Statuses 0}} {{if $status.TargetURL}} - {{template "repo/commit_status" .Status}} + {{template "repo/commit_status" .Status}} {{else}} {{template "repo/commit_status" .Status}} {{end}} @@ -11,17 +11,15 @@ {{template "repo/commit_status" .Status}} {{end}} -
-
- {{range .Statuses}} -
- {{template "repo/commit_status" .}} - {{.Context}} {{.Description}} - {{if .TargetURL}} - {{$.root.locale.Tr "repo.pulls.status_checks_details"}} - {{end}} -
- {{end}} -
+
+ {{range .Statuses}} +
+ {{template "repo/commit_status" .}} + {{.Context}} {{.Description}} + {{if .TargetURL}} + {{$.root.locale.Tr "repo.pulls.status_checks_details"}} + {{end}} +
+ {{end}}
{{end}} diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index 0ebef9c7ced61..e74e3867f4af9 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -63,8 +63,8 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { resp = session.MakeRequest(t, req, http.StatusOK) doc = NewHTMLParser(t, resp.Body) - // Check if commit status is displayed in message column - sel := doc.doc.Find("#commits-table tbody tr td.message .commit-statuses-trigger .commit-status") + // Check if commit status is displayed in message column (.tippy-target to ignore the tippy trigger) + sel := doc.doc.Find("#commits-table tbody tr td.message .tippy-target .commit-status") assert.Equal(t, 1, sel.Length()) for _, class := range classes { assert.True(t, sel.HasClass(class)) @@ -199,7 +199,7 @@ func TestRepoCommitsStatusMultiple(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) doc = NewHTMLParser(t, resp.Body) - // Check that the commit-statuses-trigger (for tooltip) and commit-status (svg) are present - sel := doc.doc.Find("#commits-table tbody tr td.message .commit-statuses-trigger .commit-status") + // Check that the data-tippy="commit-statuses" (for trigger) and commit-status (svg) are present + sel := doc.doc.Find("#commits-table tbody tr td.message [data-tippy=\"commit-statuses\"] .commit-status") assert.Equal(t, 1, sel.Length()) } diff --git a/web_src/js/features/repo-commit.js b/web_src/js/features/repo-commit.js index 3aba85091124e..33ce0673ac097 100644 --- a/web_src/js/features/repo-commit.js +++ b/web_src/js/features/repo-commit.js @@ -57,7 +57,7 @@ export function initRepoCommitLastCommitLoader() { } export function initCommitStatuses() { - $('.commit-statuses-trigger').each(function () { + $('[data-tippy="commit-statuses"]').each(function () { const top = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0; createTippy(this, { diff --git a/web_src/less/_base.less b/web_src/less/_base.less index 4b65ae6812a01..3c8830820e24a 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -340,8 +340,7 @@ a.label, .ui.search .results a, .ui .menu a, .ui.cards a.card, -.issue-keyword a, -a.commit-statuses-trigger { +.issue-keyword a { text-decoration: none !important; } From 9ca16b73cc929a926b88badb583702509a6b2302 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Fri, 17 Feb 2023 10:37:46 +0100 Subject: [PATCH 09/11] delete unused css --- web_src/less/_repository.less | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 39362722de535..18213a58dcd82 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -1,28 +1,4 @@ .repository { - .popup.commit-statuses { - // we had better limit the max size of the popup, and add scroll bars if the content size is too large. - // otherwise some part of the popup will be hidden by viewport boundary - max-height: 45vh; - max-width: 60vw; - - &.ui.right { - // Override `.ui.attached.header .right:not(.dropdown) height: 30px;` which would otherwise lead to - // the status popup box having its height fixed at 30px. See https://github.com/go-gitea/gitea/issues/18498 - height: auto; - } - - overflow: auto; - padding: 0; - - .list { - padding: .8em; // to make the scrollbar align to the border, we move the padding from outer `.popup` to this inside `.list` - - > .item { - line-height: 2; - } - } - } - .repo-header { .ui.compact.menu { margin-left: 1rem; From 793b6d8ceede00559a28410c2e282b4a9285ab72 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Fri, 17 Feb 2023 10:57:50 +0100 Subject: [PATCH 10/11] nicer if/else --- templates/repo/commit_statuses.tmpl | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 820f39598eda5..17c68f3f04b6d 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,16 +1,11 @@ {{if .Statuses}} - - {{if eq (len .Statuses) 1}} - {{$status := index .Statuses 0}} - {{if $status.TargetURL}} - {{template "repo/commit_status" .Status}} - {{else}} - {{template "repo/commit_status" .Status}} - {{end}} - {{else}} + {{if and (eq (len .Statuses) 1) .Status.TargetURL}} + {{template "repo/commit_status" .Status}} + {{else}} + {{template "repo/commit_status" .Status}} - {{end}} - + + {{end}}
{{range .Statuses}}
From 4734aeb03c72bb2bd49bf82e3d5564f1be603562 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Fri, 17 Feb 2023 11:03:35 +0100 Subject: [PATCH 11/11] nicer indentation --- templates/repo/commit_statuses.tmpl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 17c68f3f04b6d..8858fb8402129 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,6 +1,8 @@ {{if .Statuses}} {{if and (eq (len .Statuses) 1) .Status.TargetURL}} - {{template "repo/commit_status" .Status}} + + {{template "repo/commit_status" .Status}} + {{else}} {{template "repo/commit_status" .Status}}