mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-05-16 20:00:52 +00:00
Compare commits
12 commits
4b79a98910
...
f45a6cb3b7
Author | SHA1 | Date | |
---|---|---|---|
f45a6cb3b7 | |||
5b6a375d05 | |||
ac34a68a93 | |||
fcf85b12af | |||
2949bbcad1 | |||
b23d4ec4bb | |||
d758633c91 | |||
d449fcff0a | |||
a7400b1812 | |||
a6d31a30a2 | |||
b917571d81 | |||
c91f7d3599 |
2
Makefile
2
Makefile
|
@ -27,7 +27,7 @@ DIFF ?= diff --unified
|
|||
XGO_VERSION := go-1.21.x
|
||||
|
||||
AIR_PACKAGE ?= github.com/cosmtrek/air@v1.49.0
|
||||
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
|
||||
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v2/cmd/editorconfig-checker@2.8.0
|
||||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.6.0
|
||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
|
||||
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
|
||||
|
|
1
release-notes/8.0.0/3572.md
Normal file
1
release-notes/8.0.0/3572.md
Normal file
|
@ -0,0 +1 @@
|
|||
Fix gogs migration if gogs is hosted at a subpath
|
1
release-notes/8.0.0/3608.md
Normal file
1
release-notes/8.0.0/3608.md
Normal file
|
@ -0,0 +1 @@
|
|||
Fix text selection color
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
user_service "code.gitea.io/gitea/services/user"
|
||||
)
|
||||
|
@ -27,6 +28,12 @@ func BlockedUsers(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = shared_user.LoadHeaderCount(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("LoadHeaderCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["BlockedUsers"] = blockedUsers
|
||||
|
||||
ctx.HTML(http.StatusOK, tplBlockedUsers)
|
||||
|
|
|
@ -38,17 +38,24 @@ func (f *GogsDownloaderFactory) New(ctx context.Context, opts base.MigrateOption
|
|||
return nil, err
|
||||
}
|
||||
|
||||
baseURL := u.Scheme + "://" + u.Host
|
||||
repoNameSpace := strings.TrimSuffix(u.Path, ".git")
|
||||
repoNameSpace = strings.Trim(repoNameSpace, "/")
|
||||
|
||||
fields := strings.Split(repoNameSpace, "/")
|
||||
if len(fields) < 2 {
|
||||
numFields := len(fields)
|
||||
if numFields < 2 {
|
||||
return nil, fmt.Errorf("invalid path: %s", repoNameSpace)
|
||||
}
|
||||
|
||||
log.Trace("Create gogs downloader. BaseURL: %s RepoOwner: %s RepoName: %s", baseURL, fields[0], fields[1])
|
||||
return NewGogsDownloader(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, fields[0], fields[1]), nil
|
||||
repoOwner := fields[numFields-2]
|
||||
repoName := fields[numFields-1]
|
||||
|
||||
u.Path = ""
|
||||
u = u.JoinPath(fields[:numFields-2]...)
|
||||
baseURL := u.String()
|
||||
|
||||
log.Trace("Create gogs downloader. BaseURL: %s RepoOwner: %s RepoName: %s", baseURL, repoOwner, repoName)
|
||||
return NewGogsDownloader(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, repoOwner, repoName), nil
|
||||
}
|
||||
|
||||
// GitServiceType returns the type of git service
|
||||
|
|
|
@ -137,3 +137,87 @@ func TestGogsDownloadRepo(t *testing.T) {
|
|||
_, _, err = downloader.GetPullRequests(1, 3)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestGogsDownloaderFactory_New(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args base.MigrateOptions
|
||||
baseURL string
|
||||
repoOwner string
|
||||
repoName string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Gogs_at_root",
|
||||
args: base.MigrateOptions{
|
||||
CloneAddr: "https://git.example.com/user/repo.git",
|
||||
AuthUsername: "username",
|
||||
AuthPassword: "password",
|
||||
AuthToken: "authtoken",
|
||||
},
|
||||
baseURL: "https://git.example.com/",
|
||||
repoOwner: "user",
|
||||
repoName: "repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Gogs_at_sub_path",
|
||||
args: base.MigrateOptions{
|
||||
CloneAddr: "https://git.example.com/subpath/user/repo.git",
|
||||
AuthUsername: "username",
|
||||
AuthPassword: "password",
|
||||
AuthToken: "authtoken",
|
||||
},
|
||||
baseURL: "https://git.example.com/subpath",
|
||||
repoOwner: "user",
|
||||
repoName: "repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Gogs_at_2nd_sub_path",
|
||||
args: base.MigrateOptions{
|
||||
CloneAddr: "https://git.example.com/sub1/sub2/user/repo.git",
|
||||
AuthUsername: "username",
|
||||
AuthPassword: "password",
|
||||
AuthToken: "authtoken",
|
||||
},
|
||||
baseURL: "https://git.example.com/sub1/sub2",
|
||||
repoOwner: "user",
|
||||
repoName: "repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Gogs_URL_too_short",
|
||||
args: base.MigrateOptions{
|
||||
CloneAddr: "https://git.example.com/repo.git",
|
||||
AuthUsername: "username",
|
||||
AuthPassword: "password",
|
||||
AuthToken: "authtoken",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f := &GogsDownloaderFactory{}
|
||||
opts := base.MigrateOptions{
|
||||
CloneAddr: tt.args.CloneAddr,
|
||||
AuthUsername: tt.args.AuthUsername,
|
||||
AuthPassword: tt.args.AuthPassword,
|
||||
AuthToken: tt.args.AuthToken,
|
||||
}
|
||||
got, err := f.New(context.Background(), opts)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("GogsDownloaderFactory.New() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
} else if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
assert.IsType(t, &GogsDownloader{}, got)
|
||||
assert.EqualValues(t, tt.baseURL, got.(*GogsDownloader).baseURL)
|
||||
assert.EqualValues(t, tt.repoOwner, got.(*GogsDownloader).repoOwner)
|
||||
assert.EqualValues(t, tt.repoName, got.(*GogsDownloader).repoName)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
{{if .RepoCount}}
|
||||
<div class="ui small label">{{.RepoCount}}</div>
|
||||
{{end}}
|
||||
<span hidden test-name="repository-count">{{.RepoCount}}</span>
|
||||
</a>
|
||||
{{if .CanReadProjects}}
|
||||
<a class="{{if .PageIsViewProjects}}active {{end}}item" href="{{$.Org.HomeLink}}/-/projects">
|
||||
|
@ -13,6 +14,7 @@
|
|||
{{if .ProjectCount}}
|
||||
<div class="ui small label">{{.ProjectCount}}</div>
|
||||
{{end}}
|
||||
<span hidden test-name="project-count">{{.ProjectCount}}</span>
|
||||
</a>
|
||||
{{end}}
|
||||
{{if and .IsPackageEnabled .CanReadPackages}}
|
||||
|
@ -31,6 +33,7 @@
|
|||
<div class="ui small label">{{.NumMembers}}</div>
|
||||
</a>
|
||||
{{end}}
|
||||
<span hidden test-name="member-count">{{.NumMembers}}</span>
|
||||
{{if .IsOrganizationMember}}
|
||||
<a class="{{if $.PageIsOrgTeams}}active {{end}}item" href="{{$.OrgLink}}/teams">
|
||||
{{svg "octicon-people"}} {{ctx.Locale.Tr "org.teams"}}
|
||||
|
@ -39,6 +42,7 @@
|
|||
{{end}}
|
||||
</a>
|
||||
{{end}}
|
||||
<span hidden test-name="team-count">{{.NumTeams}}</span>
|
||||
{{if .IsOrganizationOwner}}
|
||||
<a id="settings-btn" class="{{if .PageIsOrgSettings}}active {{end}}right item" href="{{.OrgLink}}/settings">
|
||||
{{svg "octicon-tools"}} {{ctx.Locale.Tr "repo.settings"}}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{{if .Title}}{{.Title}}{{else}}{{ctx.Locale.Tr "actions.runs.empty_commit_message"}}{{end}}
|
||||
</a>
|
||||
<div class="flex-item-body">
|
||||
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>:
|
||||
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b> -
|
||||
{{- if .ScheduleID -}}
|
||||
{{ctx.Locale.Tr "actions.runs.scheduled"}}
|
||||
{{- else -}}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
{{if .RepoCount}}
|
||||
<div class="ui small label">{{.RepoCount}}</div>
|
||||
{{end}}
|
||||
<span hidden test-name="repository-count">{{.RepoCount}}</span>
|
||||
</a>
|
||||
{{if or .ContextUser.IsIndividual .CanReadProjects}}
|
||||
<a href="{{.ContextUser.HomeLink}}/-/projects" class="{{if .PageIsViewProjects}}active {{end}}item">
|
||||
|
@ -17,6 +18,7 @@
|
|||
{{if .ProjectCount}}
|
||||
<div class="ui small label">{{.ProjectCount}}</div>
|
||||
{{end}}
|
||||
<span hidden test-name="project-count">{{.ProjectCount}}</span>
|
||||
</a>
|
||||
{{end}}
|
||||
{{if and .IsPackageEnabled (or .ContextUser.IsIndividual .CanReadPackages)}}
|
||||
|
|
|
@ -41,9 +41,11 @@
|
|||
<label for="redirect-uris">{{ctx.Locale.Tr "settings.oauth2_redirect_uris"}}</label>
|
||||
<textarea name="redirect_uris" id="redirect-uris" required>{{StringUtils.Join .App.RedirectURIs "\n"}}</textarea>
|
||||
</div>
|
||||
<div class="field ui checkbox {{if .Err_ConfidentialClient}}error{{end}}">
|
||||
<label>{{ctx.Locale.Tr "settings.oauth2_confidential_client"}}</label>
|
||||
<input type="checkbox" name="confidential_client" {{if .App.ConfidentialClient}}checked{{end}}>
|
||||
<div class="field {{if .Err_ConfidentialClient}}error{{end}}">
|
||||
<div class="ui checkbox">
|
||||
<label>{{ctx.Locale.Tr "settings.oauth2_confidential_client"}}</label>
|
||||
<input type="checkbox" name="confidential_client" {{if .App.ConfidentialClient}}checked{{end}}>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui primary button">
|
||||
{{ctx.Locale.Tr "settings.save_application"}}
|
||||
|
|
|
@ -61,9 +61,11 @@
|
|||
<label for="redirect-uris">{{ctx.Locale.Tr "settings.oauth2_redirect_uris"}}</label>
|
||||
<textarea name="redirect_uris" id="redirect-uris" required></textarea>
|
||||
</div>
|
||||
<div class="field ui checkbox {{if .Err_ConfidentialClient}}error{{end}}">
|
||||
<label>{{ctx.Locale.Tr "settings.oauth2_confidential_client"}}</label>
|
||||
<input type="checkbox" name="confidential_client" checked>
|
||||
<div class="field {{if .Err_ConfidentialClient}}error{{end}}">
|
||||
<div class="ui checkbox">
|
||||
<label>{{ctx.Locale.Tr "settings.oauth2_confidential_client"}}</label>
|
||||
<input type="checkbox" name="confidential_client" checked>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui primary button">
|
||||
{{ctx.Locale.Tr "settings.create_oauth2_application_button"}}
|
||||
|
|
167
tests/integration/user_count_test.go
Normal file
167
tests/integration/user_count_test.go
Normal file
|
@ -0,0 +1,167 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
project_model "code.gitea.io/gitea/models/project"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type userCountTest struct {
|
||||
doer *user_model.User
|
||||
user *user_model.User
|
||||
session *TestSession
|
||||
repoCount int64
|
||||
projectCount int64
|
||||
memberCount int64
|
||||
teamCount int64
|
||||
}
|
||||
|
||||
func (countTest *userCountTest) Init(t *testing.T, doerID, userID int64) {
|
||||
countTest.doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doerID})
|
||||
countTest.user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
|
||||
countTest.session = loginUser(t, countTest.doer.Name)
|
||||
|
||||
var err error
|
||||
|
||||
countTest.repoCount, err = repo_model.CountRepository(db.DefaultContext, &repo_model.SearchRepoOptions{
|
||||
Actor: countTest.doer,
|
||||
OwnerID: countTest.user.ID,
|
||||
Private: true,
|
||||
Collaborate: optional.Some(false),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
var projectType project_model.Type
|
||||
if countTest.user.IsOrganization() {
|
||||
projectType = project_model.TypeOrganization
|
||||
} else {
|
||||
projectType = project_model.TypeIndividual
|
||||
}
|
||||
countTest.projectCount, err = db.Count[project_model.Project](db.DefaultContext, project_model.SearchOptions{
|
||||
OwnerID: countTest.user.ID,
|
||||
IsClosed: optional.Some(false),
|
||||
Type: projectType,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
if !countTest.user.IsOrganization() {
|
||||
return
|
||||
}
|
||||
|
||||
org := (*organization.Organization)(countTest.user)
|
||||
|
||||
isMember, err := org.IsOrgMember(db.DefaultContext, countTest.doer.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
countTest.memberCount, err = organization.CountOrgMembers(db.DefaultContext, &organization.FindOrgMembersOpts{
|
||||
OrgID: org.ID,
|
||||
PublicOnly: !isMember,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
teams, err := org.LoadTeams(db.DefaultContext)
|
||||
require.NoError(t, err)
|
||||
|
||||
countTest.teamCount = int64(len(teams))
|
||||
}
|
||||
|
||||
func (countTest *userCountTest) getCount(doc *goquery.Document, name string) (int64, error) {
|
||||
selection := doc.Find(fmt.Sprintf("[test-name=\"%s\"]", name))
|
||||
|
||||
if selection.Length() != 1 {
|
||||
return 0, fmt.Errorf("%s was not found", name)
|
||||
}
|
||||
|
||||
return strconv.ParseInt(selection.Text(), 10, 64)
|
||||
}
|
||||
|
||||
func (countTest *userCountTest) TestPage(t *testing.T, page string, orgLink bool) {
|
||||
t.Run(page, func(t *testing.T) {
|
||||
var userLink string
|
||||
|
||||
if orgLink {
|
||||
userLink = countTest.user.OrganisationLink()
|
||||
} else {
|
||||
userLink = countTest.user.HomeLink()
|
||||
}
|
||||
|
||||
req := NewRequestf(t, "GET", "%s/%s", userLink, page)
|
||||
resp := countTest.session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
repoCount, err := countTest.getCount(htmlDoc.doc, "repository-count")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, countTest.repoCount, repoCount)
|
||||
|
||||
projectCount, err := countTest.getCount(htmlDoc.doc, "project-count")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, countTest.projectCount, projectCount)
|
||||
|
||||
if !countTest.user.IsOrganization() {
|
||||
return
|
||||
}
|
||||
|
||||
memberCount, err := countTest.getCount(htmlDoc.doc, "member-count")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, countTest.memberCount, memberCount)
|
||||
|
||||
teamCount, err := countTest.getCount(htmlDoc.doc, "team-count")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, countTest.teamCount, teamCount)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFrontendHeaderCountUser(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
countTest := new(userCountTest)
|
||||
countTest.Init(t, 2, 2)
|
||||
|
||||
countTest.TestPage(t, "", false)
|
||||
countTest.TestPage(t, "?tab=repositories", false)
|
||||
countTest.TestPage(t, "-/projects", false)
|
||||
countTest.TestPage(t, "-/packages", false)
|
||||
countTest.TestPage(t, "?tab=activity", false)
|
||||
countTest.TestPage(t, "?tab=stars", false)
|
||||
}
|
||||
|
||||
func TestFrontendHeaderCountOrg(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
countTest := new(userCountTest)
|
||||
countTest.Init(t, 15, 17)
|
||||
|
||||
countTest.TestPage(t, "", false)
|
||||
countTest.TestPage(t, "-/projects", false)
|
||||
countTest.TestPage(t, "-/packages", false)
|
||||
countTest.TestPage(t, "members", true)
|
||||
countTest.TestPage(t, "teams", true)
|
||||
|
||||
countTest.TestPage(t, "settings", true)
|
||||
countTest.TestPage(t, "settings/hooks", true)
|
||||
countTest.TestPage(t, "settings/labels", true)
|
||||
countTest.TestPage(t, "settings/applications", true)
|
||||
countTest.TestPage(t, "settings/packages", true)
|
||||
countTest.TestPage(t, "settings/actions/runners", true)
|
||||
countTest.TestPage(t, "settings/actions/secrets", true)
|
||||
countTest.TestPage(t, "settings/actions/variables", true)
|
||||
countTest.TestPage(t, "settings/blocked_users", true)
|
||||
countTest.TestPage(t, "settings/delete", true)
|
||||
}
|
|
@ -141,6 +141,7 @@
|
|||
/* other colors */
|
||||
--color-gold: #b1983b;
|
||||
--color-white: #ffffff;
|
||||
--color-pure-black: #000000;
|
||||
--color-diff-removed-word-bg: #783030;
|
||||
--color-diff-added-word-bg: #255c39;
|
||||
--color-diff-removed-row-bg: #432121;
|
||||
|
@ -304,7 +305,7 @@ i.grey.icon.icon.icon.icon {
|
|||
}
|
||||
::selection {
|
||||
background: var(--steel-100) !important;
|
||||
color: var(--color-white) !important;
|
||||
color: var(--color-pure-black) !important;
|
||||
}
|
||||
strong.attention-important, svg.attention-important {
|
||||
color: var(--color-violet-light);
|
||||
|
|
Loading…
Reference in a new issue