Exemplo n.º 1
0
        static int Main(string[] args)
        {
            int error = WindowsErrorDefinition.Success;

            if (args.Length < 3)
            {
                ShowUsage();
                error = WindowsErrorDefinition.NotSupported;
            }
            else
            {
                string pvcsUserId            = args[0];
                string buildSetSpecification = args[1];
                string gitLogReportFilename  = args[2];

                string gitLogReportPathAndFilename = Path.GetFullPath(gitLogReportFilename);

                Console.WriteLine("PVCS User Id is \"{0}\"", pvcsUserId);
                Console.WriteLine("Build Set Specification is \"{0}\"", buildSetSpecification);
                Console.WriteLine("Supplied git log filename is \"{0}\" resolving to \"{1}\"", gitLogReportFilename, gitLogReportPathAndFilename);

                BuildSetDetails buildSetDetails = new BuildSetDetails(buildSetSpecification);

                if (!buildSetDetails.AreValid)
                {
                    Console.WriteLine("eisGitToPvcsUpdate : Unable to identify the Build Set with specification \"{0}\"", buildSetSpecification);
                    error = WindowsErrorDefinition.BadEnvironment;
                }
                else
                {
                    buildSetDetails.Display("Selected Build Set");
                    Console.WriteLine(
                        "Managing PVCS update from Build Set \"{0}\" to PVCS Promotion Group \"{1}\"",
                        buildSetDetails.Identifier,
                        buildSetDetails.SecondaryIdentifier);
                    Console.WriteLine("Git Log report filename is \"{0}\"", gitLogReportPathAndFilename);

                    // Do not meddle with the sources if there is no associated git source change control
                    if (String.Compare(buildSetDetails.SourceChangeControlType, "git", true /* ignore case */) != 0)
                    {
                        Console.WriteLine("Build Set \"{0}\" is not Git Source Change Control Type", buildSetDetails.Identifier);
                        error = WindowsErrorDefinition.InvalidFunction;
                    }
                    else
                    {
                        PvcsPromotionGroupDataSortedSet pvcsPromotionGroupDataSortedSet = new PvcsPromotionGroupDataSortedSet();
                        error = pvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup(pvcsUserId, buildSetDetails, gitLogReportPathAndFilename);
                    }
                }
            }
            return(error);
        }
