/// <summary> /// Adds a label to an issue /// </summary> /// <remarks> /// See the <a href="http://developer.github.com/v3/issues/labels/#add-labels-to-an-issue">API documentation</a> for more information. /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="number">The number of the issue</param> /// <param name="labels">The names of the labels to add</param> public IObservable <Label> AddToIssue(string owner, string name, int number, string[] labels) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(labels, nameof(labels)); return(_client.AddToIssue(owner, name, number, labels) .ToObservable() .SelectMany(x => x)); // HACK: POST is not compatible with GetAndFlattenPages }
public async Task CanAddToIssue() { var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; var newLabel = new NewLabel("test label 1b", "FFFFFF"); var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel); Assert.NotNull(label); var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); Assert.NotNull(issue); await _issuesLabelsClient.AddToIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new [] { label.Name }); var labels = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.NotEmpty(labels); Assert.Equal(label.Name, labels[0].Name); Assert.Equal(label.Color, labels[0].Color); }
private async Task UpdateIssueLabelsAsync(PortingInfo ruleToPort, Issue existingIssue) { var existingLabelNames = new Collection <string>(existingIssue.Labels.Select(label => label.Name).ToList()); var labelNamesToAdd = new Collection <string>(); var labelNamesToRemove = new Collection <string>(); AddLabel(FxCopPortLabel, labelNamesToAdd, existingLabelNames); if (ruleToPort.Soon) { AddLabel(UrgencySoonLabel, labelNamesToAdd, existingLabelNames); } else { RemoveLabel(UrgencySoonLabel, labelNamesToRemove, existingLabelNames); } switch (ruleToPort.Disposition) { case Disposition.NeedsReview: AddLabel(NeedsReviewLabel, labelNamesToAdd, existingLabelNames); RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames); RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames); break; case Disposition.Port: RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames); RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames); RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames); break; case Disposition.Cut: AddLabel(CutLabel, labelNamesToAdd, existingLabelNames); RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames); RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames); break; case Disposition.Ported: AddLabel(PortedLabel, labelNamesToAdd, existingLabelNames); RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames); RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames); break; } RemoveAreaLabels(existingLabelNames, labelNamesToRemove); AddAreaLabel(ruleToPort, labelNamesToAdd); if (_options.DryRun) { _log.Info(Resources.InfoDryRunLabelsNotUpdated); } else { if (labelNamesToAdd.Any()) { await _issuesLabelsClient.AddToIssue( _options.RepoOwner, _options.RepoName, existingIssue.Number, labelNamesToAdd.ToArray()); } // Take care not to remove any labels we've just added. // // For some reason the "Remove" API doesn't take an array. foreach (string labelName in labelNamesToRemove.Except(labelNamesToAdd)) { await _issuesLabelsClient.RemoveFromIssue( _options.RepoOwner, _options.RepoName, existingIssue.Number, labelName); } } }
/// <summary> /// Adds a label to an issue /// </summary> /// <remarks> /// See the <a href="http://developer.github.com/v3/issues/labels/#add-labels-to-an-issue">API documentation</a> for more information. /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="repo">The name of the repository</param> /// <param name="number">The number of the issue</param> /// <param name="labels">The names of the labels to add</param> /// <returns></returns> public IObservable <Label> AddToIssue(string owner, string repo, int number, string[] labels) { return(_client.AddToIssue(owner, repo, number, labels) .ToObservable() .SelectMany(x => x)); // HACK: POST is not compatible with GetAndFlattenPages }