tags:

views:

85

answers:

2

I am currently trying to write a little powershell script (I have no experience in Powershell scripting so was wanting to use this as a test) that loops through our svn repositories counting how many commits have been made with a comment of "Reviewed by; No-one" as this indicates an unreviewed commit.

I currently have the following

$repositorys = @("Path1", "path2","path3","path4")
$matches = 0
foreach ($path in $repositorys){
"Path: {0}" -f $path.tostring() 
( [xml] (svn log --xml $path)).log.logentry | Where-Object {$_.msg -imatch "(Reviewed By: (no(.*)one))" } | measure-object | format-list

}

This gives me the output with the count depending on how many matches it has found

          Count Average             Sum                 Maximum             Minimum             Property
          ----- -------             ---                 -------             -------             --------
              1

If I remove the measure-object then I get the details of the SVN commit (revision, author, message, date etc.)

Essentially what I want to be able to report is the number of un-reviewed commits and there details (so essentially a merge between the two methods described above). So I have report that looks like

Path1:

Number of un-reviewed commits: xx
   Revision             Author
   --------             ------- 
    x                    x

Can anyone enlighten me?? Is this possible?

+2  A: 

well, in that case you'd have to output two different things. I'd suggest you save the result of the pipeline that does the work in a variable and then do something like the following:

$x = ( [xml] (svn log --xml $path)).log.logentry | Where-Object {$_.msg -imatch "(Reviewed By: (no(.*)one))" }

Write-Host Number of un-reviewed commits: ($x.Count)
$x | fl

So you just output the number and then just drop your collection from the pipeline to print it.

Joey
+4  A: 

This is what the Tee-Object cmdlet is for.

[xml] (svn log --xml $path)).log.logentry | 
    ? {$_.msg -imatch "(Reviewed By: (no(.*)one))" } | 
    tee -variable temp | 
    measure |
    % { "Number of un-reviewed commits: $($_.count)" }
$temp | fl

There's nothing here you can't do by manually breaking up the pipeline & assigning variables, but "tee" is a handy shortcut to know.

Its other common use is to write intermediate results to a file. See 'help tee -examples' for details.

Richard Berg