Skip to content

Commit 0fd90b4

Browse files
authored
Merge branch 'main' into bugfix/actions_rerun
2 parents fa6c3c1 + d5fa2e7 commit 0fd90b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+224
-87
lines changed

Diff for: docs/content/doc/help/faq.en-us.md

+11
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,14 @@ It is highly recommended to back-up your database before running these commands.
449449
If you are using Cloudflare, turn off the auto-minify option in the dashboard.
450450

451451
`Speed` -> `Optimization` -> Uncheck `HTML` within the `Auto-Minify` settings.
452+
453+
## How to adopt repositories from disk
454+
455+
- Add your (bare) repositories to the correct spot for your configuration (`repository.ROOT`), ensuring they are in the correct layout `<REPO_ROOT>/[user]/[repo].git`.
456+
- **Note:** the directory names must be lowercase.
457+
- You can also check `<ROOT_URL>/admin/config` for the repository root path.
458+
- Ensure that the user/org exists that you want to adopt repositories for.
459+
- As an admin, go to `<ROOT_URL>/admin/repos/unadopted` and search.
460+
- Users can also be given similar permissions via config [`ALLOW_ADOPTION_OF_UNADOPTED_REPOSITORIES`]({{< relref "doc/advanced/config-cheat-sheet.en-us.md#repository" >}}).
461+
- If the above steps are done correctly, you should be able to select repositories to adopt.
462+
- If no repositories are found, enable [debug logging]({{< relref "doc/advanced/config-cheat-sheet.en-us.md#repository" >}}) to check for any specific errors.

Diff for: docs/content/doc/installation/with-docker-rootless.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gitea provides automatically updated Docker images within its Docker Hub organiz
1919
possible to always use the latest stable tag or to use another service that handles updating
2020
Docker images.
2121

22-
The rootless image use Gitea internal SSH to provide Git protocol and doesn't support OpenSSH.
22+
The rootless image uses Gitea internal SSH to provide Git protocol and doesn't support OpenSSH.
2323

2424
This reference setup guides users through the setup based on `docker-compose`, but the installation
2525
of `docker-compose` is out of scope of this documentation. To install `docker-compose` itself, follow

Diff for: models/activities/action.go

+46-5
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,49 @@ func (a *Action) GetRepoAbsoluteLink() string {
223223
return setting.AppURL + url.PathEscape(a.GetRepoUserName()) + "/" + url.PathEscape(a.GetRepoName())
224224
}
225225

