Skip to content

Commit e9392c1

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: If a repository return no commitstatus, then still cache it but not query it from database (go-gitea#30700) [skip ci] Updated translations via Crowdin Fix view of readme file in the home code page. (go-gitea#30564) Add test for go-gitea#30674 (go-gitea#30679) Fix border-radius of header+segment boxes (go-gitea#30667)
2 parents 4b88f93 + c685eef commit e9392c1

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

options/locale/locale_pt-PT.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ manage_themes=Escolher o tema padrão
763763
manage_openid=Gerir endereços OpenID
764764
email_desc=O seu endereço de email principal irá ser usado para notificações, recuperação de senha e, desde que não esteja oculto, operações Git baseados na web.
765765
theme_desc=Este será o seu tema padrão em todo o sítio.
766+
theme_colorblindness_help=Suporte a temas para daltónicos
767+
theme_colorblindness_prompt=O Gitea acabou de obter alguns temas com suporte básico para daltónicos que têm apenas algumas cores definidas. O trabalho ainda está em andamento. Poderiam ser feitos mais melhoramentos se fossem definidas mais cores nos ficheiros CSS do tema.
766768
primary=Principal
767769
activated=Em uso
768770
requires_activation=Tem que ser habilitado

services/repository/commitstatus/commitstatus.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ func getCommitStatusCache(repoID int64, branchName string) *commitStatusCacheVal
3838
if ok && statusStr != "" {
3939
var cv commitStatusCacheValue
4040
err := json.Unmarshal([]byte(statusStr), &cv)
41-
if err == nil && cv.State != "" {
41+
if err == nil {
4242
return &cv
4343
}
44-
if err != nil {
45-
log.Warn("getCommitStatusCache: json.Unmarshal failed: %v", err)
46-
}
44+
log.Warn("getCommitStatusCache: json.Unmarshal failed: %v", err)
4745
}
4846
return nil
4947
}
@@ -128,15 +126,22 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
128126
// FindReposLastestCommitStatuses loading repository default branch latest combinded commit status with cache
129127
func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Repository) ([]*git_model.CommitStatus, error) {
130128
results := make([]*git_model.CommitStatus, len(repos))
129+
allCached := true
131130
for i, repo := range repos {
132131
if cv := getCommitStatusCache(repo.ID, repo.DefaultBranch); cv != nil {
133132
results[i] = &git_model.CommitStatus{
134133
State: api.CommitStatusState(cv.State),
135134
TargetURL: cv.TargetURL,
136135
}
136+
} else {
137+
allCached = false
137138
}
138139
}
139140

141+
if allCached {
142+
return results, nil
143+
}
144+
140145
// collect the latest commit of each repo
141146
// at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
142147
repoBranchNames := make(map[int64]string, len(repos))
@@ -165,10 +170,10 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep
165170
for i, repo := range repos {
166171
if repo.ID == summary.RepoID {
167172
results[i] = summary
168-
_ = slices.DeleteFunc(repoSHAs, func(repoSHA git_model.RepoSHA) bool {
173+
repoSHAs = slices.DeleteFunc(repoSHAs, func(repoSHA git_model.RepoSHA) bool {
169174
return repoSHA.RepoID == repo.ID
170175
})
171-
if results[i].State != "" {
176+
if results[i] != nil {
172177
if err := updateCommitStatusCache(repo.ID, repo.DefaultBranch, results[i].State, results[i].TargetURL); err != nil {
173178
log.Error("updateCommitStatusCache[%d:%s] failed: %v", repo.ID, repo.DefaultBranch, err)
174179
}
@@ -177,6 +182,9 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep
177182
}
178183
}
179184
}
185+
if len(repoSHAs) == 0 {
186+
return results, nil
187+
}
180188

181189
// call the database O(1) times to get the commit statuses for all repos
182190
repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoSHAs)
@@ -187,7 +195,7 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep
187195
for i, repo := range repos {
188196
if results[i] == nil {
189197
results[i] = git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
190-
if results[i].State != "" {
198+
if results[i] != nil {
191199
if err := updateCommitStatusCache(repo.ID, repo.DefaultBranch, results[i].State, results[i].TargetURL); err != nil {
192200
log.Error("updateCommitStatusCache[%d:%s] failed: %v", repo.ID, repo.DefaultBranch, err)
193201
}

templates/repo/view_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@
6868
{{end}}
6969
</tbody>
7070
</table>
71-
{{if .ReadmeExist}}
71+
{{if and .ReadmeExist (or .IsMarkup .IsPlainText)}}
7272
{{template "repo/view_file" .}}
7373
{{end}}

tests/integration/pull_compare_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ package integration
55

66
import (
77
"net/http"
8+
"net/url"
89
"testing"
910

11+
"code.gitea.io/gitea/models/db"
12+
repo_model "code.gitea.io/gitea/models/repo"
13+
"code.gitea.io/gitea/models/unittest"
14+
user_model "code.gitea.io/gitea/models/user"
15+
repo_service "code.gitea.io/gitea/services/repository"
1016
"code.gitea.io/gitea/tests"
1117

1218
"github.com/stretchr/testify/assert"
@@ -32,4 +38,33 @@ func TestPullCompare(t *testing.T) {
3238
doc := NewHTMLParser(t, resp.Body)
3339
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
3440
assert.Greater(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
41+
42+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
43+
defer tests.PrepareTestEnv(t)()
44+
45+
session := loginUser(t, "user1")
46+
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
47+
testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusSeeOther)
48+
testEditFile(t, session, "user1", "repo1", "master1", "README.md", "Hello, World (Edited)\n")
49+
resp = testPullCreate(t, session, "user1", "repo1", false, "master", "master1", "This is a pull title")
50+
51+
// the max value on issue_index.yml for repo_id=1 is 5
52+
req = NewRequest(t, "GET", "/user2/repo1/pulls/6/files")
53+
resp = session.MakeRequest(t, req, http.StatusOK)
54+
doc := NewHTMLParser(t, resp.Body)
55+
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
56+
assert.Greater(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
57+
58+
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
59+
repoForked := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1"})
60+
// delete the head repository and revisit the PR diff view
61+
err := repo_service.DeleteRepositoryDirectly(db.DefaultContext, user2, repoForked.ID)
62+
assert.NoError(t, err)
63+
64+
req = NewRequest(t, "GET", "/user2/repo1/pulls/6/files")
65+
resp = session.MakeRequest(t, req, http.StatusOK)
66+
doc = NewHTMLParser(t, resp.Body)
67+
editButtonCount = doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
68+
assert.EqualValues(t, editButtonCount, 0, "Expected not to find a button to edit a file in the PR diff view because head repository has been deleted")
69+
})
3570
}

web_src/css/modules/segment.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
border-top: none;
152152
}
153153

154+
.ui.attached.segment:has(+ .ui[class*="top attached"].header),
155+
.ui.attached.segment:last-child {
156+
border-radius: 0 0 0.28571429rem 0.28571429rem;
157+
}
158+
154159
.ui[class*="top attached"].segment {
155160
bottom: 0;
156161
margin-bottom: 0;

0 commit comments

Comments
 (0)