Skip to content

Commit f70786f

Browse files
authored
Merge branch 'main' into fix-test-dep
2 parents d554c81 + 9f664ab commit f70786f

File tree

10 files changed

+177
-7
lines changed

10 files changed

+177
-7
lines changed

models/actions/run.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ func (run *ActionRun) PrettyRef() string {
102102
return refName.ShortName()
103103
}
104104

105+
// RefTooltip return a tooltop of run's ref. For pull request, it's the title of the PR, otherwise it's the ShortName.
106+
func (run *ActionRun) RefTooltip() string {
107+
payload, err := run.GetPullRequestEventPayload()
108+
if err == nil && payload != nil && payload.PullRequest != nil {
109+
return payload.PullRequest.Title
110+
}
111+
return git.RefName(run.Ref).ShortName()
112+
}
113+
105114
// LoadAttributes load Repo TriggerUser if not loaded
106115
func (run *ActionRun) LoadAttributes(ctx context.Context) error {
107116
if run == nil {

models/issues/review_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func GetReviewsByIssueID(ctx context.Context, issueID int64) (latestReviews, mig
173173
reviewersMap := make(map[int64][]*Review) // key is reviewer id
174174
originalReviewersMap := make(map[int64][]*Review) // key is original author id
175175
reviewTeamsMap := make(map[int64][]*Review) // key is reviewer team id
176-
countedReivewTypes := []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest}
176+
countedReivewTypes := []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, ReviewTypeComment}
177177
for _, review := range reviews {
178178
if review.ReviewerTeamID == 0 && slices.Contains(countedReivewTypes, review.Type) && !review.Dismissed {
179179
if review.OriginalAuthorID != 0 {

models/issues/review_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,20 @@ func TestGetReviewersByIssueID(t *testing.T) {
122122
assert.NoError(t, unittest.PrepareTestDatabase())
123123

124124
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
125+
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
125126
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
126127
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
127128
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
128129
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
129130

130131
expectedReviews := []*issues_model.Review{}
131132
expectedReviews = append(expectedReviews,
133+
&issues_model.Review{
134+
ID: 5,
135+
Reviewer: user1,
136+
Type: issues_model.ReviewTypeComment,
137+
UpdatedUnix: 946684810,
138+
},
132139
&issues_model.Review{
133140
ID: 7,
134141
Reviewer: org3,
@@ -167,8 +174,9 @@ func TestGetReviewersByIssueID(t *testing.T) {
167174
for _, review := range allReviews {
168175
assert.NoError(t, review.LoadReviewer(t.Context()))
169176
}
170-
if assert.Len(t, allReviews, 5) {
177+
if assert.Len(t, allReviews, 6) {
171178
for i, review := range allReviews {
179+
assert.Equal(t, expectedReviews[i].ID, review.ID)
172180
assert.Equal(t, expectedReviews[i].Reviewer, review.Reviewer)
173181
assert.Equal(t, expectedReviews[i].Type, review.Type)
174182
assert.Equal(t, expectedReviews[i].UpdatedUnix, review.UpdatedUnix)

options/locale/locale_pt-BR.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,8 @@ settings=Configurações
20752075
settings.desc=Configurações é onde você pode gerenciar as opções para o repositório.
20762076
settings.options=Repositório
20772077
settings.public_access=Acesso Público
2078+
settings.public_access_desc=Configurar permissões de acesso do visitante público para substituir os padrões deste repositório.
2079+
settings.public_access.docs.not_set=Não definido: nenhuma permissão extra de acesso público. A permissão do visitante segue a visibilidade e as permissões de membro do repositório.
20782080
settings.collaboration=Colaboradores
20792081
settings.collaboration.admin=Administrador
20802082
settings.collaboration.write=Escrita
@@ -2760,6 +2762,11 @@ view_as_role=Ver como: %s
27602762
view_as_public_hint=Você está vendo o README como um usuário público.
27612763
view_as_member_hint=Você está vendo o README como um membro desta organização.
27622764

2765+
worktime.date_range_start=Data de início
2766+
worktime.date_range_end=Data de término
2767+
worktime.by_repositories=Por repositórios
2768+
worktime.by_milestones=Por marcos
2769+
worktime.by_members=Por membros
27632770

27642771
[admin]
27652772
maintenance=Manutenção
@@ -3371,6 +3378,7 @@ versions=Versões
33713378
versions.view_all=Ver todas
33723379
dependency.id=ID
33733380
dependency.version=Versão
3381+
search_in_external_registry=Pesquisar em %s
33743382
alpine.registry=Configure este registro adicionando o URL no arquivo <code>/etc/apk/repositories</code>:
33753383
alpine.registry.key=Baixe a chave RSA pública do registro para a pasta <code>/etc/apk/keys/</code> para verificar a assinatura do índice:
33763384
alpine.registry.info=Escolha o $branch e $repository da lista abaixo.
@@ -3398,6 +3406,7 @@ conda.install=Para instalar o pacote usando o Conda, execute o seguinte comando:
33983406
container.details.type=Tipo de Imagem
33993407
container.details.platform=Plataforma
34003408
container.pull=Puxe a imagem pela linha de comando:
3409+
container.images=Imagens
34013410
container.digest=Digest
34023411
container.multi_arch=S.O. / Arquitetura
34033412
container.layers=Camadas da Imagem
@@ -3506,6 +3515,8 @@ creation.name_placeholder=apenas caracteres alfanuméricos ou underline (_), nã
35063515
creation.value_placeholder=Insira qualquer conteúdo. Espaços em branco no início e no fim serão omitidos.
35073516

35083517

3518+
add_secret=Adicionar segredo
3519+
edit_secret=Editar segredo
35093520
deletion=Excluir segredo
35103521
deletion.description=A exclusão de um segredo é permanente e não pode ser desfeita. Continuar?
35113522
deletion.success=O segredo foi excluído.
@@ -3605,9 +3616,11 @@ variables.update.success=A variável foi editada.
36053616

36063617

36073618
[projects]
3619+
deleted.display_name=Excluir Projeto
36083620
type-1.display_name=Projeto Individual
36093621
type-2.display_name=Projeto do Repositório
36103622
type-3.display_name=Projeto da Organização
3623+
enter_fullscreen=Tela cheia
36113624
exit_fullscreen=Sair da Tela Cheia
36123625

36133626
[git.filemode]

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ func Routes() *web.Router {
14231423
m.Get("/tags/{sha}", repo.GetAnnotatedTag)
14241424
m.Get("/notes/{sha}", repo.GetNote)
14251425
}, context.ReferencesGitRepo(true), reqRepoReader(unit.TypeCode))
1426+
m.Post("/diffpatch", mustEnableEditor, reqToken(), bind(api.ApplyDiffPatchFileOptions{}), repo.ReqChangeRepoFileOptionsAndCheck, repo.ApplyDiffPatch)
14261427
m.Group("/contents", func() {
14271428
m.Get("", repo.GetContentsList)
14281429
m.Get("/*", repo.GetContents)
@@ -1434,7 +1435,6 @@ func Routes() *web.Router {
14341435
m.Put("", bind(api.UpdateFileOptions{}), repo.ReqChangeRepoFileOptionsAndCheck, repo.UpdateFile)
14351436
m.Delete("", bind(api.DeleteFileOptions{}), repo.ReqChangeRepoFileOptionsAndCheck, repo.DeleteFile)
14361437
})
1437-
m.Post("/diffpatch", bind(api.ApplyDiffPatchFileOptions{}), repo.ReqChangeRepoFileOptionsAndCheck, repo.ApplyDiffPatch)
14381438
}, mustEnableEditor, reqToken())
14391439
}, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
14401440
m.Group("/contents-ext", func() {

routers/api/v1/repo/patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func ApplyDiffPatch(ctx *context.APIContext) {
3636
// in: body
3737
// required: true
3838
// schema:
39-
// "$ref": "#/definitions/UpdateFileOptions"
39+
// "$ref": "#/definitions/ApplyDiffPatchFileOptions"
4040
// responses:
4141
// "200":
4242
// "$ref": "#/responses/FileResponse"

routers/api/v1/swagger/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ type swaggerParameterBodies struct {
121121
// in:body
122122
GetFilesOptions api.GetFilesOptions
123123

124+
// in:body
125+
ApplyDiffPatchFileOptions api.ApplyDiffPatchFileOptions
126+
124127
// in:body
125128
ChangeFilesOptions api.ChangeFilesOptions
126129

templates/repo/actions/runs_list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
</div>
2929
<div class="flex-item-trailing">
3030
{{if $run.IsRefDeleted}}
31-
<span class="ui label run-list-ref gt-ellipsis tw-line-through" data-tooltip-content="{{$run.PrettyRef}}">{{$run.PrettyRef}}</span>
31+
<span class="ui label run-list-ref gt-ellipsis tw-line-through" data-tooltip-content="{{$run.RefTooltip}}">{{$run.PrettyRef}}</span>
3232
{{else}}
33-
<a class="ui label run-list-ref gt-ellipsis" href="{{$run.RefLink}}" data-tooltip-content="{{$run.PrettyRef}}">{{$run.PrettyRef}}</a>
33+
<a class="ui label run-list-ref gt-ellipsis" href="{{$run.RefLink}}" data-tooltip-content="{{$run.RefTooltip}}">{{$run.PrettyRef}}</a>
3434
{{end}}
3535
<div class="run-list-item-right">
3636
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince $run.Updated}}</div>

templates/swagger/v1_json.tmpl

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package integration
5+
6+
import (
7+
"fmt"
8+
"net/http"
9+
"net/url"
10+
"testing"
11+
12+
auth_model "code.gitea.io/gitea/models/auth"
13+
repo_model "code.gitea.io/gitea/models/repo"
14+
"code.gitea.io/gitea/models/unittest"
15+
user_model "code.gitea.io/gitea/models/user"
16+
api "code.gitea.io/gitea/modules/structs"
17+
18+
"github.com/stretchr/testify/assert"
19+
)
20+
21+
func getApplyDiffPatchFileOptions() *api.ApplyDiffPatchFileOptions {
22+
return &api.ApplyDiffPatchFileOptions{
23+
FileOptions: api.FileOptions{
24+
BranchName: "master",
25+
},
26+
Content: `diff --git a/patch-file-1.txt b/patch-file-1.txt
27+
new file mode 100644
28+
index 0000000000..aaaaaaaaaa
29+
--- /dev/null
30+
+++ b/patch-file-1.txt
31+
@@ -0,0 +1 @@
32+
+File 1
33+
`,
34+
}
35+
}
36+
37+
func TestAPIApplyDiffPatchFileOptions(t *testing.T) {
38+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
39+
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) // owner of the repo1 & repo16
40+
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}) // owner of the repo3, is an org
41+
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) // owner of neither repos
42+
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) // public repo
43+
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}) // public repo
44+
repo16 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16}) // private repo
45+
46+
session2 := loginUser(t, user2.Name)
47+
token2 := getTokenForLoggedInUser(t, session2, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
48+
session4 := loginUser(t, user4.Name)
49+
token4 := getTokenForLoggedInUser(t, session4, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
50+
51+
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/diffpatch", getApplyDiffPatchFileOptions()).AddTokenAuth(token2)
52+
resp := MakeRequest(t, req, http.StatusCreated)
53+
var fileResponse api.FileResponse
54+
DecodeJSON(t, resp, &fileResponse)
55+
assert.Nil(t, fileResponse.Content)
56+
assert.NotEmpty(t, fileResponse.Commit.HTMLURL)
57+
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/raw/patch-file-1.txt")
58+
resp = MakeRequest(t, req, http.StatusOK)
59+
assert.Equal(t, "File 1\n", resp.Body.String())
60+
61+
// Test creating a file in repo1 by user4 who does not have write access
62+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", user2.Name, repo16.Name), getApplyDiffPatchFileOptions()).
63+
AddTokenAuth(token4)
64+
MakeRequest(t, req, http.StatusNotFound)
65+
66+
// Tests a repo with no token given so will fail
67+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", user2.Name, repo16.Name), getApplyDiffPatchFileOptions())
68+
MakeRequest(t, req, http.StatusNotFound)
69+
70+
// Test using access token for a private repo that the user of the token owns
71+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", user2.Name, repo16.Name), getApplyDiffPatchFileOptions()).
72+
AddTokenAuth(token2)
73+
MakeRequest(t, req, http.StatusCreated)
74+
75+
// Test using org repo "org3/repo3" where user2 is a collaborator
76+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", org3.Name, repo3.Name), getApplyDiffPatchFileOptions()).
77+
AddTokenAuth(token2)
78+
MakeRequest(t, req, http.StatusCreated)
79+
80+
// Test using org repo "org3/repo3" with no user token
81+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", org3.Name, repo3.Name), getApplyDiffPatchFileOptions())
82+
MakeRequest(t, req, http.StatusNotFound)
83+
84+
// Test using repo "user2/repo1" where user4 is a NOT collaborator
85+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", user2.Name, repo1.Name), getApplyDiffPatchFileOptions()).
86+
AddTokenAuth(token4)
87+
MakeRequest(t, req, http.StatusForbidden)
88+
})
89+
}

0 commit comments

Comments
 (0)