public async Task <IActionResult> GetMergePolicies([Required] string repository, [Required] string branch)
        {
            if (string.IsNullOrEmpty(repository))
            {
                ModelState.TryAddModelError(nameof(repository), "The repository parameter is required");
            }

            if (string.IsNullOrEmpty(branch))
            {
                ModelState.TryAddModelError(nameof(branch), "The branch parameter is required");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            RepositoryBranch repoBranch = await Context.RepositoryBranches.FindAsync(repository, branch);

            if (repoBranch == null)
            {
                return(NotFound());
            }

            List <MergePolicyDefinition> policies =
                repoBranch.PolicyObject?.MergePolicies ?? new List <MergePolicyDefinition>();

            return(Ok(policies.Select(p => new MergePolicy(p))));
        }
Example #2
0
            //private string Content { get; set; }
            public File(RepositoryBranch repositoryBranch, string path,
                        [System.Runtime.CompilerServices.CallerFilePath] string callerFilePath  = "",
                        [System.Runtime.CompilerServices.CallerLineNumber] int callerLineNumber = 0
                        )
            {
                RepositoryBranch = repositoryBranch;
                Path             = path;
                var hash = RepositoryBranch.Owner.Name + RepositoryBranch.Name + RepositoryBranch.Reference + path;

                hash = string.Concat(hash.Split(System.IO.Path.GetInvalidFileNameChars()));
                //using (new Stopwatch("Load hash of " + hash)) {
                FileCache = FileCache.Load(hash);
                if (FileCache == null)
                {
                    FileCache = FileCache.Create(hash);
                    var client = new WebClient();
                    try {
                        FileCache.Content = client.DownloadStringTaskAsync(RawUri).Result;
                    }
                    catch (Exception e) {
                        Log.Error.On(callerFilePath, callerLineNumber, e.Message);
                    }
                    FileCache.Save();
                }
                //}
                //var
            }
Example #3
0
        public void RepositoryBranch_Test_EmtyBranch_HasEmptyHistory()
        {
            var repository = new RepositoryBranch <string, string>();

            Assert.That(repository.Head == null);
            Assert.That(repository.GetHistory().Count() == 0, "Empty repository should have zero length history");
        }
        public async Task <IActionResult> RetryActionAsync(string repository, string branch, long timestamp)
        {
            if (string.IsNullOrEmpty(repository))
            {
                ModelState.TryAddModelError(nameof(repository), "The repository parameter is required");
            }

            if (string.IsNullOrEmpty(branch))
            {
                ModelState.TryAddModelError(nameof(branch), "The branch parameter is required");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DateTime ts = DateTimeOffset.FromUnixTimeSeconds(timestamp).UtcDateTime;

            RepositoryBranch repoBranch = await Context.RepositoryBranches.FindAsync(repository, branch);

            if (repoBranch == null)
            {
                return(NotFound());
            }

            RepositoryBranchUpdateHistoryEntry update = await Context.RepositoryBranchUpdateHistory
                                                        .Where(u => u.Repository == repository && u.Branch == branch)
                                                        .FirstOrDefaultAsync(u => Math.Abs(EF.Functions.DateDiffSecond(u.Timestamp, ts)) < 1);

            if (update == null)
            {
                return(NotFound());
            }

            if (update.Success)
            {
                return(StatusCode(
                           (int)HttpStatusCode.NotAcceptable,
                           new ApiError("That action was successful, it cannot be retried.")));
            }

            Queue.Post(
                async() =>
            {
                IPullRequestActor actor =
                    PullRequestActorFactory(PullRequestActorId.Create(update.Repository, update.Branch));
                await actor.RunActionAsync(update.Method, update.Arguments);
            });

            return(Accepted());
        }
Example #5
0
        public void RepositoryBranch_Test_CommitTheSameValue()
        {
            var          repository = new RepositoryBranch <string, string>();
            const string value      = "some string";
            var          valueChars = new char[value.Length];

            value.CopyTo(0, valueChars, 0, value.Length);
            string theCopyValue = new String(valueChars);

            var firstCommit = repository.Commit(value, string.Empty);

            Assert.That(firstCommit != null, "Commit may not return null value");

            var secondCommit = repository.Commit(theCopyValue, string.Empty);

            Assert.That(firstCommit.Equals(secondCommit), "Commit of the current value should not produce new version");
            Assert.That(firstCommit == secondCommit, "Commit of the current value should return the current commit instance");
        }
Example #6
0
        public void RepositoryBranch_Test_CommitOperation()
        {
            var repository = new RepositoryBranch <string, string>();

            Assert.That(repository.Head == null);

            var commit = repository.Commit(string.Empty, string.Empty);

            Assert.That(repository.Head.Equals(commit), "Repo should poit to the last commit");
            Assert.That(commit.Previous == null, "First commit should not have any parents");

            var commit2 = repository.Commit("other", string.Empty);

            Assert.That(repository.Head.Equals(commit2), "Repo should poit to the last commit");
            Assert.That(commit2.Previous != null, "New commit should point to previous one");
            Assert.That(commit2.Previous.Equals(commit), "New commit should point to previous one");
            Assert.That(repository.GetHistory().Count() == 2, "Repository should contains exactly two commits at this point");
            Assert.That(repository.GetHistory().First().Equals(commit2), "History should starts from last commit");
        }
        private async Task <RepositoryBranch> GetRepositoryBranch(string repository, string branch)
        {
            RepositoryBranch repoBranch = await Context.RepositoryBranches.FindAsync(repository, branch);

            if (repoBranch == null)
            {
                Context.RepositoryBranches.Add(
                    repoBranch = new RepositoryBranch
                {
                    RepositoryName = repository,
                    BranchName     = branch
                });
            }
            else
            {
                Context.RepositoryBranches.Update(repoBranch);
            }

            return(repoBranch);
        }
        public override int GetHashCode()
        {
            var hash = 17;

            hash = hash * 31 + Repository.GetHashCode();

            if (!string.IsNullOrEmpty(RepositoryBranch))
            {
                hash = hash * 31 + RepositoryBranch.GetHashCode();
            }

            hash = hash * 31 + IdeUserIdentity.Id.GetHashCode();
            hash = hash * 31 + BeingEdited.GetHashCode();
            hash = hash * 31 + HasFocus.GetHashCode();
            hash = hash * 31 + (CaretPositionInfo?.LeafMemberCaretOffset.GetHashCode() ?? 0);
            hash = hash * 31 + (CaretPositionInfo?.LeafMemberLineOffset.GetHashCode() ?? 0);
            hash = hash * 31 + (CaretPositionInfo?.SyntaxNodeIds.GetHashCode() ?? 0);

            return(hash);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BuildParameters"/> class.
        /// </summary>
        /// <param name="build">The build.</param>
        public BuildParameters(Build build)
        {
            Title          = "Azure.Offline.Sync";
            RepositoryName = build.GitRepository.Identifier;

            RepositoryBranch    = build.GitRepository?.Branch ?? string.Empty;
            IsMasterBranch      = RepositoryBranch.Equals(MasterBranch);
            IsDevelopmentBranch = RepositoryBranch.Equals(DevelopBranch);
            IsReleaseBranch     = RepositoryBranch.Contains(ReleaseBranchPrefix);
            IsPullRequest       = build.GitRepository.Head?.Contains("pull") ?? false;

            IsMainRepo = build.GitRepository.Identifier == "RocketSurgeonsGuild/Azure.Offline.Sync";

            IsReleasable = !IsLocalBuild && IsMainRepo && (IsDevelopmentBranch || IsMasterBranch || IsReleaseBranch);

            ShouldPublishTestResults = IsMainRepo && IsRunningOnAzureDevOps;

            IsNuGetRelease = IsReleasable && ShouldPublishNuGet && (IsMasterBranch || IsReleaseBranch);

            ShouldPublishMyGet = !IsLocalBuild && HasEnvironmentVariable(MyGetApiKey) && HasEnvironmentVariable(MyGetSource);
            ShouldPublishNuGet = !IsLocalBuild && HasEnvironmentVariable(NuGetApiKey) && HasEnvironmentVariable(NuGetSource);
        }
        public BuildParameters(Build b)
        {
            // ARGUMENTS
            Configuration = b.Configuration ?? "Release";
            SkipTests     = b.SkipTests;
            SkipPreviewer = b.SkipPreviewer;

            // CONFIGURATION
            MainRepo             = "https://github.com/AvaloniaUI/Avalonia";
            MasterBranch         = "refs/heads/master";
            ReleaseBranchPrefix  = "refs/heads/release/";
            ReleaseConfiguration = "Release";
            MSBuildSolution      = RootDirectory / "dirs.proj";

            // PARAMETERS
            IsLocalBuild    = Host == HostType.Console;
            IsRunningOnUnix = Environment.OSVersion.Platform == PlatformID.Unix ||
                              Environment.OSVersion.Platform == PlatformID.MacOSX;
            IsRunningOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
            IsRunningOnAzure   = Host == HostType.AzurePipelines ||
                                 Environment.GetEnvironmentVariable("LOGNAME") == "vsts";

            if (IsRunningOnAzure)
            {
                RepositoryName   = AzurePipelines.Instance.RepositoryUri;
                RepositoryBranch = AzurePipelines.Instance.SourceBranch;
                IsPullRequest    = AzurePipelines.Instance.PullRequestId.HasValue;
                IsMainRepo       = StringComparer.OrdinalIgnoreCase.Equals(MainRepo, AzurePipelines.Instance.RepositoryUri);
            }
            IsMainRepo =
                StringComparer.OrdinalIgnoreCase.Equals(MainRepo,
                                                        RepositoryName);
            IsMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch,
                                                                     RepositoryBranch);
            IsReleaseBranch = RepositoryBranch?.StartsWith(ReleaseBranchPrefix, StringComparison.OrdinalIgnoreCase) ==
                              true;

            IsReleasable   = StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, Configuration);
            IsMyGetRelease = IsReleasable;
            IsNuGetRelease = IsMainRepo && IsReleasable && IsReleaseBranch;

            // VERSION
            Version = b.ForceNugetVersion ?? GetVersion();

            if (IsRunningOnAzure)
            {
                if (!IsNuGetRelease)
                {
                    // Use AssemblyVersion with Build as version
                    Version += "-cibuild" + int.Parse(Environment.GetEnvironmentVariable("BUILD_BUILDID")).ToString("0000000") + "-beta";
                }

                PublishTestResults = true;
            }

            // DIRECTORIES
            ArtifactsDir          = RootDirectory / "artifacts";
            NugetRoot             = ArtifactsDir / "nuget";
            NugetIntermediateRoot = RootDirectory / "build-intermediate" / "nuget";
            ZipRoot           = ArtifactsDir / "zip";
            BinRoot           = ArtifactsDir / "bin";
            TestResultsRoot   = ArtifactsDir / "test-results";
            BuildDirs         = GlobDirectories(RootDirectory, "**bin").Concat(GlobDirectories(RootDirectory, "**obj")).ToList();
            DirSuffix         = Configuration;
            FileZipSuffix     = Version + ".zip";
            ZipCoreArtifacts  = ZipRoot / ("Avalonia-" + FileZipSuffix);
            ZipNuGetArtifacts = ZipRoot / ("Avalonia-NuGet-" + FileZipSuffix);
            ZipTargetControlCatalogNetCoreDir = ZipRoot / ("ControlCatalog.NetCore-" + FileZipSuffix);
        }