Exemplo n.º 2
0
        public int Commit(string pvcsUserId,
                          BuildSetDetails buildsetDetails,
                          PvcsPromotionGroupData pvcsPromotionGroupData,
                          PvcsPromotionGroupDataSortedSet pvcsPromotionGroupDataSortedSet)
        {
            int error = WindowsErrorDefinition.Success;

            // Make sure there is something to commit
            if ((String.IsNullOrEmpty(PvcsCommitUserId)) ||
                (String.IsNullOrEmpty(Hash)) ||
                (String.IsNullOrEmpty(emailAddress)) ||
                ((DateTime == DateTime.MinValue)) ||
                (String.IsNullOrEmpty(Description))
                )
            {
                Console.WriteLine("PvcsCommitData.Commit : Insufficient data to perform a Commit");
            }
            else
            {
                // There is Commit information

                if (!Committed)
                {
                    // This Commit has not been committed already

                    if (PvcsCommitFileDataCollection.Count < 1)
                    {
                        Console.WriteLine("PvcsCommitData.Commit : No files to commit");
                        error = WindowsErrorDefinition.InvalidFunction;
                    }
                    else
                    {
                        // There are files to commit

                        error = PvcsConfiguration.SetPvcsEnvironment(pvcsUserId);
                        if (error == WindowsErrorDefinition.Success)
                        {
                            // Successfully set the PVCS Environment

                            for (int fileIndex = 0;
                                 (fileIndex < PvcsCommitFileDataCollection.Count) &&
                                 (error == WindowsErrorDefinition.Success);
                                 ++fileIndex)
                            {
                                error = PvcsCommitFileDataCollection.ElementAt(fileIndex).Commit(
                                    pvcsUserId,
                                    FullChangeDescription,
                                    buildsetDetails,
                                    pvcsPromotionGroupData,
                                    pvcsPromotionGroupDataSortedSet);
                                if (error != WindowsErrorDefinition.Success)
                                {
                                    Console.WriteLine("PvcsCommitData.Commit : File with index {0} = \"{1}\" failed to commit into PVCS",
                                                      fileIndex, PvcsCommitFileDataCollection.ElementAt(fileIndex).Name);
                                }
                            } // for fileIndex
                        }     // Successfully set the PVCS Environment
                    }         // There are files to commit

                    Committed = true;
                } // This Commit has not been committed already
            }     // There is Commit information

            return(error);
        } // Commit
        public int UpdatePvcsForPromotionGroup(string pvcsUserId, BuildSetDetails buildsetDetails, string gitLogReportFilenameWithPath)
        {
            int error = 0;
            PvcsPromotionGroupData promotionGroupData = GetPromotionGroupData(buildsetDetails.SecondaryIdentifier);

            if (promotionGroupData == null)
            {
                Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Promotion Group \"{0}\" is not known", buildsetDetails.SecondaryIdentifier);
                error = WindowsErrorDefinition.BadEnvironment;
            }
            else
            {
                // Promotion Group is known

                if (!File.Exists(gitLogReportFilenameWithPath))
                {
                    Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : git log report file \"{0}\" does not exist", gitLogReportFilenameWithPath);
                    error = WindowsErrorDefinition.FileNotFound;
                }
                else
                {
                    // git log report file exists

                    Console.WriteLine("Current directory is \"{0}\"", Directory.GetCurrentDirectory());

                    using (StreamReader gitLogFileStream = new StreamReader(gitLogReportFilenameWithPath))
                    {
                        string         gitLogLine           = null;
                        int            lineNumber           = 0;
                        int            commitCount          = 0;
                        int            commitAttributeCount = 0;
                        PvcsCommitData pvcsCommitData       = null; // One object reused for each commit

                        ReadingState readingState = ReadingState.Reading;

                        while (((gitLogLine = gitLogFileStream.ReadLine()) != null) && (error == WindowsErrorDefinition.Success))
                        {
                            lineNumber += 1;
                            Console.WriteLine("{0,-2} : {1}", lineNumber.ToString("###"), gitLogLine);
                            if (!gitLogLine.StartsWith("#"))
                            {
                                // Not a commented out line
                                switch (readingState)
                                {
                                case ReadingState.Reading:
                                    // Check for entering a processing state
                                    if (gitLogLine == "+++")
                                    {
                                        readingState         = ReadingState.ProcessingCommitAttributes;
                                        commitCount         += 1;
                                        commitAttributeCount = 0;
                                        // Replace any existing commit data
                                        pvcsCommitData = new PvcsCommitData(pvcsUserId);
                                    }
                                    break;

                                case ReadingState.ProcessingCommitAttributes:
                                    // Check for a exiting a commit attributs processing state
                                    if (gitLogLine == "---")
                                    {
                                        readingState = ReadingState.ProcessingCommitFilenames;
                                    }
                                    else
                                    {
                                        // Process the attribute

                                        switch (commitAttributeCount)
                                        {
                                        case 0:
                                            // Must be the Commit Hash
                                            pvcsCommitData.Hash   = gitLogLine;
                                            commitAttributeCount += 1;
                                            break;

                                        case 1:
                                            // Must be the email address
                                            pvcsCommitData.emailAddress = gitLogLine;
                                            commitAttributeCount       += 1;
                                            break;

                                        case 2:
                                        {
                                            // Must be the Commit Data/Time
                                            try
                                            {
                                                pvcsCommitData.DateTime = System.Convert.ToDateTime(gitLogLine);
                                            }
                                            catch (Exception)
                                            {
                                                pvcsCommitData.DateTime = DateTime.Now;
                                                Console.WriteLine("{0} : Line Number {1} : Unable to convert \"{2}\" to a DateTime, Defaulting to \"Now\" = {3}",
                                                                  gitLogReportFilenameWithPath, lineNumber, gitLogLine, pvcsCommitData.DateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                                            }
                                            commitAttributeCount += 1;
                                            break;
                                        }

                                        case 3:
                                            // Cope with multi-line descriptions
                                            if (String.IsNullOrEmpty(pvcsCommitData.Description))
                                            {
                                                commitAttributeCount += 1;
                                            }
                                            if (!(String.IsNullOrEmpty(gitLogLine)) && (!String.IsNullOrWhiteSpace(gitLogLine)))
                                            {
                                                if (String.IsNullOrEmpty(pvcsCommitData.Description))
                                                {
                                                    pvcsCommitData.Description = gitLogLine;
                                                }
                                                else
                                                {
                                                    // Separate multiple lines with a space
                                                    pvcsCommitData.Description += " " + gitLogLine;
                                                }
                                            }
                                            break;

                                        default:
                                            Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Unexpected Commit Attribute Index {0}", commitAttributeCount);
                                            break;
                                        }
                                    }     // Process the attribute
                                    break;

                                case ReadingState.ProcessingCommitFilenames:
                                    if (gitLogLine.Length == 0)
                                    {
                                        // Nothing to do
                                    }
                                    else if (gitLogLine == "+++")
                                    {
                                        // Found the next commit entry so process this one

                                        error = pvcsCommitData.Commit(pvcsUserId,
                                                                      buildsetDetails,
                                                                      promotionGroupData,
                                                                      this);

                                        if (error == WindowsErrorDefinition.Success)
                                        {
                                            // Go back to processing commit attributes
                                            readingState         = ReadingState.ProcessingCommitAttributes;
                                            commitCount         += 1;
                                            commitAttributeCount = 0;
                                            pvcsCommitData       = new PvcsCommitData(pvcsUserId);
                                        } // Go back to processing commit attributes
                                    }     // Found the next commit entry so process this one
                                    else
                                    {
                                        // Process the filename
                                        string commitstatus = new string(gitLogLine.ToCharArray(), 0, 1);
                                        string filename     = gitLogLine.Substring(1).Trim();
                                        // Replace all forward slashes with back slashes
                                        filename = filename.Replace("/", "\\");
                                        PvcsCommitFileData pvcsCommitFileData = new PvcsCommitFileData(filename, commitstatus);
                                        pvcsCommitData.PvcsCommitFileDataCollection.Add(pvcsCommitFileData);
                                    }     // Process the filename
                                    break;

                                default:
                                    Console.WriteLine("Reading \"{0}\" : Unexpected Reading State = \"{1}\"", gitLogReportFilenameWithPath, readingState.ToString());
                                    break;
                                } // switch
                            }     // Not a commented out line
                        }         // while

                        if (error == WindowsErrorDefinition.Success)
                        {
                            // Ensure it was committed
                            error = pvcsCommitData.Commit(pvcsUserId,
                                                          buildsetDetails,
                                                          promotionGroupData,
                                                          this);
                        }

                        if (error == WindowsErrorDefinition.Success)
                        {
                            Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Successfully processed {0} PVCS Commits", commitCount);
                        }
                        else
                        {
                            Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Processed {0} PVCS Commits with error {1}", commitCount, error);
                        }
                    } // using
                }     // git log report file exists
            }         // Promotion Group is known
            return(error);
        }             // UpdatePvcsForPromotionGroup
