Skip to content

Added possibility to filter repositories by project for Code-ReIndexing #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Azure_DevOps_Server_2019/Re-IndexingCodeRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ Param(
[string]$CollectionName,

[Parameter(Mandatory=$True, Position=5, HelpMessage="Update the tfvc/git repository name here.")]
[string]$RepositoryName
)
[string]$RepositoryName,

[Parameter(Mandatory=$False, Position=5, HelpMessage="Set the name for the project of the repository here if there are multiple repositories with the same name.")]
[string]$ProjectName=""
)

Import-Module .\Common.psm1 -Force

Expand All @@ -27,9 +30,13 @@ ImportSQLModule

$CollectionID = ValidateCollectionName $SQLServerInstance $ConfigurationDatabaseName $CollectionName

if([string]::IsNullOrWhiteSpace($ProjectName)) {
$ProjectName = "" # make sure it's just an empty string if project name is null or whitespace
}

if(IsExtensionInstalled $SQLServerInstance $CollectionDatabaseName "IsCollectionIndexed")
{
$addDataParams = "IndexingUnitType='$IndexingUnitType'","CollectionId='$CollectionID'","RepositoryName='$RepositoryName'","RepositoryType='$IndexingUnitType'"
$addDataParams = "IndexingUnitType='$IndexingUnitType'","CollectionId='$CollectionID'","RepositoryName='$RepositoryName'","RepositoryType='$IndexingUnitType'","ProjectName='$ProjectName'"
$SqlFullPath = Join-Path $PWD -ChildPath 'SqlScripts\AddCodeRe-IndexingJobData.sql'
Invoke-Sqlcmd -InputFile $SqlFullPath -serverInstance $SQLServerInstance -database $CollectionDatabaseName -Variable $addDataParams
Write-Host "Added the job data as '$addDataParams'" -ForegroundColor Cyan
Expand Down
30 changes: 27 additions & 3 deletions Azure_DevOps_Server_2019/SqlScripts/AddCodeRe-IndexingJobData.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,37 @@ DECLARE @RepositoryName nvarchar(max) = $(RepositoryName)
-- Update the type of repository, use 'Git_Repository' for git repos and 'TFVC_Repository' for TFVC projects.
DECLARE @RepositoryType varchar(30) = $(RepositoryType)

-- **UPDATE**
-- Set the name for the project of the repository here if there are multiple repositories with the same name, this can be any string.
DECLARE @ProjectName nvarchar(max) = $(ProjectName)

DECLARE @CollectionId uniqueidentifier = $(CollectionId)
DECLARE @RepositoryId varchar(50)
if(@IndexingUnitType <> 'Collection')
BEGIN
SELECT @RepositoryId = TFSEntityId from Search.tbl_IndexingUnit
where TFSEntityAttributes Like '%<RepositoryName>'+@RepositoryName+'</RepositoryName>%' and IndexingUnitType Like '%Repository%'
and PartitionId > 0
if(@ProjectName <> '')
BEGIN
SELECT @RepositoryId = TFSEntityId
from [Search].[tbl_IndexingUnit] siu
inner join [dbo].[tbl_GitRepository] grp
on siu.PartitionId = grp.PartitionId
and siu.TFSEntityId = grp.RepositoryId
and siu.EntityType = 'Code'
inner join [dbo].[tbl_Dataspace] dsp
on grp.PartitionId = dsp.PartitionId
and grp.DataspaceId = dsp.DataspaceId
inner join [dbo].[tbl_projects] prj
on dsp.PartitionId = prj.PartitionId
and dsp.[DataspaceIdentifier] = prj.[project_id]
where grp.Name = @RepositoryName and IndexingUnitType Like '%Repository%' and prj.project_Name = @ProjectName
and siu.PartitionId > 0
END
ELSE
BEGIN
SELECT @RepositoryId = TFSEntityId from Search.tbl_IndexingUnit
where TFSEntityAttributes Like '%<RepositoryName>'+@RepositoryName+'</RepositoryName>%' and IndexingUnitType Like '%Repository%'
and PartitionId > 0
END

if(@RepositoryId is null)
BEGIN
Expand Down