Skip to content

iRaindrop/RepoFind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RepoFind

This project has scripts for searching and managing repository content, markdown files, and metadata. The script produces two types of output:

  • Metadata
  • Search results

If no arguments are specified, a metadata report is run that creates RepoFindMetadata.csv. If a search string is specified as an argument (only one argument is permitted) a search results report is run that creates RepoFindResults.csv.

This script creates CSV files containing the search results or metadata for one or more repository folders. The script acts recursively on subfolders on all Markdown .md files.

Set up

Save RepoFind.ps1, RepoLog.ps1, and RFconfig.xml to a folder and do the following:

  • Set execution policy.
  • Configure RFConfig.xml.
  • Configure and run RepoLog.ps1.

Set execution policy

In PowerShell, you might have to set your execution policy:

PS C:\RFind> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Configure RFConfig.xml

<?xml version="1.0"?>
<configuration>
  <startup>
   <installdir key="dirR" value="c:\Repos"/>
   <logfiledir key="dirL" value="c:\Logs"/>
  </startup>
  <srchFolders>
    <folder key="fld1" value="selfhelpcontent\articles\microsoft.virtualmachines.rca.tdp"/>
    <folder key="fld2" value="selfhelpcontent\articles\microsoft.virtualmachine.rca.restarts"/>
  </srchFolders>
</configuration>

The text specified for the key does not matter, only the values specified for value are processed.

  • For the installdir value, specify the folder that contains your local repository folders. You can leave this value as an empty string if you're installing by default into your home account under c:\users\yourname\.
  • For the logfiledir values, specify a folder that contains the files output from RepoLog.ps1.
  • For the srchFolders node, add a folder element for each folder of the repository you want to search. The searches are recursive, you only need one element with selfhelpcontent\articles as the value.

Configure and run RepoLog.ps1

This script runs the git log command on repository files and outputs the results to a specfied directory. In the RepoFind.ps1 script, the Get-DateFromLog function reads the third line from the top of each log file to parse the date when the file was last updated.

If a log file is not available to get the date for a file, an empty string is returned.

Set values at the top of the script:

$logPath = "C:\Logs"
$repoTop = "c:\Repos\SelfhelpContent"

$sources = New-Object 'System.Collections.Generic.List[string]'
$sources.Add("C:\Repos\SelfHelpContent\articles\microsoft.virtualmachine.rca.restarts")
$sources.Add("C:\Repos\SelfHelpContent\articles\microsoft.virtualmachines.rca.tdp")
  • For the $logPath value, specify the folder to contain the log files generated by the script.
  • For the $repoTop value, specify the root of your repo. The script need to set its location here to access git.
  • Add a path to the $sources collection for each folder you want to process.
  • Run the script.

The script works recursively, so you could just specify the root of your repo as the only element in the $sources collection to get a log of each markdown file, but that might take a long time.

Run RepoFind.ps1

The script creates two types of reports: RepoFindMetadata.csv or RepoFindResults.csv.

To report on metadata only, run the script without a parameter, for example:

PS C:\RFind> .\RepoFind.ps1

To search for text, include the search string as the only parameter.

PS C:\RFind> .\RepoFind.ps1 "deploy a vm"

The files are written to the folder that contains the script. You are alerted to the number of occurrences or if no results were found.

Manage reporting for metadata properties

To add a metadata property for reporting, add a property for it to the RData or RFind class.

For the Data (RData) report, add an elseif clause to the if ($inProps) block (~ ln 234) to detect if the desired property name is on the current line ($line), such as shown here to detect description and articleId:

if ($inProps) {
    # Get values for metadata properties using the Get-PropValue
    # function defined above. To get values for other properties
    # add code for it here and add to the $data class.
    if ($line.Contains("description=")) {
        $data.Description = Get-PropValue $line
    }
    elseif ($line.Contains("articleId=")) {
        $data.ArticleId = Get-PropValue $line
    }               
}

Next, the script calls the Get-PropValue funtion that parases the metadata property value from current line and sets the result to its associated property on the class.

Do similar for the Search Results (RFind) report (~ ln. 295).

if ($inProps) {
    # Get values for metadata properties using the Get-PropValue
    # function defined above. To get values for other properties
    # add code for it here and add to the $data class. Use elseif
    # for subsequent properties.
    if ($line.Contains("articleId=")) {
        $metaArticleID = Get-PropValue $line
    }               
}

But for this report, the value is set to a temporary variable, $metaArticleID, as it not known at this point if a there is a search hit to create a new RFind object. So it's set on the object a few lines down (~ ln 309):

# Create data object and set properties
  $hit = New-Object "RFind"
  $hit.ArticleId = $metaArticleID

Note that metdata property values are case sensitive.

About

Scripts for searching metadata and content in repository files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published