Exemplo n.º 4
0
        public int Commit(string pvcsUserId,
                          string changeDescription,
                          BuildSetDetails buildSetDetails,
                          PvcsPromotionGroupData pvcsPromotionGroupData,
                          PvcsPromotionGroupDataSortedSet pvcsPromotionGroupDataSortedSet)
        {
            int error = WindowsErrorDefinition.Success;

            // Check whether the PVCS Archive exists
            if (!File.Exists(PvcsArchiveNameAndPath))
            {
                Console.WriteLine("PvcsCommitFileData.Commit : PVCS Archive \"{0}\" does not exist", PvcsArchiveNameAndPath);
                error = WindowsErrorDefinition.FileNotFound;
            }
            else
            {
                // PVCS Archive exists

                Console.WriteLine("PvcsCommitFileData.Commit : Committing \"{0}\"", Name);

                // Identify all the Promotion Groups in the PVCS Archive
                SortedSet <string> promotionGroupSortedSet = new SortedSet <string>();
                error = PvcsCommandOperation.GetArchivePromotionGroupNames(PvcsArchiveNameAndPath, ref promotionGroupSortedSet);
                if (error != WindowsErrorDefinition.Success)
                {
                    Console.WriteLine("PvcsCommitFileData.Commit({0}) : Failed to locate any Promotion Groups within the PVCS Archive", PvcsArchiveNameAndPath);
                }
                else
                {
                    // Got the Promotion Groups within the Archive or there aren't any

                    if ((promotionGroupSortedSet.Count > 0) &&
                        (promotionGroupSortedSet.Contains(pvcsPromotionGroupData.LowerSourcePromotionGroupName))
                        )
                    {
                        // There are Promotion Groups and the lower Promotion Group exists

                        error = PvcsCommandOperation.Promote(PvcsArchiveNameAndPath,
                                                             pvcsPromotionGroupData.LowerSourcePromotionGroupName);
                    } // There are Promotion Groups and the lower Promotion Group exists
                    else
                    {
                        // Try to Check In the new source via the Direct Checkin Promotion Group

                        // The mechanism of CheckIn is slightly different for an empty Archive

                        bool archiveIsEmpty = false;
                        error = PvcsCommandOperation.ArchiveIsEmpty(PvcsArchiveNameAndPath, out archiveIsEmpty);
                        if ((error == WindowsErrorDefinition.Success) &&
                            (!archiveIsEmpty)
                            )
                        {
                            // Lock the Archive at the Direct CheckIn Promotion Group

                            if (pvcsPromotionGroupData.DirectCheckInPromotionGroupName == null)
                            {
                                Console.WriteLine("PvcsCommitFileData.Commit : Promotion Group \"{0}\" has no Direct CheckIn Promotion Group",
                                                  pvcsPromotionGroupData.Name);
                                error = WindowsErrorDefinition.PathNotFound;
                            }
                            else
                            {
                                error = PvcsCommandOperation.Lock(PvcsArchiveNameAndPath,
                                                                  pvcsPromotionGroupData.DirectCheckInPromotionGroupName);
                            }
                        } // Lock the Archive at the Direct CheckIn Promotion Group

                        if (error == WindowsErrorDefinition.Success)
                        {
                            // Archive is ready for CheckIn

                            // Build the full path and filename to the source that has changed
                            string sourcePathAndFilename = Path.Combine(buildSetDetails.BuildSetRootPath, Name);

                            if (archiveIsEmpty)
                            {
                                // Checking In to an empty Archive requires assigning the correct Promotion Group
                                error = PvcsCommandOperation.CheckIntoEmptyArchive(pvcsUserId,
                                                                                   changeDescription,
                                                                                   pvcsPromotionGroupData.
                                                                                   DirectCheckInPromotionGroupName,
                                                                                   PvcsArchiveNameAndPath,
                                                                                   sourcePathAndFilename);
                            }
                            else
                            {
                                // A non-empty Archive will have had a revision locked at the necessary Promotion Group
                                error = PvcsCommandOperation.CheckIntoNonEmptyArchive(pvcsUserId,
                                                                                      changeDescription,
                                                                                      PvcsArchiveNameAndPath,
                                                                                      sourcePathAndFilename);
                            }

                            if (error == WindowsErrorDefinition.Success)
                            {
                                // Source has been CheckedIn

                                // Promote to end up at the required Promotion Group

                                // "DevelopmentN" Promotion Groups have IsCandidate "Pre_System_TestN"
                                // Promotion Groups above them so there would need to be two Promotions
                                // to get to the necessary Promotion Group
                                if (pvcsPromotionGroupData.DirectCheckInPromotionGroupName.StartsWith("Development"))
                                {
                                    // There will need to be two Promotions

                                    // Promote from the Direct CheckIn Promotion Group
                                    error = PvcsCommandOperation.Promote(PvcsArchiveNameAndPath,
                                                                         pvcsPromotionGroupData.
                                                                         DirectCheckInPromotionGroupName);
                                    if (error == WindowsErrorDefinition.Success)
                                    {
                                        // Now Promote from the Group above the Direct CheckIn Promotion Group

                                        // Get the data for the Direct CheckIn Promotion Group
                                        PvcsPromotionGroupData pvcsPromotionGroupDataDirectCheckIn =
                                            pvcsPromotionGroupDataSortedSet.GetPromotionGroupData(
                                                pvcsPromotionGroupData.DirectCheckInPromotionGroupName);

                                        if (pvcsPromotionGroupDataDirectCheckIn == null)
                                        {
                                            Console.WriteLine(
                                                "PvcsCommitFileData.Commit : Unable to find the details for the"
                                                + " Promotion Group that is higher than \"{0}\"",
                                                pvcsPromotionGroupData.DirectCheckInPromotionGroupName);
                                            error = WindowsErrorDefinition.PathNotFound;
                                        }
                                        else
                                        {
                                            // Promote from the Group above the Direct CheckIn Promotion Group
                                            error = PvcsCommandOperation.Promote(PvcsArchiveNameAndPath,
                                                                                 pvcsPromotionGroupDataDirectCheckIn.NextHigherPromotionGroupName);
                                        }
                                    } // Now Promote from the Group above the Direct CheckIn Promotion Group
                                }     // There will need to be two Promotions
                                else
                                {
                                    // There will need to be one Promotion only

                                    // Promote from the Direct CheckIn Promotion Group
                                    error = PvcsCommandOperation.Promote(PvcsArchiveNameAndPath,
                                                                         pvcsPromotionGroupData.
                                                                         DirectCheckInPromotionGroupName);
                                } // There will need to be one Promotion only
                            }     // Source has been CheckedIn
                        }         // Archive is ready for CheckIn
                    }             // Try to Check In the new source via the Direct Checkin Promotion Group
                }                 // Got the Promotion Groups within the Archive or there aren't any
            }                     // PVCS Archive exists

            return(error);
        } // Commit