VSS Automation script
In our company we have a policy of creating a checkin mail that describes the files that you are checking in and what changes or bugs have been fixed in that checkin. The process of creating the mail involved opening VSS and then getting a list of all checked out files and then copying and pasting that to the mail. I've always wanted to get into windows scripting and i thought what better oppurtunity than this. So i wrote this small script that gets a list of all checked out files from VSS and then creates a new mail with the required info already filled in.
var oVss = new ActiveXObject("SourceSafe");
oVss.Open("<Insert path to srcsafe.ini>");
var oProj = oVss.VSSItem("<Insert project path e.g. $/");
var allProjects = new Array();
allProjects = GetAllProjects(oProj,allProjects);
var output = "";
var projItem;
var projEnumerator = new Enumerator(allProjects);
for (; !projEnumerator.atEnd() ; projEnumerator.moveNext() )
{
projItem = projEnumerator.item();
var checkouts = GetCheckedOutFiles(projItem);
if(checkouts.length > 0)
{
output += projItem.Spec + "\n";
var checkoutEnumerator = new Enumerator(checkouts);
for(;!checkoutEnumerator.atEnd();checkoutEnumerator.moveNext())
{
var checkoutItem = checkoutEnumerator.item();
output += "\t" + checkoutItem + "\n";
}
output += "\n";
}
}
var olApp = new ActiveXObject("Outlook.Application");
var mailItem = olApp.CreateItem(0 /*olMailItem*/);
mailItem.Recipients.Add("<Insert e-mail address to send mail to>");
mailItem.Body = "\n" + output;
mailItem.Display();
function GetCheckedOutFiles( projectItem )
{
var checkouts = new Array();
var itemEnumerator = new Enumerator(projectItem.items(false));
for(; !itemEnumerator.atEnd(); itemEnumerator.moveNext())
{
var item = itemEnumerator.item();
//File
if(item.Type == 1/*VSSITEM_FILE*/ && item.IsCheckedOut == 2 /*VSSFILE_CHECKEDOUT_ME*/)
{
checkouts.push(item.Name);
}
}
return checkouts;
}
function GetAllProjects( rootItem )
{
var projects = new Array();
var items = new Enumerator(rootItem.items(false));
for(;!items.atEnd();items.moveNext())
{
var item = items.item();
//Project
if(item.Type == 0 /*VSSITEM_PROJECT*/)
{
projects.push(item);
var subProjects = GetAllProjects(item);
var subProjectEnumerator = new Enumerator(subProjects);
for(;!subProjectEnumerator.atEnd();subProjectEnumerator.moveNext())
{
var subProjectItem = subProjectEnumerator.item();
projects.push(subProjectItem);
}
}
}
return projects;
}
function printItems(items, prop)
{
var itemEnumerator = new Enumerator(items);
for(;!itemEnumerator.atEnd();itemEnumerator.moveNext() )
{
var item = itemEnumerator.item();
WScript.Echo(item[prop]);
}
}
oVss.Open("<Insert path to srcsafe.ini>");
var oProj = oVss.VSSItem("<Insert project path e.g. $/");
var allProjects = new Array();
allProjects = GetAllProjects(oProj,allProjects);
var output = "";
var projItem;
var projEnumerator = new Enumerator(allProjects);
for (; !projEnumerator.atEnd() ; projEnumerator.moveNext() )
{
projItem = projEnumerator.item();
var checkouts = GetCheckedOutFiles(projItem);
if(checkouts.length > 0)
{
output += projItem.Spec + "\n";
var checkoutEnumerator = new Enumerator(checkouts);
for(;!checkoutEnumerator.atEnd();checkoutEnumerator.moveNext())
{
var checkoutItem = checkoutEnumerator.item();
output += "\t" + checkoutItem + "\n";
}
output += "\n";
}
}
var olApp = new ActiveXObject("Outlook.Application");
var mailItem = olApp.CreateItem(0 /*olMailItem*/);
mailItem.Recipients.Add("<Insert e-mail address to send mail to>");
mailItem.Body = "\n" + output;
mailItem.Display();
function GetCheckedOutFiles( projectItem )
{
var checkouts = new Array();
var itemEnumerator = new Enumerator(projectItem.items(false));
for(; !itemEnumerator.atEnd(); itemEnumerator.moveNext())
{
var item = itemEnumerator.item();
//File
if(item.Type == 1/*VSSITEM_FILE*/ && item.IsCheckedOut == 2 /*VSSFILE_CHECKEDOUT_ME*/)
{
checkouts.push(item.Name);
}
}
return checkouts;
}
function GetAllProjects( rootItem )
{
var projects = new Array();
var items = new Enumerator(rootItem.items(false));
for(;!items.atEnd();items.moveNext())
{
var item = items.item();
//Project
if(item.Type == 0 /*VSSITEM_PROJECT*/)
{
projects.push(item);
var subProjects = GetAllProjects(item);
var subProjectEnumerator = new Enumerator(subProjects);
for(;!subProjectEnumerator.atEnd();subProjectEnumerator.moveNext())
{
var subProjectItem = subProjectEnumerator.item();
projects.push(subProjectItem);
}
}
}
return projects;
}
function printItems(items, prop)
{
var itemEnumerator = new Enumerator(items);
for(;!itemEnumerator.atEnd();itemEnumerator.moveNext() )
{
var item = itemEnumerator.item();
WScript.Echo(item[prop]);
}
}