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

rwjdk / TrelloDotNet / 21438348630

28 Jan 2026 12:32PM UTC coverage: 80.629% (-0.02%) from 80.649%
21438348630

push

github

rwjdk
WIP

2598 of 3512 branches covered (73.97%)

Branch coverage included in aggregate %.

4586 of 5398 relevant lines covered (84.96%)

129.65 hits per line

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

95.74
/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);
34✔
32
        }
34✔
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
            if (options == null)
2✔
44
            {
45
                return await GetLabelsOfBoardAsync(boardId, cancellationToken);
1✔
46
            }
47

48
            return await _apiRequestController.Get<List<Label>>(GetUrlBuilder.GetLabelsOfBoard(boardId), cancellationToken, options.GetParameters());
1✔
49
        }
2✔
50

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

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

74
            if (missing.Count == 0)
20✔
75
            {
76
                return card; //All already There
1✔
77
            }
78

79
            //Need update
80
            card.LabelIds.AddRange(missing);
19✔
81
            return await UpdateCardAsync(cardId, new List<CardUpdate>
19✔
82
            {
19✔
83
                CardUpdate.Labels(card.LabelIds.Distinct().ToList())
19✔
84
            }, cancellationToken);
19✔
85
        }
20✔
86

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

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

114
            //Need update
115
            card.LabelIds = card.LabelIds.Except(toRemove).ToList();
2✔
116
            return await UpdateCardAsync(cardId, new List<CardUpdate>
2✔
117
            {
2✔
118
                CardUpdate.Labels(card.LabelIds.Distinct().ToList())
2✔
119
            }, cancellationToken);
2✔
120
        }
3✔
121

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

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

147
        /// <summary>
148
        /// Adds a new label to the board. (Not to be confused with 'AddLabelsToCardAsync', which assigns labels to cards.)
149
        /// </summary>
150
        /// <param name="label">The definition of the new label to add</param>
151
        /// <param name="cancellationToken">Cancellation Token</param>
152
        /// <returns>The newly created label</returns>
153
        public async Task<Label> AddLabelAsync(Label label, CancellationToken cancellationToken = default)
154
        {
155
            return await _apiRequestController.Post<Label>($"{UrlPaths.Labels}", cancellationToken, _queryParametersBuilder.GetViaQueryParameterAttributes(label));
22✔
156
        }
22✔
157
    }
158
}
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