Skip to content

Commit

Permalink
More API and Healthcheckk work
Browse files Browse the repository at this point in the history
  • Loading branch information
richmahn committed Jan 1, 2025
1 parent ea67187 commit a983a38
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 19 deletions.
2 changes: 0 additions & 2 deletions models/door43metadata/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ type SearchCatalogOptions struct {
MetadataVersions []string
Topics []string
InvertedTopics []string
Healthchecks []string
ShowIngredients util.OptionalBool
Languages []string
LanguageIsGL util.OptionalBool
Expand Down Expand Up @@ -132,7 +131,6 @@ func SearchCatalogCondition(opts *SearchCatalogOptions) builder.Cond {
GetMetadataTypeCond(opts.MetadataTypes, opts.PartialMatch),
GetTopicCond(opts.Topics, opts.PartialMatch),
GetInvertedTopicCond(opts.InvertedTopics, opts.PartialMatch),
GetHealthcheckCond(opts.Healthchecks),
GetTagCond(opts.Tags),
repoCond,
ownerCond,
Expand Down
7 changes: 7 additions & 0 deletions models/repo/repo_dcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ package repo

import (
"context"
"net/url"

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/door43metadata"
"code.gitea.io/gitea/modules/dcs"
"code.gitea.io/gitea/modules/setting"

"xorm.io/builder"
)

// HealthcheckURL the api url for a repo's healthcheck
func (repo *Repository) RepoHealthcheckURL() string {
return setting.AppURL + "api/v1/repos/" + url.PathEscape(repo.OwnerName) + "/" + url.PathEscape(repo.Name) + "/healthcheck"
}

// LoadLatestDMs loads the latest DMs
func (repo *Repository) LoadLatestDMs(ctx context.Context) error {
if repo.LatestProdDM == nil {
Expand Down
1 change: 1 addition & 0 deletions modules/structs/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type CatalogEntry struct {
Books []string `json:"books,omitempty"`
IsValid bool `json:"is_valid"`
ValidationErrorsURL string `json:"validation_errors_url"`
HealthcheckSeverity string `json:"healthcheck_severity"`
}

// Ingredient is a single project of a resource
Expand Down
6 changes: 6 additions & 0 deletions modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type Repository struct {
// swagger:strfmt date-time
MirrorUpdated time.Time `json:"mirror_updated,omitempty"`
RepoTransfer *RepoTransfer `json:"repo_transfer"`
// topics
Topics []string `json:"topics"` // DCS Customizations
// language from the manifest
MetadataType string `json:"metadata_type"` // DCS Customiations
// language from the manifest
Expand Down Expand Up @@ -137,6 +139,10 @@ type Repository struct {
CatalogStages *CatalogStages `json:"catalog"` // DCS Customiations
// content format
ContentFormat string `json:"content_format"` // DCS Customizaitons
// healthcheck severity
HealthcheckSeverity string `json:"healthcheck_severity"` // DCS Customizations
// healthcheck URL
HealthcheckURL string `json:"healthcheck_url"` // DCS Customizations
}

// CreateRepoOption options when creating repository
Expand Down
11 changes: 1 addition & 10 deletions routers/api/v1/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,11 @@ func Search(ctx *context.APIContext) {
// type: string
// - name: invertedTopic
// in: query
// description: Inverted topic. Repos that do NOT have this topic will be returned. Multiple values are ANDed.
// description: Inverted topic. Entries with a repository that do NOT have this topic will be returned. Multiple values are ANDed.
// type: array
// collectionFormat: multi
// items:
// type: string
// - name: healthcheck
// in: query
// description: Healthcheck severity. Options are error, warning, info, success. Multiple values are ORed.
// type: array
// collectionFormat: multi
// items:
// type: string
// enum: [error,warning,info,success]
// - name: partialMatch
// in: query
// description: if true, subject, owner and repo search fields will use partial match (LIKE) when querying the catalog, default is false
Expand Down Expand Up @@ -1024,7 +1016,6 @@ func searchCatalog(ctx *context.APIContext) {
MetadataVersions: metadataVersions,
Topics: QueryStrings(ctx, "topic"),
InvertedTopics: QueryStrings(ctx, "invertedTopic"),
Healthchecks: QueryStrings(ctx, "healthcheck"),
PartialMatch: ctx.FormBool("partialMatch"),
}

Expand Down
6 changes: 3 additions & 3 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ func Search(ctx *context.APIContext) {
// type: string
// - name: invertedTopic
// in: query
// description: Inverted topic. Repos that do NOT have this topic will be returned. Multiple values are ANDed.
// description: Inverted topic. Repositories that do NOT have this topic will be returned. Multiple values are ANDed.
// type: array
// collectionFormat: multi
// items:
// type: string
// - name: healthcheck
// - name: healthcheckSeverity
// in: query
// description: Healthcheck severity. Options are error, warning, info, success. Multiple values are ORed.
// type: array
Expand Down Expand Up @@ -253,7 +253,7 @@ func Search(ctx *context.APIContext) {
MetadataVersions: catalog.QueryStrings(ctx, "metadataVersion"),
Topics: catalog.QueryStrings(ctx, "topic"),
InvertedTopics: catalog.QueryStrings(ctx, "invertedTopic"),
Healthchecks: catalog.QueryStrings(ctx, "healthcheck"),
Healthchecks: catalog.QueryStrings(ctx, "healthcheckSeverity"),
LanguageIsGL: ctx.FormOptionalBool("is_gl"),
PartialMatch: ctx.FormBool("partialMatch"),
/*** END DCS Customizations ***/
Expand Down
1 change: 0 additions & 1 deletion routers/web/dcs/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func RenderCatalogSearch(ctx *context.Context, opts *CatalogSearchOptions) {
MetadataVersions: searchMap["metadata_version"],
Topics: searchMap["topic"],
InvertedTopics: searchMap["topic_inverted"],
Healthchecks: searchMap["healthcheck"],
Tags: searchMap["tag"],
CheckingLevels: searchMap["checking_level"],
})
Expand Down
3 changes: 3 additions & 0 deletions services/convert/repository_dcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func ToRepoDCS(ctx context.Context, repo *repo_model.Repository, apiRepo *api.Re
apiRepo.LanguageIsGL = dm.LanguageIsGL
apiRepo.CheckingLevel = dm.CheckingLevel
apiRepo.ContentFormat = dm.ContentFormat
apiRepo.HealthcheckSeverity = dm.HealthcheckSeverity.String()
apiRepo.HealthcheckURL = repo.RepoHealthcheckURL()
apiRepo.MetadataType = dm.MetadataType
apiRepo.MetadataVersion = dm.MetadataVersion
apiRepo.Ingredients = dm.Ingredients
Expand All @@ -35,5 +37,6 @@ func ToRepoDCS(ctx context.Context, repo *repo_model.Repository, apiRepo *api.Re
PreProduction: ToCatalogStage(ctx, repo.LatestPreprodDM),
Latest: ToCatalogStage(ctx, repo.DefaultBranchDM),
}
apiRepo.Topics = repo.Topics
return apiRepo
}
8 changes: 5 additions & 3 deletions templates/repo/dcs_healthcheck_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
<div class="item-text">
{{RenderMarkdownToHtml $.Context $issue.Details}}
</div>
<div class="item-text">
{{RenderMarkdownToHtml $.Context $issue.Suggestion}}
</div>
{{if eq .Door43Metadata.RefType "branch"}}
<div class="item-text">
{{RenderMarkdownToHtml $.Context $issue.Suggestion}}
</div>
{{end}}
</div>
{{end}}
</div>
Expand Down
4 changes: 4 additions & 0 deletions templates/shared/searchbuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
const qInput = document.querySelector('[name="q"]');
const advancedSearchContainer = document.getElementById('search-builder');
const catalogOnlyFields = ['stage', 'tag'];
const repoOnlyFields = ['healthcheck'];
const searchFields = [
{ name: 'query', tooltip: 'queries repo name, owner, description & topics. Allows partial match' },
{ name: 'lang', tooltip: 'language code, e.g. en, fr' },
Expand Down Expand Up @@ -135,6 +136,9 @@
if (!isCatalogSearch && catalogOnlyFields.includes(fieldObj.name)) {
inputGroup.style.display = 'none';
}
if (isCatalogSearch && repoOnlyFields.includes(fieldObj.name)) {
inputGroup.style.display = 'none';
}
advancedSearchContainer.appendChild(inputGroup);
});
Expand Down

0 comments on commit a983a38

Please sign in to comment.