2
2
using System ;
3
3
using System . Threading . Tasks ;
4
4
5
- namespace DotNetDocs . Tools . GraphQLQueries
5
+ namespace DotNetDocs . Tools . GraphQLQueries ;
6
+
7
+ /// <summary>
8
+ /// Add or remove a label.
9
+ /// </summary>
10
+ /// <remarks>
11
+ /// This class performs a mutation to remove or
12
+ /// add a label to a "labelable" node.
13
+ /// </remarks>
14
+ public class AddOrRemoveLabelMutation
6
15
{
7
- /// <summary>
8
- /// Add or remove a label.
9
- /// </summary>
10
- /// <remarks>
11
- /// This class performs a mutation to remove or
12
- /// add a label to a "labelable" node.
13
- /// </remarks>
14
- public class AddOrRemoveLabelMutation
15
- {
16
- private static readonly string removeLabelMutationText =
16
+ private static readonly string removeLabelMutationText =
17
17
@"mutation RemoveLabels($nodeID: ID!, $labelIDs: [ID!]!) {
18
18
removeLabelsFromLabelable(input: {
19
19
labelableId:$nodeID
@@ -28,7 +28,7 @@ public class AddOrRemoveLabelMutation
28
28
}
29
29
" ;
30
30
31
- private static readonly string addLabelMutationText =
31
+ private static readonly string addLabelMutationText =
32
32
@"mutation AddLabels($nodeID: ID!, $labelIDs: [ID!]!) {
33
33
addLabelsToLabelable(input: {
34
34
labelableId:$nodeID
@@ -42,52 +42,51 @@ public class AddOrRemoveLabelMutation
42
42
}
43
43
}
44
44
" ;
45
- private readonly IGitHubClient client ;
46
- private readonly string nodeId ;
47
- private readonly string labelId ;
48
- private readonly bool addLabel ;
45
+ private readonly IGitHubClient client ;
46
+ private readonly string nodeId ;
47
+ private readonly string labelId ;
48
+ private readonly bool addLabel ;
49
49
50
- /// <summary>
51
- /// Construct the query object.
52
- /// </summary>
53
- /// <param name="client">The client.</param>
54
- /// <param name="nodeId">The node to modify</param>
55
- /// <param name="labelId">The id of the label to add or remove</param>
56
- /// <param name="add">True to add, false to remove.</param>
57
- public AddOrRemoveLabelMutation ( IGitHubClient client , string nodeId , string labelId , bool add )
58
- {
59
- this . client = client ?? throw new ArgumentNullException ( paramName : nameof ( client ) , message : "Cannot be null" ) ;
60
- this . nodeId = ! string . IsNullOrWhiteSpace ( nodeId )
61
- ? nodeId
62
- : throw new ArgumentException ( message : "Must not be whitespace" , paramName : nameof ( nodeId ) ) ;
63
- this . labelId = ! string . IsNullOrWhiteSpace ( labelId )
64
- ? labelId
65
- : throw new ArgumentException ( message : "Must not be whitespace" , paramName : nameof ( labelId ) ) ;
66
- this . addLabel = add ;
67
- }
50
+ /// <summary>
51
+ /// Construct the query object.
52
+ /// </summary>
53
+ /// <param name="client">The client.</param>
54
+ /// <param name="nodeId">The node to modify</param>
55
+ /// <param name="labelId">The id of the label to add or remove</param>
56
+ /// <param name="add">True to add, false to remove.</param>
57
+ public AddOrRemoveLabelMutation ( IGitHubClient client , string nodeId , string labelId , bool add )
58
+ {
59
+ this . client = client ?? throw new ArgumentNullException ( paramName : nameof ( client ) , message : "Cannot be null" ) ;
60
+ this . nodeId = ! string . IsNullOrWhiteSpace ( nodeId )
61
+ ? nodeId
62
+ : throw new ArgumentException ( message : "Must not be whitespace" , paramName : nameof ( nodeId ) ) ;
63
+ this . labelId = ! string . IsNullOrWhiteSpace ( labelId )
64
+ ? labelId
65
+ : throw new ArgumentException ( message : "Must not be whitespace" , paramName : nameof ( labelId ) ) ;
66
+ this . addLabel = add ;
67
+ }
68
68
69
- /// <summary>
70
- /// Perform the mutation.
71
- /// </summary>
72
- /// <returns>A task to be awaited.</returns>
73
- /// <remarks>
74
- /// I haven't see failures from the GitHub endpoint reflected
75
- /// in the result packet. However, on rare occasions, the
76
- /// mutation fails. This should be updated once I see why it fails.
77
- /// </remarks>
78
- public async Task PerformMutation ( )
69
+ /// <summary>
70
+ /// Perform the mutation.
71
+ /// </summary>
72
+ /// <returns>A task to be awaited.</returns>
73
+ /// <remarks>
74
+ /// I haven't see failures from the GitHub endpoint reflected
75
+ /// in the result packet. However, on rare occasions, the
76
+ /// mutation fails. This should be updated once I see why it fails.
77
+ /// </remarks>
78
+ public async Task PerformMutation ( )
79
+ {
80
+ var labelPacket = new GraphQLPacket
79
81
{
80
- var labelPacket = new GraphQLPacket
82
+ query = addLabel ? addLabelMutationText : removeLabelMutationText ,
83
+ variables =
81
84
{
82
- query = addLabel ? addLabelMutationText : removeLabelMutationText ,
83
- variables =
84
- {
85
- [ "nodeID" ] = nodeId ,
86
- [ "labelIDs" ] = labelId
87
- }
88
- } ;
89
- var jsonData = await client . PostGraphQLRequestAsync ( labelPacket ) ;
90
- // TODO: check for errors
91
- }
85
+ [ "nodeID" ] = nodeId ,
86
+ [ "labelIDs" ] = labelId
87
+ }
88
+ } ;
89
+ var jsonData = await client . PostGraphQLRequestAsync ( labelPacket ) ;
90
+ // TODO: check for errors
92
91
}
93
92
}
0 commit comments