Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Statuses |
|
| 1.2;1.2 | ||||
Statuses$StatusCreate |
|
| 1.2;1.2 | ||||
Statuses$StatusCreate$AjcClosure1 |
|
| 1.2;1.2 | ||||
Statuses$StatusCreate$AjcClosure3 |
|
| 1.2;1.2 | ||||
Statuses$StatusCreate$AjcClosure5 |
|
| 1.2;1.2 | ||||
Statuses$StatusCreate$AjcClosure7 |
|
| 1.2;1.2 | ||||
Statuses$StatusCreate$AjcClosure9 |
|
| 1.2;1.2 |
1 | 0 | /** |
2 | * Copyright (c) 2013-2017, jcabi.com | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: 1) Redistributions of source code must retain the above | |
8 | * copyright notice, this list of conditions and the following | |
9 | * disclaimer. 2) Redistributions in binary form must reproduce the above | |
10 | * copyright notice, this list of conditions and the following | |
11 | * disclaimer in the documentation and/or other materials provided | |
12 | * with the distribution. 3) Neither the name of the jcabi.com nor | |
13 | * the names of its contributors may be used to endorse or promote | |
14 | * products derived from this software without specific prior written | |
15 | * permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
19 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
20 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
21 | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
28 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | package com.jcabi.github; | |
31 | ||
32 | import com.google.common.base.Optional; | |
33 | import com.jcabi.aspects.Immutable; | |
34 | import com.jcabi.aspects.Loggable; | |
35 | import java.io.IOException; | |
36 | import javax.json.Json; | |
37 | import javax.json.JsonObject; | |
38 | import javax.json.JsonObjectBuilder; | |
39 | import lombok.EqualsAndHashCode; | |
40 | import lombok.ToString; | |
41 | ||
42 | /** | |
43 | * Github status. | |
44 | * | |
45 | * <p>The status exposes all available properties through its | |
46 | * {@code json()} method. However, it is recommended to use its | |
47 | * "smart" decorator, which helps you to get access to all JSON properties, | |
48 | * for example: | |
49 | * | |
50 | * <pre> URL url = new Status.Smart(status).url();</pre> | |
51 | * | |
52 | * @author Marcin Cylke (marcin.cylke+github@gmail.com) | |
53 | * @version $Id: 4271b32a989d020b30a9ca80c3583ef591c6afe0 $ | |
54 | * @since 0.23 | |
55 | * @see <a href="https://developer.github.com/v3/repos/statuses/">Repo statuses</a> | |
56 | */ | |
57 | @Immutable | |
58 | @SuppressWarnings("PMD.TooManyMethods") | |
59 | public interface Statuses extends JsonReadable { | |
60 | ||
61 | /** | |
62 | * Associated commit. | |
63 | * @return Commit | |
64 | */ | |
65 | Commit commit(); | |
66 | ||
67 | /** | |
68 | * Create new status. | |
69 | * @param status Add this status | |
70 | * @throws java.io.IOException If there is any I/O problem | |
71 | * @return The added status | |
72 | * @see <a href="https://developer.github.com/v3/repos/statuses/#create-a-status">Create a Status</a> | |
73 | */ | |
74 | Status create( | |
75 | final StatusCreate status | |
76 | ) throws IOException; | |
77 | ||
78 | /** | |
79 | * List all statuses for a given ref. | |
80 | * @param ref It can be a SHA, a branch name, or a tag name. | |
81 | * @return Iterable of statuses | |
82 | * @see <a href="https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref">List Statuses for a specific Ref</a> | |
83 | */ | |
84 | Iterable<Status> list( | |
85 | final String ref | |
86 | ); | |
87 | ||
88 | /** | |
89 | * Data to use when creating a new GitHub commit status. | |
90 | * | |
91 | * @author Chris Rebert (github@rebertia.com) | |
92 | * @version $Id: 4271b32a989d020b30a9ca80c3583ef591c6afe0 $ | |
93 | * @since 0.24 | |
94 | * @see <a href="https://developer.github.com/v3/repos/statuses/#create-a-status">Create a Status</a> | |
95 | */ | |
96 | 0 | @ToString |
97 | @Loggable(Loggable.DEBUG) | |
98 | 0 | @EqualsAndHashCode(of = { |
99 | "state", | |
100 | "description", | |
101 | "context", | |
102 | "targeturl" | |
103 | }) | |
104 | final class StatusCreate implements JsonReadable { | |
105 | /** | |
106 | * State. | |
107 | */ | |
108 | private final transient Status.State state; | |
109 | /** | |
110 | * Description. | |
111 | */ | |
112 | private final transient String description; | |
113 | /** | |
114 | * Context string. | |
115 | */ | |
116 | private final transient Optional<String> context; | |
117 | /** | |
118 | * Target URL. | |
119 | */ | |
120 | private final transient Optional<String> targeturl; | |
121 | ||
122 | /** | |
123 | * Public ctor. | |
124 | * @param stat State | |
125 | */ | |
126 | public StatusCreate( | |
127 | final Status.State stat | |
128 | ) { | |
129 | 10 | this( |
130 | stat, | |
131 | "", | |
132 | 5 | Optional.<String>absent(), |
133 | 5 | Optional.<String>absent() |
134 | ); | |
135 | 5 | } |
136 | ||
137 | /** | |
138 | * Private ctor. | |
139 | * @param stat State | |
140 | * @param desc Description | |
141 | * @param cntxt Context | |
142 | * @param target Target URL | |
143 | * @checkstyle ParameterNumberCheck (10 lines) | |
144 | */ | |
145 | private StatusCreate( | |
146 | final Status.State stat, | |
147 | final String desc, | |
148 | final Optional<String> cntxt, | |
149 | final Optional<String> target | |
150 | 17 | ) { |
151 | 17 | this.state = stat; |
152 | 17 | this.description = desc; |
153 | 17 | this.context = cntxt; |
154 | 17 | this.targeturl = target; |
155 | 17 | } |
156 | ||
157 | /** | |
158 | * Returns a StatusCreate with the given state. | |
159 | * @param stat State | |
160 | * @return StatusCreate | |
161 | */ | |
162 | public StatusCreate withState(final Status.State stat) { | |
163 | 0 | return new StatusCreate( |
164 | stat, | |
165 | this.description, | |
166 | this.context, | |
167 | this.targeturl | |
168 | ); | |
169 | } | |
170 | ||
171 | /** | |
172 | * Returns a StatusCreate with the given description. | |
173 | * @param desc Description | |
174 | * @return StatusCreate | |
175 | */ | |
176 | public StatusCreate withDescription(final String desc) { | |
177 | 8 | return new StatusCreate( |
178 | this.state, | |
179 | desc, | |
180 | this.context, | |
181 | this.targeturl | |
182 | ); | |
183 | } | |
184 | ||
185 | /** | |
186 | * Returns a StatusCreate with the given context. | |
187 | * @param cntxt Context | |
188 | * @return StatusCreate | |
189 | */ | |
190 | public StatusCreate withContext(final Optional<String> cntxt) { | |
191 | 8 | return new StatusCreate( |
192 | this.state, | |
193 | this.description, | |
194 | cntxt, | |
195 | this.targeturl | |
196 | ); | |
197 | } | |
198 | ||
199 | /** | |
200 | * Returns a StatusCreate with the given target URL. | |
201 | * @param target Target URL | |
202 | * @return StatusCreate | |
203 | */ | |
204 | public StatusCreate withTargetUrl(final Optional<String> target) { | |
205 | 8 | return new StatusCreate( |
206 | this.state, | |
207 | this.description, | |
208 | this.context, | |
209 | target | |
210 | ); | |
211 | } | |
212 | ||
213 | @Override | |
214 | public JsonObject json() { | |
215 | 10 | final JsonObjectBuilder builder = Json.createObjectBuilder() |
216 | 5 | .add("state", this.state.identifier()) |
217 | 5 | .add("description", this.description); |
218 | 5 | if (this.context.isPresent()) { |
219 | 4 | builder.add("context", this.context.get()); |
220 | } | |
221 | 5 | if (this.targeturl.isPresent()) { |
222 | 4 | builder.add("target_url", this.targeturl.get()); |
223 | } | |
224 | 5 | return builder.build(); |
225 | } | |
226 | } | |
227 | } |