• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rwjdk / TrelloDotNet / 19698231357

26 Nov 2025 09:05AM UTC coverage: 80.581% (-0.2%) from 80.785%
19698231357

push

github

rwjdk
Tweaks

2557 of 3464 branches covered (73.82%)

Branch coverage included in aggregate %.

4547 of 5352 relevant lines covered (84.96%)

126.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.35
/src/TrelloDotNet/TrelloClient.Labels.cs
1
using System.Collections.Generic;
2
using System.Linq;
3
using System.Threading;
4
using System.Threading.Tasks;
5
using TrelloDotNet.Control;
6
using TrelloDotNet.Model;
7
using TrelloDotNet.Model.Options.GetLabelOptions;
8

9
namespace TrelloDotNet
10
{
11
    public partial class TrelloClient
12
    {
13
        /// <summary>
14
        /// Deletes a label from the board and removes it from all cards it was assigned to. This operation is irreversible. If you want to remove a label from a single card, use 'RemoveLabelsFromCardAsync' or 'RemoveAllLabelsFromCardAsync'.
15
        /// </summary>
16
        /// <param name="labelId">The ID of the label to delete</param>
17
        /// <param name="cancellationToken">Cancellation Token</param>
18
        public async Task DeleteLabelAsync(string labelId, CancellationToken cancellationToken = default)
19
        {
20
            await _apiRequestController.Delete($"{UrlPaths.Labels}/{labelId}", cancellationToken, 0);
2✔
21
        }
2✔
22

23
        /// <summary>
24
        /// Retrieves all labels defined for a specific board.
25
        /// </summary>
26
        /// <param name="boardId">ID of the board (long or short version)</param>
27
        /// <param name="cancellationToken">Cancellation Token</param>
28
        /// <returns>List of labels on the board</returns>
29
        public async Task<List<Label>> GetLabelsOfBoardAsync(string boardId, CancellationToken cancellationToken = default)
30
        {
31
            return await _apiRequestController.Get<List<Label>>(GetUrlBuilder.GetLabelsOfBoard(boardId), cancellationToken);
33✔
32
        }
33✔
33

34
        /// <summary>
35
        /// Retrieves all labels defined for a specific board, with additional options for filtering and selection.
36
        /// </summary>
37
        /// <param name="boardId">ID of the board (long or short version)</param>
38
        /// <param name="options">Options for filtering and selecting labels</param>
39
        /// <param name="cancellationToken">Cancellation Token</param>
40
        /// <returns>List of labels on the board</returns>
41
        public async Task<List<Label>> GetLabelsOfBoardAsync(string boardId, GetLabelOptions options, CancellationToken cancellationToken = default)
42
        {
43
            return await _apiRequestController.Get<List<Label>>(GetUrlBuilder.GetLabelsOfBoard(boardId), cancellationToken, options.GetParameters());
1✔
44
        }
1✔
45

46
        /// <summary>
47
        /// Adds one or more labels to a card by their IDs.
48
        /// </summary>
49
        /// <param name="cardId">ID of the card to add labels to</param>
50
        /// <param name="labelIdsToAdd">One or more IDs of labels to add</param>
51
        /// <returns>The updated card with the added labels</returns>
52
        public async Task<Card> AddLabelsToCardAsync(string cardId, params string[] labelIdsToAdd)
53
        {
54
            return await AddLabelsToCardAsync(cardId, CancellationToken.None, labelIdsToAdd.Distinct().ToArray());
×
55
        }
×
56

57
        /// <summary>
58
        /// Adds one or more labels to a card by their IDs.
59
        /// </summary>
60
        /// <param name="cardId">ID of the card to add labels to</param>
61
        /// <param name="cancellationToken">Cancellation Token</param>
62
        /// <param name="labelIdsToAdd">One or more IDs of labels to add</param>
63
        /// <returns>The updated card with the added labels</returns>
64
        public async Task<Card> AddLabelsToCardAsync(string cardId, CancellationToken cancellationToken = default, params string[] labelIdsToAdd)
65
        {
66
            var card = await GetCardAsync(cardId, cancellationToken);
20✔
67
            var missing = labelIdsToAdd.Where(x => !card.LabelIds.Contains(x)).ToList();
88✔
68

69
            if (missing.Count == 0)
20✔
70
            {
71
                return card; //All already There
1✔
72
            }
73

74
            //Need update
75
            card.LabelIds.AddRange(missing);
19✔
76
            return await UpdateCardAsync(cardId, new List<CardUpdate>
19✔
77
            {
19✔
78
                CardUpdate.Labels(card.LabelIds.Distinct().ToList())
19✔
79
            }, cancellationToken);
19✔
80
        }
20✔
81

82
        /// <summary>
83
        /// Removes one or more labels from a card by their IDs.
84
        /// </summary>
85
        /// <param name="cardId">ID of the card to remove labels from</param>
86
        /// <param name="labelIdsToRemove">One or more IDs of labels to remove</param>
87
        /// <returns>The updated card with the labels removed</returns>
88
        public async Task<Card> RemoveLabelsFromCardAsync(string cardId, params string[] labelIdsToRemove)
89
        {
90
            return await RemoveLabelsFromCardAsync(cardId, CancellationToken.None, labelIdsToRemove);
1✔
91
        }
1✔
92

93
        /// <summary>
94
        /// Removes one or more labels from a card by their IDs.
95
        /// </summary>
96
        /// <param name="cardId">ID of the card to remove labels from</param>
97
        /// <param name="cancellationToken">Cancellation Token</param>
98
        /// <param name="labelIdsToRemove">One or more IDs of labels to remove</param>
99
        /// <returns>The updated card with the labels removed</returns>
100
        public async Task<Card> RemoveLabelsFromCardAsync(string cardId, CancellationToken cancellationToken, params string[] labelIdsToRemove)
101
        {
102
            var card = await GetCardAsync(cardId, cancellationToken);
3✔
103
            var toRemove = labelIdsToRemove.Where(x => card.LabelIds.Contains(x)).ToList();
6✔
104
            if (toRemove.Count == 0)
3✔
105
            {
106
                return card; //All not there
1✔
107
            }
108

109
            //Need update
110
            card.LabelIds = card.LabelIds.Except(toRemove).ToList();
2✔
111
            return await UpdateCardAsync(cardId, new List<CardUpdate>
2✔
112
            {
2✔
113
                CardUpdate.Labels(card.LabelIds.Distinct().ToList())
2✔
114
            }, cancellationToken);
2✔
115
        }
3✔
116

117
        /// <summary>
118
        /// Removes all labels from a card, leaving it without any labels.
119
        /// </summary>
120
        /// <param name="cardId">ID of the card to remove all labels from</param>
121
        /// <param name="cancellationToken">Cancellation Token</param>
122
        /// <returns>The updated card with all labels removed</returns>
123
        public async Task<Card> RemoveAllLabelsFromCardAsync(string cardId, CancellationToken cancellationToken = default)
124
        {
125
            return await UpdateCardAsync(cardId, new List<CardUpdate>
2✔
126
            {
2✔
127
                CardUpdate.Labels(new List<string>())
2✔
128
            }, cancellationToken);
2✔
129
        }
2✔
130

131
        /// <summary>
132
        /// Updates the definition of a label (Name and Color).
133
        /// </summary>
134
        /// <param name="labelWithUpdates">The label object containing the updated name and/or color</param>
135
        /// <param name="cancellationToken">Cancellation Token</param>
136
        /// <returns>The updated label</returns>
137
        public async Task<Label> UpdateLabelAsync(Label labelWithUpdates, CancellationToken cancellationToken = default)
138
        {
139
            return await _apiRequestController.Put<Label>($"{UrlPaths.Labels}/{labelWithUpdates.Id}", cancellationToken, _queryParametersBuilder.GetViaQueryParameterAttributes(labelWithUpdates));
46✔
140
        }
46✔
141

142
        /// <summary>
143
        /// Adds a new label to the board. (Not to be confused with 'AddLabelsToCardAsync', which assigns labels to cards.)
144
        /// </summary>
145
        /// <param name="label">The definition of the new label to add</param>
146
        /// <param name="cancellationToken">Cancellation Token</param>
147
        /// <returns>The newly created label</returns>
148
        public async Task<Label> AddLabelAsync(Label label, CancellationToken cancellationToken = default)
149
        {
150
            return await _apiRequestController.Post<Label>($"{UrlPaths.Labels}", cancellationToken, _queryParametersBuilder.GetViaQueryParameterAttributes(label));
22✔
151
        }
22✔
152
    }
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc