in tools/issue-labeler/src/Hubbup.MikLabelModel/Labeler.cs [206:297]
private async Task UpdateTask(
LabelerOptions options,
string owner, string repo,
int number,
bool foundArea,
HashSet<string> labels,
string theFoundLabel,
GithubObjectType issueOrPr,
ILabelRetriever labelRetriever)
{
if (labelRetriever.AddDelayBeforeUpdatingLabels)
{
// to avoid race with dotnet-bot
await Task.Delay(TimeSpan.FromSeconds(10));
}
// get iop again
var iop = await _gitHubClientWrapper.GetIssue(owner, repo, number);
var existingLabelList = iop?.Labels?.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).ToList();
bool issueMissingAreaLabel = !existingLabelList.Where(x => x.StartsWith("area-", StringComparison.OrdinalIgnoreCase)).Any();
// update section
if (labels.Count > 0 || (foundArea && issueMissingAreaLabel))
{
//var issueUpdate = iop.ToUpdate();
var issueUpdate = new IssueUpdate();
if (foundArea && issueMissingAreaLabel)
{
// no area label yet
issueUpdate.AddLabel(theFoundLabel);
}
var existingLabelNames = existingLabelList.ToHashSet();
foreach (var newLabel in labels)
{
if (!existingLabelNames.Contains(newLabel))
{
issueUpdate.AddLabel(newLabel);
}
}
if (options.CanUpdateIssue && issueUpdate.Labels != null && issueUpdate.Labels.Count > 0)
{
issueUpdate.Milestone = iop.Milestone?.Number; // The number of milestone associated with the issue.
foreach (var existingLabel in existingLabelNames)
{
issueUpdate.AddLabel(existingLabel);
}
await _gitHubClientWrapper.UpdateIssue(owner, repo, number, issueUpdate);
}
else if (!options.CanUpdateIssue && issueUpdate.Labels != null && issueUpdate.Labels.Count > 0)
{
_logger.LogInformation($"! skipped updating labels for {issueOrPr} {number}. would have become: {string.Join(",", issueUpdate.Labels)}");
}
else
{
_logger.LogInformation($"! dispatcher app - No update made to labels for {issueOrPr} {number}.");
}
}
// comment section
if (options.CanCommentOnIssue)
{
foreach (var labelFound in labels)
{
if (!string.IsNullOrEmpty(labelRetriever.CommentFor(labelFound)))
{
await _gitHubClientWrapper.CommentOn(owner, repo, iop.Number, labelRetriever.CommentFor(labelFound));
}
}
// if newlabels has no area-label and existing does not also. then comment
if (!foundArea && issueMissingAreaLabel && labelRetriever.CommentWhenMissingAreaLabel)
{
if (issueOrPr == GithubObjectType.Issue)
{
await _gitHubClientWrapper.CommentOn(owner, repo, iop.Number, labelRetriever.MessageToAddAreaLabelForIssue);
}
else
{
await _gitHubClientWrapper.CommentOn(owner, repo, iop.Number, labelRetriever.MessageToAddAreaLabelForPr);
}
}
}
else
{
_logger.LogInformation($"! dispatcher app - No comment made to labels for {issueOrPr} {number}.");
}
}