public async Task <ActionResult <bool> > UpdateAsync(int buildId) { Subscription subscription = await Context.Subscriptions.FindAsync(SubscriptionId); Build build = await Context.Builds.Include(b => b.Assets) .ThenInclude(a => a.Locations) .FirstAsync(b => b.Id == buildId); ActorId pullRequestActorId; if (subscription.PolicyObject.Batchable) { pullRequestActorId = PullRequestActorId.Create( subscription.TargetRepository, subscription.TargetBranch); } else { pullRequestActorId = PullRequestActorId.Create(SubscriptionId); } IPullRequestActor pullRequestActor = PullRequestActorFactory(pullRequestActorId); List <Asset> assets = build.Assets.Select( a => new Asset { Name = a.Name, Version = a.Version }) .ToList(); await pullRequestActor.UpdateAssetsAsync(SubscriptionId, build.Id, build.Commit, assets); return(ActionResult.Create(true, "Update Sent")); }
public Task ProcessAsync(JToken argumentToken) { var update = argumentToken.ToObject <Arguments>(); IPullRequestActor actor = _factory.Lookup(PullRequestActorId.Create(update.Repository, update.Branch)); return(actor.RunActionAsync(update.Method, update.MethodArguments)); }
public async Task <ActionResult <bool> > UpdateAsync(int buildId) { Subscription subscription = await Context.Subscriptions.FindAsync(SubscriptionId); await AddDependencyFlowEventAsync( buildId, DependencyFlowEventType.Fired, DependencyFlowEventReason.New, MergePolicyCheckResult.PendingPolicies, "PR", null); Logger.LogInformation($"Looking up build {buildId}"); Build build = await Context.Builds.Include(b => b.Assets) .ThenInclude(a => a.Locations) .FirstAsync(b => b.Id == buildId); ActorId pullRequestActorId; if (subscription.PolicyObject.Batchable) { pullRequestActorId = PullRequestActorId.Create( subscription.TargetRepository, subscription.TargetBranch); } else { pullRequestActorId = PullRequestActorId.Create(SubscriptionId); } Logger.LogInformation($"Creating pull request actor for '{pullRequestActorId}'"); IPullRequestActor pullRequestActor = PullRequestActorFactory(pullRequestActorId); List <Asset> assets = build.Assets.Select( a => new Asset { Name = a.Name, Version = a.Version }) .ToList(); Logger.LogInformation($"Running asset update for {SubscriptionId}"); await pullRequestActor.UpdateAssetsAsync( SubscriptionId, build.Id, build.GitHubRepository ?? build.AzureDevOpsRepository, build.Commit, assets); Logger.LogInformation($"Asset update complete for {SubscriptionId}"); return(ActionResult.Create(true, "Update Sent")); }
public async Task <IActionResult> RetryActionAsync([Required] string repository, [Required] 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; Data.Models.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()); }