Skip to content

Commit 3d7a341

Browse files
authored
Merge branch 'main' into update-i.8713187.xyz/google/go-github
2 parents 168ea01 + e5dcd6a commit 3d7a341

File tree

12 files changed

+51
-26
lines changed

12 files changed

+51
-26
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ generate-go: $(TAGS_PREREQ)
747747

748748
.PHONY: security-check
749749
security-check:
750-
go run $(GOVULNCHECK_PACKAGE) -v ./...
750+
go run $(GOVULNCHECK_PACKAGE) ./...
751751

752752
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
753753
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@

models/actions/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ActionRun struct {
3636
TriggerUser *user_model.User `xorm:"-"`
3737
Ref string
3838
CommitSHA string
39-
IsForkPullRequest bool
39+
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
4040
NeedApproval bool // may need approval if it's a fork pull request
4141
ApprovedBy int64 `xorm:"index"` // who approved
4242
Event webhook_module.HookEventType

modules/context/repo.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,35 +240,34 @@ func (r *Repository) FileExists(path, branch string) (bool, error) {
240240

241241
// GetEditorconfig returns the .editorconfig definition if found in the
242242
// HEAD of the default repo branch.
243-
func (r *Repository) GetEditorconfig(optCommit ...*git.Commit) (*editorconfig.Editorconfig, error) {
243+
func (r *Repository) GetEditorconfig(optCommit ...*git.Commit) (cfg *editorconfig.Editorconfig, warning, err error) {
244244
if r.GitRepo == nil {
245-
return nil, nil
245+
return nil, nil, nil
246246
}
247-
var (
248-
err error
249-
commit *git.Commit
250-
)
247+
248+
var commit *git.Commit
249+
251250
if len(optCommit) != 0 {
252251
commit = optCommit[0]
253252
} else {
254253
commit, err = r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
255254
if err != nil {
256-
return nil, err
255+
return nil, nil, err
257256
}
258257
}
259258
treeEntry, err := commit.GetTreeEntryByPath(".editorconfig")
260259
if err != nil {
261-
return nil, err
260+
return nil, nil, err
262261
}
263262
if treeEntry.Blob().Size() >= setting.UI.MaxDisplayFileSize {
264-
return nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"}
263+
return nil, nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"}
265264
}
266265
reader, err := treeEntry.Blob().DataAsync()
267266
if err != nil {
268-
return nil, err
267+
return nil, nil, err
269268
}
270269
defer reader.Close()
271-
return editorconfig.Parse(reader)
270+
return editorconfig.ParseGraceful(reader)
272271
}
273272

274273
// RetrieveBaseRepo retrieves base repository

routers/api/v1/repo/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func GetEditorconfig(ctx *context.APIContext) {
381381
// "404":
382382
// "$ref": "#/responses/notFound"
383383

384-
ec, err := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
384+
ec, _, err := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
385385
if err != nil {
386386
if git.IsErrNotExist(err) {
387387
ctx.NotFound(err)

routers/web/repo/editor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
165165

166166
// GetEditorConfig returns a editorconfig JSON string for given treePath or "null"
167167
func GetEditorConfig(ctx *context.Context, treePath string) string {
168-
ec, err := ctx.Repo.GetEditorconfig()
168+
ec, _, err := ctx.Repo.GetEditorconfig()
169169
if err == nil {
170170
def, err := ec.GetDefinitionForFilename(treePath)
171171
if err == nil {

routers/web/repo/middlewares.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func SetEditorconfigIfExists(ctx *context.Context) {
1919
return
2020
}
2121

22-
ec, err := ctx.Repo.GetEditorconfig()
22+
ec, _, err := ctx.Repo.GetEditorconfig()
2323

2424
if err != nil && !git.IsErrNotExist(err) {
2525
description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)

routers/web/repo/view.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,18 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
346346
ctx.Data["RawFileLink"] = rawLink + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
347347

348348
if ctx.Repo.TreePath == ".editorconfig" {
349-
_, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
350-
ctx.Data["FileError"] = editorconfigErr
349+
_, editorconfigWarning, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
350+
if editorconfigWarning != nil {
351+
ctx.Data["FileWarning"] = strings.TrimSpace(editorconfigWarning.Error())
352+
}
353+
if editorconfigErr != nil {
354+
ctx.Data["FileError"] = strings.TrimSpace(editorconfigErr.Error())
355+
}
351356
} else if ctx.Repo.IsIssueConfig(ctx.Repo.TreePath) {
352357
_, issueConfigErr := ctx.Repo.GetIssueConfig(ctx.Repo.TreePath, ctx.Repo.Commit)
353-
ctx.Data["FileError"] = issueConfigErr
358+
if issueConfigErr != nil {
359+
ctx.Data["FileError"] = strings.TrimSpace(issueConfigErr.Error())
360+
}
354361
}
355362

356363
isDisplayingSource := ctx.FormString("display") == "source"

services/actions/notifier_helper.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ func notify(ctx context.Context, input *notifyInput) error {
152152
return fmt.Errorf("json.Marshal: %w", err)
153153
}
154154

155+
isForkPullRequest := false
156+
if pr := input.PullRequest; pr != nil {
157+
switch pr.Flow {
158+
case issues_model.PullRequestFlowGithub:
159+
isForkPullRequest = pr.IsFromFork()
160+
case issues_model.PullRequestFlowAGit:
161+
// There is no fork concept in agit flow, anyone with read permission can push refs/for/<target-branch>/<topic-branch> to the repo.
162+
// So we can treat it as a fork pull request because it may be from an untrusted user
163+
isForkPullRequest = true
164+
default:
165+
// unknown flow, assume it's a fork pull request to be safe
166+
isForkPullRequest = true
167+
}
168+
}
169+
155170
for id, content := range workflows {
156171
run := &actions_model.ActionRun{
157172
Title: strings.SplitN(commit.CommitMessage, "\n", 2)[0],
@@ -161,7 +176,7 @@ func notify(ctx context.Context, input *notifyInput) error {
161176
TriggerUserID: input.Doer.ID,
162177
Ref: ref,
163178
CommitSHA: commit.ID.String(),
164-
IsForkPullRequest: input.PullRequest != nil && input.PullRequest.IsFromFork(),
179+
IsForkPullRequest: isForkPullRequest,
165180
Event: input.Event,
166181
EventPayload: string(p),
167182
Status: actions_model.StatusWaiting,

services/release/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
227227
deletedUUIDs.Add(attach.UUID)
228228
}
229229

230-
if _, err := repo_model.DeleteAttachments(ctx, attachments, false); err != nil {
230+
if _, err := repo_model.DeleteAttachments(ctx, attachments, true); err != nil {
231231
return fmt.Errorf("DeleteAttachments [uuids: %v]: %w", delAttachmentUUIDs, err)
232232
}
233233
}

templates/package/content/nuget.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<div class="ui form">
55
<div class="field">
66
<label>{{svg "octicon-terminal"}} {{.locale.Tr "packages.nuget.registry"}}</label>
7-
<div class="markup"><pre class="code-block"><code>dotnet nuget add source --name Gitea --username your_username --password your_token <gitea-origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/nuget/index.json"></gitea-origin-url></code></pre></div>
7+
<div class="markup"><pre class="code-block"><code>dotnet nuget add source --name {{.PackageDescriptor.Owner.Name}} --username your_username --password your_token <gitea-origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/nuget/index.json"></gitea-origin-url></code></pre></div>
88
</div>
99
<div class="field">
1010
<label>{{svg "octicon-terminal"}} {{.locale.Tr "packages.nuget.install"}}</label>
11-
<div class="markup"><pre class="code-block"><code>dotnet add package --source Gitea --version {{.PackageDescriptor.Version.Version}} {{.PackageDescriptor.Package.Name}}</code></pre></div>
11+
<div class="markup"><pre class="code-block"><code>dotnet add package --source {{.PackageDescriptor.Owner.Name}} --version {{.PackageDescriptor.Version.Version}} {{.PackageDescriptor.Package.Name}}</code></pre></div>
1212
</div>
1313
<div class="field">
1414
<label>{{.locale.Tr "packages.nuget.documentation" | Safe}}</label>

templates/repo/view_file.tmpl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<div class="{{TabSizeClass .Editorconfig .FileName}} non-diff-file-content">
22
{{- if .FileError}}
3+
<div class="ui error message">
4+
<div class="text left gt-whitespace-pre">{{.FileError}}</div>
5+
</div>
6+
{{end}}
7+
{{- if .FileWarning}}
38
<div class="ui warning message">
4-
<div class="text left">
5-
<div>{{.FileError}}</div>
6-
</div>
9+
<div class="text left gt-whitespace-pre">{{.FileWarning}}</div>
710
</div>
811
{{end}}
912
<h4 class="file-header ui top attached header gt-df gt-ac gt-sb gt-fw">

web_src/css/helpers.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
.gt-overflow-x-scroll { overflow-x: scroll !important; }
2626
.gt-cursor-default { cursor: default !important; }
2727
.gt-items-start { align-items: flex-start !important; }
28+
.gt-whitespace-pre { white-space: pre !important }
2829

2930
.gt-mono {
3031
font-family: var(--fonts-monospace) !important;

0 commit comments

Comments
 (0)