Skip to content

Commit

Permalink
#1320 Git Branch result
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 8, 2024
1 parent a964817 commit 46555b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import java.util.function.BiConsumer

@Component
class GitBranchSearchIndexer(
extensionFeature: GitExtensionFeature,
private val gitService: GitService,
private val structureService: StructureService,
private val uriBuilder: EntityURIBuilder
extensionFeature: GitExtensionFeature,
private val gitService: GitService,
private val structureService: StructureService,
private val uriBuilder: EntityURIBuilder
) : SearchIndexer<GitBranchSearchItem> {

override val searchResultType = SearchResultType(
feature = extensionFeature.featureDescription,
id = "git-branch",
name = "Git Branch",
description = "Git branch associated to an Ontrack branch"
feature = extensionFeature.featureDescription,
id = "git-branch",
name = "Git Branch",
description = "Git branch associated to an Ontrack branch"
)

override val indexerName: String = "Git Branches"
Expand All @@ -36,7 +36,7 @@ class GitBranchSearchIndexer(
override fun indexAll(processor: (GitBranchSearchItem) -> Unit) {
gitService.forEachConfiguredBranch(BiConsumer { branch, branchConfig ->
processor(
GitBranchSearchItem(branch, branchConfig)
GitBranchSearchItem(branch, branchConfig)
)
})
}
Expand All @@ -47,32 +47,40 @@ class GitBranchSearchIndexer(
val branchConfig = branch?.let { gitService.getBranchConfiguration(branch) }
return if (branch != null && branchConfig != null) {
SearchResult(
title = branch.entityDisplayName,
description = "Git branch ${branchConfig.branch}",
uri = uriBuilder.getEntityURI(branch),
page = uriBuilder.getEntityPage(branch),
accuracy = score,
type = searchResultType
title = branch.entityDisplayName,
description = "Git branch ${branchConfig.branch}",
uri = uriBuilder.getEntityURI(branch),
page = uriBuilder.getEntityPage(branch),
accuracy = score,
type = searchResultType,
data = mapOf(
SearchResult.SEARCH_RESULT_BRANCH to branch,
SEARCH_RESULT_GIT_BRANCH to branchConfig.branch,
),
)
} else null
}

companion object {
const val SEARCH_RESULT_GIT_BRANCH = "gitBranch"
}
}

const val GIT_BRANCH_SEARCH_INDEX = "git-branch"

class GitBranchSearchItem(
val branchId: Int,
val gitBranch: String
val branchId: Int,
val gitBranch: String
) : SearchItem {

constructor(branch: Branch, branchConfig: GitBranchConfiguration) : this(
branchId = branch.id(),
gitBranch = branchConfig.branch
branchId = branch.id(),
gitBranch = branchConfig.branch
)

override val id: String = branchId.toString()

override val fields: Map<String, Any?> = asMap(
this::gitBranch
this::gitBranch
)
}
16 changes: 14 additions & 2 deletions ontrack-web-core/components/framework/search/git-branch/Result.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import SearchResultComponent from "@components/framework/search/SearchResultComponent";
import BranchLink from "@components/branches/BranchLink";
import {Space, Typography} from "antd";
import ProjectLink from "@components/projects/ProjectLink";

export default function Result({data}) {
return <SearchResultComponent
title="TODO"
description={JSON.stringify(data)}
title={
<>
<Space>
<Typography.Text strong code>{data.gitBranch}</Typography.Text>
<ProjectLink project={data.branch.project}/>
<Typography.Text type="secondary">/</Typography.Text>
<BranchLink branch={data.branch}/>
</Space>
</>
}
description={data.branch.description}
/>
}

0 comments on commit 46555b2

Please sign in to comment.