226+
// GetCommentHTMLURL returns link to action comment.
227+
func (a *Action) GetCommentHTMLURL() string {
228+
return a.getCommentHTMLURL(db.DefaultContext)
229+
}
230+
231+
func (a *Action) loadComment(ctx context.Context) (err error) {
232+
if a.CommentID == 0 || a.Comment != nil {
233+
return nil
234+
}
235+
a.Comment, err = issues_model.GetCommentByID(ctx, a.CommentID)
236+
return err
237+
}
238+
239+
func (a *Action) getCommentHTMLURL(ctx context.Context) string {
240+
if a == nil {
241+
return "#"
242+
}
243+
_ = a.loadComment(ctx)
244+
if a.Comment != nil {
245+
return a.Comment.HTMLURL()
246+
}
247+
if len(a.GetIssueInfos()) == 0 {
248+
return "#"
249+
}
250+
// Return link to issue
251+
issueIDString := a.GetIssueInfos()[0]
252+
issueID, err := strconv.ParseInt(issueIDString, 10, 64)
253+
if err != nil {
254+
return "#"
255+
}
256+
257+
issue, err := issues_model.GetIssueByID(ctx, issueID)
258+
if err != nil {
259+
return "#"
260+
}
261+
262+
if err = issue.LoadRepo(ctx); err != nil {
263+
return "#"
264+
}
265+
266+
return issue.HTMLURL()
267+
}
268+
226269
// GetCommentLink returns link to action comment.
227270
func (a *Action) GetCommentLink() string {
228271
return a.getCommentLink(db.DefaultContext)
@@ -232,11 +275,9 @@ func (a *Action) getCommentLink(ctx context.Context) string {
232275
if a == nil {
233276
return "#"
234277
}
235-
if a.Comment == nil && a.CommentID != 0 {
236-
a.Comment, _ = issues_model.GetCommentByID(ctx, a.CommentID)
237-
}
278+
_ = a.loadComment(ctx)
238279
if a.Comment != nil {
239-
return a.Comment.HTMLURL()
280+
return a.Comment.Link()
240281
}
241282
if len(a.GetIssueInfos()) == 0 {
242283
return "#"
@@ -257,7 +298,7 @@ func (a *Action) getCommentLink(ctx context.Context) string {
257298
return "#"
258299
}
259300

260-
return issue.HTMLURL()
301+
return issue.Link()
261302
}
262303

263304
// GetBranch returns the action's repository branch.

Diff for: models/activities/action_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestAction_GetRepoLink(t *testing.T) {
3636
expected := path.Join(setting.AppSubURL, owner.Name, repo.Name)
3737
assert.Equal(t, expected, action.GetRepoLink())
3838
assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink())
39-
assert.Equal(t, comment.HTMLURL(), action.GetCommentLink())
39+
assert.Equal(t, comment.HTMLURL(), action.GetCommentHTMLURL())
4040
}
4141

4242
func TestGetFeeds(t *testing.T) {

Diff for: models/activities/notification.go

+16
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,22 @@ func (n *Notification) HTMLURL() string {
459459
return ""
460460
}
461461

462+
// Link formats a relative URL-string to the notification
463+
func (n *Notification) Link() string {
464+
switch n.Source {
465+
case NotificationSourceIssue, NotificationSourcePullRequest:
466+
if n.Comment != nil {
467+
return n.Comment.Link()
468+
}
469+
return n.Issue.Link()
470+
case NotificationSourceCommit:
471+
return n.Repository.Link() + "/commit/" + url.PathEscape(n.CommitID)
472+
case NotificationSourceRepository:
473+
return n.Repository.Link()
474+
}
475+
return ""
476+
}
477+
462478
// APIURL formats a URL-string to the notification
463479
func (n *Notification) APIURL() string {
464480
return setting.AppURL + "api/v1/notifications/threads/" + strconv.FormatInt(n.ID, 10)

Diff for: models/issues/comment.go

+26-7
Original file line numberDiff line numberDiff line change
@@ -391,21 +391,40 @@ func (c *Comment) HTMLURL() string {
391391
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
392392
return ""
393393
}
394+
return c.Issue.HTMLURL() + c.hashLink()
395+
}
396+
397+
// Link formats a relative URL-string to the issue-comment
398+
func (c *Comment) Link() string {
399+
err := c.LoadIssue(db.DefaultContext)
400+
if err != nil { // Silently dropping errors :unamused:
401+
log.Error("LoadIssue(%d): %v", c.IssueID, err)
402+
return ""
403+
}
404+
err = c.Issue.LoadRepo(db.DefaultContext)
405+
if err != nil { // Silently dropping errors :unamused:
406+
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
407+
return ""
408+
}
409+
return c.Issue.Link() + c.hashLink()
410+
}
411+
412+
func (c *Comment) hashLink() string {
394413
if c.Type == CommentTypeCode {
395414
if c.ReviewID == 0 {
396-
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
415+
return "/files#" + c.HashTag()
397416
}
398417
if c.Review == nil {
399418
if err := c.LoadReview(); err != nil {
400419
log.Warn("LoadReview(%d): %v", c.ReviewID, err)
401-
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
420+
return "/files#" + c.HashTag()
402421
}
403422
}
404423
if c.Review.Type <= ReviewTypePending {
405-
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
424+
return "/files#" + c.HashTag()
406425
}
407426
}
408-
return fmt.Sprintf("%s#%s", c.Issue.HTMLURL(), c.HashTag())
427+
return "#" + c.HashTag()
409428
}
410429

411430
// APIURL formats a API-string to the issue-comment
@@ -708,8 +727,8 @@ func (c *Comment) UnsignedLine() uint64 {
708727
return uint64(c.Line)
709728
}
710729

711-
// CodeCommentURL returns the url to a comment in code
712-
func (c *Comment) CodeCommentURL() string {
730+
// CodeCommentLink returns the url to a comment in code
731+
func (c *Comment) CodeCommentLink() string {
713732
err := c.LoadIssue(db.DefaultContext)
714733
if err != nil { // Silently dropping errors :unamused:
715734
log.Error("LoadIssue(%d): %v", c.IssueID, err)
@@ -720,7 +739,7 @@ func (c *Comment) CodeCommentURL() string {
720739
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
721740
return ""
722741
}
723-
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
742+
return fmt.Sprintf("%s/files#%s", c.Issue.Link(), c.HashTag())
724743
}
725744

726745
// LoadPushCommits Load push commits

Diff for: models/issues/issue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (issue *Issue) HTMLURL() string {
419419
return fmt.Sprintf("%s/%s/%d", issue.Repo.HTMLURL(), path, issue.Index)
420420
}
421421

422-
// Link returns the Link URL to this issue.
422+
// Link returns the issue's relative URL.
423423
func (issue *Issue) Link() string {
424424
var path string
425425
if issue.IsPull {

Diff for: models/issues/pull.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -759,20 +759,20 @@ func GetPullRequestsByHeadBranch(ctx context.Context, headBranch string, headRep
759759
return prs, nil
760760
}
761761

762-
// GetBaseBranchHTMLURL returns the HTML URL of the base branch
763-
func (pr *PullRequest) GetBaseBranchHTMLURL() string {
762+
// GetBaseBranchLink returns the relative URL of the base branch
763+
func (pr *PullRequest) GetBaseBranchLink() string {
764764
if err := pr.LoadBaseRepo(db.DefaultContext); err != nil {
765765
log.Error("LoadBaseRepo: %v", err)
766766
return ""
767767
}
768768
if pr.BaseRepo == nil {
769769
return ""
770770
}
771-
return pr.BaseRepo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(pr.BaseBranch)
771+
return pr.BaseRepo.Link() + "/src/branch/" + util.PathEscapeSegments(pr.BaseBranch)
772772
}
773773

774-
// GetHeadBranchHTMLURL returns the HTML URL of the head branch
775-
func (pr *PullRequest) GetHeadBranchHTMLURL() string {
774+
// GetHeadBranchLink returns the relative URL of the head branch
775+
func (pr *PullRequest) GetHeadBranchLink() string {
776776
if pr.Flow == PullRequestFlowAGit {
777777
return ""
778778
}
@@ -784,7 +784,7 @@ func (pr *PullRequest) GetHeadBranchHTMLURL() string {
784784
if pr.HeadRepo == nil {
785785
return ""
786786
}
787-
return pr.HeadRepo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(pr.HeadBranch)
787+
return pr.HeadRepo.Link() + "/src/branch/" + util.PathEscapeSegments(pr.HeadBranch)
788788
}
789789

790790
// UpdateAllowEdits update if PR can be edited from maintainers

Diff for: models/packages/descriptor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type PackageFileDescriptor struct {
6565

6666
// PackageWebLink returns the package web link
6767
func (pd *PackageDescriptor) PackageWebLink() string {
68-
return fmt.Sprintf("%s/-/packages/%s/%s", pd.Owner.HTMLURL(), string(pd.Package.Type), url.PathEscape(pd.Package.LowerName))
68+
return fmt.Sprintf("%s/-/packages/%s/%s", pd.Owner.HomeLink(), string(pd.Package.Type), url.PathEscape(pd.Package.LowerName))
6969
}
7070

7171
// FullWebLink returns the package version web link

Diff for: models/project/project.go

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func (p *Project) LoadRepo(ctx context.Context) (err error) {
116116
return err
117117
}
118118

119+
// Link returns the project's relative URL.
119120
func (p *Project) Link() string {
120121
if p.OwnerID > 0 {
121122
err := p.LoadOwner(db.DefaultContext)

Diff for: models/repo/release.go

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ func (r *Release) HTMLURL() string {
130130
return r.Repo.HTMLURL() + "/releases/tag/" + util.PathEscapeSegments(r.TagName)
131131
}
132132

133+
// Link the relative url for a release on the web UI. release must have attributes loaded
134+
func (r *Release) Link() string {
135+
return r.Repo.Link() + "/releases/tag/" + util.PathEscapeSegments(r.TagName)
136+
}
137+
133138
// IsReleaseExist returns true if release with given tag name already exists.
134139
func IsReleaseExist(ctx context.Context, repoID int64, tagName string) (bool, error) {
135140
if len(tagName) == 0 {

Diff for: models/repo/repo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ func (repo *Repository) RepoPath() string {
480480
return RepoPath(repo.OwnerName, repo.Name)
481481
}
482482

483-
// Link returns the repository link
483+
// Link returns the repository relative url
484484
func (repo *Repository) Link() string {
485485
return setting.AppSubURL + "/" + url.PathEscape(repo.OwnerName) + "/" + url.PathEscape(repo.Name)
486486
}

Diff for: modules/migration/comment.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import "time"
88

99
// Commentable can be commented upon
1010
type Commentable interface {
11-
GetLocalIndex() int64
12-
GetForeignIndex() int64
11+
Reviewable
1312
GetContext() DownloaderContext
1413
}
1514

Diff for: modules/migration/issue.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ func (issue *Issue) GetExternalName() string { return issue.PosterName }
3434
// GetExternalID ExternalUserMigrated interface
3535
func (issue *Issue) GetExternalID() int64 { return issue.PosterID }
3636

37-
func (issue *Issue) GetLocalIndex() int64 { return issue.Number }
38-
func (issue *Issue) GetForeignIndex() int64 { return issue.ForeignIndex }
37+
func (issue *Issue) GetLocalIndex() int64 { return issue.Number }
38+
39+
func (issue *Issue) GetForeignIndex() int64 {
40+
// see the comment of Reviewable.GetForeignIndex
41+
// if there is no ForeignIndex, then use LocalIndex
42+
if issue.ForeignIndex == 0 {
43+
return issue.Number
44+
}
45+
return issue.ForeignIndex
46+
}
47+
3948
func (issue *Issue) GetContext() DownloaderContext { return issue.Context }

Diff for: modules/migration/review.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import "time"
88
// Reviewable can be reviewed
99
type Reviewable interface {
1010
GetLocalIndex() int64
11+
12+
// GetForeignIndex presents the foreign index, which could be misused:
13+
// For example, if there are 2 Gitea sites: site-A exports a dataset, then site-B imports it:
14+
// * if site-A exports files by using its LocalIndex
15+
// * from site-A's view, LocalIndex is site-A's IssueIndex while ForeignIndex is site-B's IssueIndex
16+
// * but from site-B's view, LocalIndex is site-B's IssueIndex while ForeignIndex is site-A's IssueIndex
17+
//
18+
// So the exporting/importing must be paired, but the meaning of them looks confusing then:
19+
// * either site-A and site-B both use LocalIndex during dumping/restoring
20+
// * or site-A and site-B both use ForeignIndex
1121
GetForeignIndex() int64
1222
}
1323

@@ -37,7 +47,7 @@ type Review struct {
3747
// GetExternalName ExternalUserMigrated interface
3848
func (r *Review) GetExternalName() string { return r.ReviewerName }
3949

40-
// ExternalID ExternalUserMigrated interface
50+
// GetExternalID ExternalUserMigrated interface
4151
func (r *Review) GetExternalID() int64 { return r.ReviewerID }
4252

4353
// ReviewComment represents a review comment

Diff for: modules/structs/repo.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type Repository struct {
6363
Language string `json:"language"`
6464
LanguagesURL string `json:"languages_url"`
6565
HTMLURL string `json:"html_url"`
66+
Link string `json:"link"`
6667
SSHURL string `json:"ssh_url"`
6768
CloneURL string `json:"clone_url"`
6869
OriginalURL string `json:"original_url"`

Diff for: routers/web/feed/convert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
7373

7474
var content, desc, title string
7575

76-
link := &feeds.Link{Href: act.GetCommentLink()}
76+
link := &feeds.Link{Href: act.GetCommentHTMLURL()}
7777

7878
// title
7979
title = act.ActUser.DisplayName() + " "

Diff for: routers/web/repo/pull.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
339339
ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
340340
}
341341
ctx.Data["BaseTarget"] = pull.BaseBranch
342-
ctx.Data["HeadBranchHTMLURL"] = pull.GetHeadBranchHTMLURL()
343-
ctx.Data["BaseBranchHTMLURL"] = pull.GetBaseBranchHTMLURL()
342+
ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink()
343+
ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink()
344344
}
345345

346346
// PrepareMergedViewPullInfo show meta information for a merged pull request view page

Diff for: routers/web/repo/repo.go

+1
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ func SearchRepo(ctx *context.Context) {
569569
Mirror: repo.IsMirror,
570570
Stars: repo.NumStars,
571571
HTMLURL: repo.HTMLURL(),
572+
Link: repo.Link(),
572573
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
573574
}
574575
}

Diff for: templates/code/searchresults.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
<div class="diff-file-box diff-box file-content non-diff-file-content repo-search-result">
1414
<h4 class="ui top attached normal header">
1515
<span class="file">
16-
<a rel="nofollow" href="{{$repo.HTMLURL}}">{{$repo.FullName}}</a>
16+
<a rel="nofollow" href="{{$repo.Link}}">{{$repo.FullName}}</a>
1717
{{if $repo.IsArchived}}
1818
<span class="ui basic label">{{$.locale.Tr "repo.desc.archived"}}</span>
1919
{{end}}
2020
- {{.Filename}}
2121
</span>
22-
<a class="ui basic tiny button" rel="nofollow" href="{{$repo.HTMLURL}}/src/commit/{{$result.CommitID | PathEscape}}/{{.Filename | PathEscapeSegments}}">{{$.locale.Tr "repo.diff.view_file"}}</a>
22+
<a class="ui basic tiny button" rel="nofollow" href="{{$repo.Link}}/src/commit/{{$result.CommitID | PathEscape}}/{{.Filename | PathEscapeSegments}}">{{$.locale.Tr "repo.diff.view_file"}}</a>
2323
</h4>
2424
<div class="ui attached table segment">
2525
<div class="file-body file-code code-view">
@@ -28,7 +28,7 @@
2828
<tr>
2929
<td class="lines-num">
3030
{{range .LineNumbers}}
31-
<a href="{{$repo.HTMLURL}}/src/commit/{{$result.CommitID | PathEscape}}/{{$result.Filename | PathEscapeSegments}}#L{{.}}"><span>{{.}}</span></a>
31+
<a href="{{$repo.Link}}/src/commit/{{$result.CommitID | PathEscape}}/{{$result.Filename | PathEscapeSegments}}#L{{.}}"><span>{{.}}</span></a>
3232
{{end}}
3333
</td>
3434
<td class="lines-code chroma"><code class="code-inner">{{.FormattedLines | Safe}}</code></td>

Diff for: templates/mail/issue/assigned.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<title>{{.Subject}}</title>
99
</head>
1010

11-
{{$repo_url := printf "<a href='%s'>%s</a>" (Escape .Issue.Repo.HTMLURL) (Escape .Issue.Repo.FullName)}}
11+
{{$repo_url := printf "<a href='%s'>%s</a>" (Escape .Issue.Repo.Link) (Escape .Issue.Repo.FullName)}}
1212
{{$link := printf "<a href='%s'>#%d</a>" (Escape .Link) .Issue.Index}}
1313
<body>
1414
<p>

0 commit comments

Comments
 (0)