/// <summary> /// Checks all open PRs for if they should have the 'Merge Conflict' tag /// </summary> /// <returns>A <see cref="Task"/> representing the running operation</returns> async Task CheckMergeConflicts() { Task AddMergeConflictTag(PullRequest pullRequest) { return(gitHubManager.AddLabel(pullRequest.Number, "Merge Conflict")); }; async Task RefreshPR(PullRequest pullRequest) { //wait 10s for refresh then give up await Task.Delay(10000).ConfigureAwait(false); pullRequest = await gitHubManager.GetPullRequest(pullRequest.Number).ConfigureAwait(false); if (pullRequest.Mergeable.HasValue && !pullRequest.Mergeable.Value) { await AddMergeConflictTag(pullRequest).ConfigureAwait(false); } }; var tasks = new List <Task>(); var prs = await gitHubManager.GetOpenPullRequests().ConfigureAwait(false); foreach (var I in prs) { if (I.Mergeable.HasValue) { if (I.Mergeable.Value) { continue; } else { tasks.Add(AddMergeConflictTag(I)); } } else { tasks.Add(RefreshPR(I)); } } await Task.WhenAll(tasks).ConfigureAwait(false); }