diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index e64fee1958..b14678056b 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -429,7 +429,7 @@ func prepareMigrationTasks() []*migration { newMigration(349, "Add security scanning tables", v1_27.AddSecurityScanningTables), newMigration(350, "Add issue type definitions table", v1_27.AddIssueTypeDefTable), newMigration(351, "Add CDN public flag to attachments", v1_27.AddAttachmentCDNPublic), - newMigration(352, "Add version prefix to repo manifest", v1_27.AddManifestVersionPrefix), + newMigration(352, "Add version prefix and element name to repo manifest", v1_27.AddManifestVersionPrefixAndElement), } return preparedMigrations } diff --git a/models/migrations/v1_27/v353.go b/models/migrations/v1_27/v353.go index 35fe2ffd64..3ab08b8467 100644 --- a/models/migrations/v1_27/v353.go +++ b/models/migrations/v1_27/v353.go @@ -5,10 +5,11 @@ package v1_27 import "xorm.io/xorm" -// AddManifestVersionPrefix adds the version_prefix column to the repo_manifest table. -func AddManifestVersionPrefix(x *xorm.Engine) error { +// AddManifestVersionPrefixAndElement adds version_prefix and element_name columns to repo_manifest. +func AddManifestVersionPrefixAndElement(x *xorm.Engine) error { type RepoManifest struct { VersionPrefix string `xorm:"TEXT 'version_prefix'"` + ElementName string `xorm:"TEXT 'element_name'"` } return x.Sync(new(RepoManifest)) } diff --git a/models/repo/repo_manifest.go b/models/repo/repo_manifest.go index e2ab8d6a3e..fe3f6e2e79 100644 --- a/models/repo/repo_manifest.go +++ b/models/repo/repo_manifest.go @@ -35,7 +35,8 @@ type RepoManifest struct { StandardsSource string `xorm:"TEXT 'standards_source'"` // URL to standards repo // versioning - VersionPrefix string `xorm:"TEXT 'version_prefix'"` // tag prefix stripped for version display, e.g. "v1.26.1-moko." + VersionPrefix string `xorm:"TEXT 'version_prefix'"` // tag prefix stripped for version display, e.g. "v1.26.1-moko." + ElementName string `xorm:"TEXT 'element_name'"` // full element name override, e.g. "pkg_mokowaas" (auto-constructed if empty) // build section Language string `xorm:"VARCHAR(50) 'language'"` // Go, PHP, TypeScript, etc. @@ -50,6 +51,45 @@ func (RepoManifest) TableName() string { return "repo_manifest" } +// joomlaTypePrefix maps Joomla extension types to their element name prefixes. +var joomlaTypePrefix = map[string]string{ + "component": "com_", + "module": "mod_", + "plugin": "plg_", + "package": "pkg_", + "template": "tpl_", + "library": "lib_", + "file": "file_", +} + +// AutoElementName returns the auto-constructed Joomla element name (e.g. pkg_mokowaas). +func (m *RepoManifest) AutoElementName() string { + if m.Name == "" || m.PackageType == "" { + return "" + } + if prefix, ok := joomlaTypePrefix[m.PackageType]; ok { + return prefix + m.Name + } + return m.Name +} + +// FullElementName returns the effective element name: override if set, otherwise auto-constructed. +func (m *RepoManifest) FullElementName() string { + if m.ElementName != "" { + return m.ElementName + } + return m.AutoElementName() +} + +// ElementNameMismatch returns true if an override is set that differs from the auto-constructed name. +func (m *RepoManifest) ElementNameMismatch() bool { + if m.ElementName == "" { + return false + } + auto := m.AutoElementName() + return auto != "" && m.ElementName != auto +} + // GetRepoManifest returns the manifest for a repo, or nil if none exists. func GetRepoManifest(ctx context.Context, repoID int64) (*RepoManifest, error) { m := new(RepoManifest) diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 96899564ee..424a899b2b 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -2737,6 +2737,12 @@ "repo.settings.manifest_desc": "Project identity, governance, and build settings from the MokoPlatform manifest. These are accessible via API for Actions workflows and the MokoPlatform CLI.", "repo.settings.manifest_identity": "Identity", "repo.settings.manifest_name": "Project Name", + "repo.settings.manifest_element_name": "Element Name", + "repo.settings.manifest_element_name_help": "Base name used to construct the Joomla element identifier (e.g. 'mokowaas'). Combined with the extension type to produce the full element name.", + "repo.settings.manifest_element_full": "Full Element Name", + "repo.settings.manifest_element_full_help": "Auto-constructed from type + name. Leave blank to use the default, or override for non-standard naming.", + "repo.settings.manifest_element_mismatch": "Warning: this overrides the auto-constructed name '%s'. Make sure this matches your Joomla extension's element identifier.", + "repo.settings.manifest_package_type_help": "Maps to the Joomla extension type and determines the element prefix (com_, mod_, plg_, pkg_, tpl_, lib_, file_).", "repo.settings.manifest_org": "Organization", "repo.settings.manifest_description": "Description", "repo.settings.manifest_version": "Version", diff --git a/routers/api/v1/repo/manifest.go b/routers/api/v1/repo/manifest.go index 2026d06803..8b3fb5a8d5 100644 --- a/routers/api/v1/repo/manifest.go +++ b/routers/api/v1/repo/manifest.go @@ -20,6 +20,7 @@ type apiManifest struct { LicenseSPDX string `json:"license_spdx"` LicenseName string `json:"license_name"` VersionPrefix string `json:"version_prefix"` + ElementName string `json:"element_name"` Platform string `json:"platform"` StandardsVersion string `json:"standards_version"` StandardsSource string `json:"standards_source"` @@ -62,6 +63,7 @@ func GetRepoManifest(ctx *context.APIContext) { LicenseSPDX: m.LicenseSPDX, LicenseName: m.LicenseName, VersionPrefix: m.VersionPrefix, + ElementName: m.FullElementName(), Platform: m.Platform, StandardsVersion: m.StandardsVersion, StandardsSource: m.StandardsSource, @@ -98,6 +100,7 @@ func UpdateRepoManifest(ctx *context.APIContext) { LicenseSPDX: req.LicenseSPDX, LicenseName: req.LicenseName, VersionPrefix: req.VersionPrefix, + ElementName: req.ElementName, Platform: req.Platform, StandardsVersion: req.StandardsVersion, StandardsSource: req.StandardsSource, @@ -119,6 +122,7 @@ func UpdateRepoManifest(ctx *context.APIContext) { LicenseSPDX: m.LicenseSPDX, LicenseName: m.LicenseName, VersionPrefix: m.VersionPrefix, + ElementName: m.FullElementName(), Platform: m.Platform, StandardsVersion: m.StandardsVersion, StandardsSource: m.StandardsSource, diff --git a/routers/web/repo/setting/manifest.go b/routers/web/repo/setting/manifest.go index 26942a1e3f..a58ad85e5e 100644 --- a/routers/web/repo/setting/manifest.go +++ b/routers/web/repo/setting/manifest.go @@ -94,6 +94,7 @@ func ManifestSettingsPost(ctx *context.Context) { LicenseSPDX: ctx.FormString("license_spdx"), LicenseName: ctx.FormString("license_name"), VersionPrefix: ctx.FormString("version_prefix"), + ElementName: ctx.FormString("element_name"), Platform: ctx.FormString("platform"), StandardsVersion: ctx.FormString("standards_version"), StandardsSource: ctx.FormString("standards_source"), diff --git a/templates/repo/settings/manifest.tmpl b/templates/repo/settings/manifest.tmpl index 68aeb2dbf2..7630bf2ed8 100644 --- a/templates/repo/settings/manifest.tmpl +++ b/templates/repo/settings/manifest.tmpl @@ -11,8 +11,14 @@
{{ctx.Locale.Tr "repo.settings.manifest_element_name_help"}}
+ {{else}} + + + {{end}}{{ctx.Locale.Tr "repo.settings.manifest_package_type_help"}}
+{{ctx.Locale.Tr "repo.settings.manifest_element_mismatch" .Manifest.AutoElementName}}
+ {{else}} +{{ctx.Locale.Tr "repo.settings.manifest_element_full_help"}}
+ {{end}}