Exemple #1
0
        public void From_WithRevisionByRevisionNumber_ProducesCorrectRevisionSpecification()
        {
            string       output   = RevSpec.From(2).ToString();
            const string expected = "2:";

            Assert.That(output, Is.EqualTo(expected));
        }
        public IEnumerable <RevisionRange> GetAfterTillHead(RevisionId revisionId, int pageSize)
        {
            var revSpec = new RevSpec(revisionId.Value);
            var command = new LogCommand().WithRevision(RevSpec.From(revSpec) && !new RevSpec(revisionId.Value));
            var pages   = _repository.Log(command)
                          .OrderBy(ch => ch.Timestamp)
                          .ToArray()
                          .Split(pageSize);

            var result = pages.Select(page => new RevisionRange(page.First().ToRevisionId(), page.Last().ToRevisionId()));

            return(result);
        }
        public IEnumerable <RevisionRange> GetFromAndBefore(RevisionId fromRevision, RevisionId toRevision, int pageSize)
        {
            var command = new LogCommand();

            if (string.IsNullOrEmpty(fromRevision.Value))
            {
                if (string.IsNullOrEmpty(toRevision.Value))
                {
                    command = command.WithAdditionalArgument("-d {0:yyyy-MM-dd} to {1:yyyy-MM-dd}".Fmt(fromRevision.Time.Value, toRevision.Time.Value));
                }
                else
                {
                    var to = new RevSpec(toRevision.Value);
                    command = command.WithRevision(RevSpec.To(to));
                    command = command.WithAdditionalArgument("-d >{0:yyyy-MM-dd}".Fmt(fromRevision.Time.Value));
                }
            }
            else
            {
                var from = new RevSpec(fromRevision.Value);
                if (string.IsNullOrEmpty(toRevision.Value))
                {
                    command = command.WithAdditionalArgument("-d <{0:yyyy-MM-dd}".Fmt(toRevision.Time.Value));
                    command = command.WithRevision(RevSpec.From(from));
                }
                else
                {
                    var to = new RevSpec(toRevision.Value);
                    command = command.WithRevision(RevSpec.Range(from, to));
                }
            }

            var pages = _repository.Log(command)
                        .OrderBy(ch => ch.Timestamp)
                        .ToArray()
                        .Split(pageSize);

            var result = pages.Select(page => new RevisionRange(page.First().ToRevisionId(), page.Last().ToRevisionId()));

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Executed by the external hook
        /// </summary>
        /// <param name="args">command line args (none)</param>
        static void Main(string[] args)
        {
            // get a reference to the hook calling the program
            var hook = new Mercurial.Hooks.MercurialChangeGroupHook();

            // configure the logger
            ConfigureLogger();

            Log.InfoFormat("MercurialChangeGroupHook: Triggered for repository [{0}]", hook.Repository);

            // get the current identity who committed the change group
            var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();

            if (windowsIdentity != null)
            {
                // log info to aide in debugging
                var user = windowsIdentity.Name;
                Log.InfoFormat("MercurialChangeGroupHook: Current user [{0}]", user);
            }

            try
            {
                // get all the change sets for the revision from the log
                var changesets =
                    hook.Repository.Log(new LogCommand()
                                        .WithRevision(RevSpec.From(hook.FirstRevision)))
                    .ToArray();

                Log.InfoFormat("MercurialChangeGroupHook: Found [{0}] change sets", changesets.Length);

                // wire up the bugnet service
                var services = new WebServices.BugNetServices
                {
                    CookieContainer = new System.Net.CookieContainer(),
                    Url             = AppSettings.BugNetServicesUrl
                };

                if (Convert.ToBoolean(AppSettings.BugNetWindowsAuthentication))
                {
                    services.UseDefaultCredentials = true;
                }
                else
                {
                    Log.Info("MercurialChangeGroupHook: Logging in to BugNET Web Services");

                    var result = services.LogIn(AppSettings.BugNetUsername, AppSettings.BugNetPassword);
                    if (result)
                    {
                        Log.Info("MercurialChangeGroupHook: Login successful");
                    }
                    else
                    {
                        Log.Error("MercurialChangeGroupHook: Unauthorized access, please check the user name and password settings");
                        Environment.Exit(1);
                    }
                }

                // get the repository from the hook
                var repositoryName = IssueTrackerIntegration.GetRepositoryName(hook.Repository.ToString());

                // loop the change sets from the log
                foreach (var changeset in changesets)
                {
                    Log.InfoFormat("MercurialChangeGroupHook: Processing change set [{0}]", changeset.Hash);
                    IssueTrackerIntegration.UpdateBugNetForChangeset(repositoryName, changeset, services);
                }

                Log.Info("MercurialChangeGroupHook: Processing complete");
            }
            catch (Exception ex)
            {
                Log.FatalFormat("MercurialChangeGroupHook: An error occurred while processing: {0} \n\n {1}", ex.Message, ex.StackTrace);
                Environment.Exit(1);
            }
        }
Exemple #5
0
 public void From_WithNullRevision_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => RevSpec.From(null));
 }