mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-10 07:32:04 +02:00
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-show
This commit is contained in:
commit
646d2c3c22
@ -17,6 +17,7 @@ insert_final_newline = false
|
|||||||
|
|
||||||
[templates/swagger/v1_json.tmpl]
|
[templates/swagger/v1_json.tmpl]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
insert_final_newline = false
|
||||||
|
|
||||||
[templates/user/auth/oidc_wellknown.tmpl]
|
[templates/user/auth/oidc_wellknown.tmpl]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
|||||||
1
.github/workflows/files-changed.yml
vendored
1
.github/workflows/files-changed.yml
vendored
@ -85,6 +85,7 @@ jobs:
|
|||||||
|
|
||||||
swagger:
|
swagger:
|
||||||
- "templates/swagger/v1_json.tmpl"
|
- "templates/swagger/v1_json.tmpl"
|
||||||
|
- "templates/swagger/v1_input.json"
|
||||||
- "Makefile"
|
- "Makefile"
|
||||||
- "package.json"
|
- "package.json"
|
||||||
- "package-lock.json"
|
- "package-lock.json"
|
||||||
|
|||||||
17
Makefile
17
Makefile
@ -165,10 +165,8 @@ ifdef DEPS_PLAYWRIGHT
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
|
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
|
||||||
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g
|
SWAGGER_SPEC_INPUT := templates/swagger/v1_input.json
|
||||||
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
|
|
||||||
SWAGGER_EXCLUDE := code.gitea.io/sdk
|
SWAGGER_EXCLUDE := code.gitea.io/sdk
|
||||||
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
|
|
||||||
|
|
||||||
TEST_MYSQL_HOST ?= mysql:3306
|
TEST_MYSQL_HOST ?= mysql:3306
|
||||||
TEST_MYSQL_DBNAME ?= testgitea
|
TEST_MYSQL_DBNAME ?= testgitea
|
||||||
@ -271,10 +269,8 @@ endif
|
|||||||
.PHONY: generate-swagger
|
.PHONY: generate-swagger
|
||||||
generate-swagger: $(SWAGGER_SPEC) ## generate the swagger spec from code comments
|
generate-swagger: $(SWAGGER_SPEC) ## generate the swagger spec from code comments
|
||||||
|
|
||||||
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
|
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA) $(SWAGGER_SPEC_INPUT)
|
||||||
$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
|
$(GO) run $(SWAGGER_PACKAGE) generate spec --exclude "$(SWAGGER_EXCLUDE)" --input "$(SWAGGER_SPEC_INPUT)" --output './$(SWAGGER_SPEC)'
|
||||||
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
|
|
||||||
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
|
|
||||||
|
|
||||||
.PHONY: swagger-check
|
.PHONY: swagger-check
|
||||||
swagger-check: generate-swagger
|
swagger-check: generate-swagger
|
||||||
@ -287,9 +283,11 @@ swagger-check: generate-swagger
|
|||||||
|
|
||||||
.PHONY: swagger-validate
|
.PHONY: swagger-validate
|
||||||
swagger-validate: ## check if the swagger spec is valid
|
swagger-validate: ## check if the swagger spec is valid
|
||||||
$(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
|
@# swagger "validate" requires that the "basePath" must start with a slash, but we are using Golang template "{{...}}"
|
||||||
|
@$(SED_INPLACE) -E -e 's|"basePath":( *)"(.*)"|"basePath":\1"/\2"|g' './$(SWAGGER_SPEC)' # add a prefix slash to basePath
|
||||||
|
@# FIXME: there are some warnings
|
||||||
$(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
|
$(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
|
||||||
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
|
@$(SED_INPLACE) -E -e 's|"basePath":( *)"/(.*)"|"basePath":\1"\2"|g' './$(SWAGGER_SPEC)' # remove the prefix slash from basePath
|
||||||
|
|
||||||
.PHONY: checks
|
.PHONY: checks
|
||||||
checks: checks-frontend checks-backend ## run various consistency checks
|
checks: checks-frontend checks-backend ## run various consistency checks
|
||||||
@ -380,6 +378,7 @@ lint-go-gopls: ## lint go files with gopls
|
|||||||
|
|
||||||
.PHONY: lint-editorconfig
|
.PHONY: lint-editorconfig
|
||||||
lint-editorconfig:
|
lint-editorconfig:
|
||||||
|
@echo "Running editorconfig check..."
|
||||||
@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)
|
@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)
|
||||||
|
|
||||||
.PHONY: lint-actions
|
.PHONY: lint-actions
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
packages_model "code.gitea.io/gitea/models/packages"
|
packages_model "code.gitea.io/gitea/models/packages"
|
||||||
maven_module "code.gitea.io/gitea/modules/packages/maven"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MetadataResponse https://maven.apache.org/ref/3.2.5/maven-repository-metadata/repository-metadata.html
|
// MetadataResponse https://maven.apache.org/ref/3.2.5/maven-repository-metadata/repository-metadata.html
|
||||||
@ -22,7 +21,7 @@ type MetadataResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pds is expected to be sorted ascending by CreatedUnix
|
// pds is expected to be sorted ascending by CreatedUnix
|
||||||
func createMetadataResponse(pds []*packages_model.PackageDescriptor) *MetadataResponse {
|
func createMetadataResponse(pds []*packages_model.PackageDescriptor, groupID, artifactID string) *MetadataResponse {
|
||||||
var release *packages_model.PackageDescriptor
|
var release *packages_model.PackageDescriptor
|
||||||
|
|
||||||
versions := make([]string, 0, len(pds))
|
versions := make([]string, 0, len(pds))
|
||||||
@ -35,11 +34,9 @@ func createMetadataResponse(pds []*packages_model.PackageDescriptor) *MetadataRe
|
|||||||
|
|
||||||
latest := pds[len(pds)-1]
|
latest := pds[len(pds)-1]
|
||||||
|
|
||||||
metadata := latest.Metadata.(*maven_module.Metadata)
|
|
||||||
|
|
||||||
resp := &MetadataResponse{
|
resp := &MetadataResponse{
|
||||||
GroupID: metadata.GroupID,
|
GroupID: groupID,
|
||||||
ArtifactID: metadata.ArtifactID,
|
ArtifactID: artifactID,
|
||||||
Latest: latest.Version.Version,
|
Latest: latest.Version.Version,
|
||||||
Version: versions,
|
Version: versions,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,20 +84,19 @@ func handlePackageFile(ctx *context.Context, serveContent bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func serveMavenMetadata(ctx *context.Context, params parameters) {
|
func serveMavenMetadata(ctx *context.Context, params parameters) {
|
||||||
// /com/foo/project/maven-metadata.xml[.md5/.sha1/.sha256/.sha512]
|
// path pattern: /com/foo/project/maven-metadata.xml[.md5/.sha1/.sha256/.sha512]
|
||||||
|
// in case there are legacy package names ("GroupID-ArtifactID") we need to check both, new packages always use ":" as separator("GroupID:ArtifactID")
|
||||||
pvs, err := packages_model.GetVersionsByPackageName(ctx, ctx.Package.Owner.ID, packages_model.TypeMaven, params.toInternalPackageName())
|
pvsLegacy, err := packages_model.GetVersionsByPackageName(ctx, ctx.Package.Owner.ID, packages_model.TypeMaven, params.toInternalPackageNameLegacy())
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
|
||||||
pvs, err = packages_model.GetVersionsByPackageName(ctx, ctx.Package.Owner.ID, packages_model.TypeMaven, params.toInternalPackageNameLegacy())
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(pvs) == 0 {
|
pvs, err := packages_model.GetVersionsByPackageName(ctx, ctx.Package.Owner.ID, packages_model.TypeMaven, params.toInternalPackageName())
|
||||||
apiError(ctx, http.StatusNotFound, packages_model.ErrPackageNotExist)
|
if err != nil {
|
||||||
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
pvs = append(pvsLegacy, pvs...)
|
||||||
|
|
||||||
pds, err := packages_model.GetPackageDescriptors(ctx, pvs)
|
pds, err := packages_model.GetPackageDescriptors(ctx, pvs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -110,7 +109,7 @@ func serveMavenMetadata(ctx *context.Context, params parameters) {
|
|||||||
return pds[i].Version.CreatedUnix < pds[j].Version.CreatedUnix
|
return pds[i].Version.CreatedUnix < pds[j].Version.CreatedUnix
|
||||||
})
|
})
|
||||||
|
|
||||||
xmlMetadata, err := xml.Marshal(createMetadataResponse(pds))
|
xmlMetadata, err := xml.Marshal(createMetadataResponse(pds, params.GroupID, params.ArtifactID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -7,8 +7,6 @@
|
|||||||
// This documentation describes the Gitea API.
|
// This documentation describes the Gitea API.
|
||||||
//
|
//
|
||||||
// Schemes: https, http
|
// Schemes: https, http
|
||||||
// BasePath: /api/v1
|
|
||||||
// Version: {{AppVer | JSEscape}}
|
|
||||||
// License: MIT http://opensource.org/licenses/MIT
|
// License: MIT http://opensource.org/licenses/MIT
|
||||||
//
|
//
|
||||||
// Consumes:
|
// Consumes:
|
||||||
|
|||||||
6
templates/swagger/v1_input.json
Normal file
6
templates/swagger/v1_input.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"info": {
|
||||||
|
"version": "{{AppVer | JSEscape}}"
|
||||||
|
},
|
||||||
|
"basePath": "{{AppSubUrl | JSEscape}}/api/v1"
|
||||||
|
}
|
||||||
2
templates/swagger/v1_json.tmpl
generated
2
templates/swagger/v1_json.tmpl
generated
@ -27580,4 +27580,4 @@
|
|||||||
"TOTPHeader": []
|
"TOTPHeader": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -80,6 +80,7 @@ func TestPackageMaven(t *testing.T) {
|
|||||||
t.Run("UploadLegacy", func(t *testing.T) {
|
t.Run("UploadLegacy", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
// try to upload a package with legacy package name (will be saved as "GroupID-ArtifactID")
|
||||||
legacyRootLink := "/api/packages/user2/maven/com/gitea/legacy-project"
|
legacyRootLink := "/api/packages/user2/maven/com/gitea/legacy-project"
|
||||||
req := NewRequestWithBody(t, "PUT", legacyRootLink+"/1.0.2/any-file-name?use_legacy_package_name=1", strings.NewReader("test-content")).AddBasicAuth(user.Name)
|
req := NewRequestWithBody(t, "PUT", legacyRootLink+"/1.0.2/any-file-name?use_legacy_package_name=1", strings.NewReader("test-content")).AddBasicAuth(user.Name)
|
||||||
MakeRequest(t, req, http.StatusCreated)
|
MakeRequest(t, req, http.StatusCreated)
|
||||||
@ -97,6 +98,13 @@ func TestPackageMaven(t *testing.T) {
|
|||||||
req = NewRequest(t, "GET", "/user2/-/packages/maven/com.gitea%3Alegacy-project/1.0.2")
|
req = NewRequest(t, "GET", "/user2/-/packages/maven/com.gitea%3Alegacy-project/1.0.2")
|
||||||
MakeRequest(t, req, http.StatusNotFound)
|
MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
|
||||||
|
// legacy package names should also be able to be listed
|
||||||
|
req = NewRequest(t, "GET", legacyRootLink+"/maven-metadata.xml").AddBasicAuth(user.Name)
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
respBody := resp.Body.String()
|
||||||
|
assert.Contains(t, respBody, "<version>1.0.2</version>")
|
||||||
|
|
||||||
|
// then upload a package with correct package name (will be saved as "GroupID:ArtifactID")
|
||||||
req = NewRequestWithBody(t, "PUT", legacyRootLink+"/1.0.3/any-file-name", strings.NewReader("test-content")).AddBasicAuth(user.Name)
|
req = NewRequestWithBody(t, "PUT", legacyRootLink+"/1.0.3/any-file-name", strings.NewReader("test-content")).AddBasicAuth(user.Name)
|
||||||
MakeRequest(t, req, http.StatusCreated)
|
MakeRequest(t, req, http.StatusCreated)
|
||||||
_, err = packages.GetPackageByName(db.DefaultContext, user.ID, packages.TypeMaven, "com.gitea-legacy-project")
|
_, err = packages.GetPackageByName(db.DefaultContext, user.ID, packages.TypeMaven, "com.gitea-legacy-project")
|
||||||
@ -114,6 +122,12 @@ func TestPackageMaven(t *testing.T) {
|
|||||||
req = NewRequest(t, "GET", "/user2/-/packages/maven/com.gitea%3Alegacy-project/1.0.2")
|
req = NewRequest(t, "GET", "/user2/-/packages/maven/com.gitea%3Alegacy-project/1.0.2")
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
// now 2 packages should be listed
|
||||||
|
req = NewRequest(t, "GET", legacyRootLink+"/maven-metadata.xml").AddBasicAuth(user.Name)
|
||||||
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
respBody = resp.Body.String()
|
||||||
|
assert.Contains(t, respBody, "<version>1.0.2</version>")
|
||||||
|
assert.Contains(t, respBody, "<version>1.0.3</version>")
|
||||||
require.NoError(t, packages.DeletePackageByID(db.DefaultContext, p.ID))
|
require.NoError(t, packages.DeletePackageByID(db.DefaultContext, p.ID))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
7
web_src/js/features/repo-common.test.ts
Normal file
7
web_src/js/features/repo-common.test.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import {substituteRepoOpenWithUrl} from './repo-common.ts';
|
||||||
|
|
||||||
|
test('substituteRepoOpenWithUrl', () => {
|
||||||
|
// For example: "x-github-client://openRepo/https://github.com/go-gitea/gitea"
|
||||||
|
expect(substituteRepoOpenWithUrl('proto://a/{url}', 'https://gitea')).toEqual('proto://a/https://gitea');
|
||||||
|
expect(substituteRepoOpenWithUrl('proto://a?link={url}', 'https://gitea')).toEqual('proto://a?link=https%3A%2F%2Fgitea');
|
||||||
|
});
|
||||||
@ -42,6 +42,14 @@ export function initRepoActivityTopAuthorsChart() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function substituteRepoOpenWithUrl(tmpl: string, url: string): string {
|
||||||
|
const pos = tmpl.indexOf('{url}');
|
||||||
|
if (pos === -1) return tmpl;
|
||||||
|
const posQuestionMark = tmpl.indexOf('?');
|
||||||
|
const needEncode = posQuestionMark >= 0 && posQuestionMark < pos;
|
||||||
|
return tmpl.replace('{url}', needEncode ? encodeURIComponent(url) : url);
|
||||||
|
}
|
||||||
|
|
||||||
function initCloneSchemeUrlSelection(parent: Element) {
|
function initCloneSchemeUrlSelection(parent: Element) {
|
||||||
const elCloneUrlInput = parent.querySelector<HTMLInputElement>('.repo-clone-url');
|
const elCloneUrlInput = parent.querySelector<HTMLInputElement>('.repo-clone-url');
|
||||||
|
|
||||||
@ -70,7 +78,7 @@ function initCloneSchemeUrlSelection(parent: Element) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const el of parent.querySelectorAll<HTMLAnchorElement>('.js-clone-url-editor')) {
|
for (const el of parent.querySelectorAll<HTMLAnchorElement>('.js-clone-url-editor')) {
|
||||||
el.href = el.getAttribute('data-href-template').replace('{url}', encodeURIComponent(link));
|
el.href = substituteRepoOpenWithUrl(el.getAttribute('data-href-template'), link);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user