| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Status |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure1 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure11 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure13 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure15 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure17 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure19 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure21 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure3 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure5 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure7 |
|
| 1.3333333333333333;1.333 | ||||
| Status$Smart$AjcClosure9 |
|
| 1.3333333333333333;1.333 | ||||
| Status$State |
|
| 1.3333333333333333;1.333 |
| 1 | 8 | /** |
| 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 java.text.ParseException; | |
| 37 | import java.util.Date; | |
| 38 | import java.util.Locale; | |
| 39 | import javax.json.JsonObject; | |
| 40 | import lombok.EqualsAndHashCode; | |
| 41 | import lombok.ToString; | |
| 42 | ||
| 43 | /** | |
| 44 | * GitHub commit status. | |
| 45 | * @author Marcin Cylke (marcin.cylke+github@gmail.com) | |
| 46 | * @version $Id: 6dd8bf03756f6e21105d4bb520491d7b2c6cbf5c $ | |
| 47 | * @since 0.23 | |
| 48 | */ | |
| 49 | @Immutable | |
| 50 | @SuppressWarnings("PMD.TooManyMethods") | |
| 51 | public interface Status extends JsonReadable { | |
| 52 | /** | |
| 53 | * Associated commit. | |
| 54 | * @return Commit | |
| 55 | */ | |
| 56 | Commit commit(); | |
| 57 | ||
| 58 | /** | |
| 59 | * Get its ID number. | |
| 60 | * @return ID number | |
| 61 | */ | |
| 62 | int identifier(); | |
| 63 | ||
| 64 | /** | |
| 65 | * Get its URL. | |
| 66 | * @return URL | |
| 67 | */ | |
| 68 | String url(); | |
| 69 | ||
| 70 | /** | |
| 71 | * States of Status API. | |
| 72 | * @author Marcin Cylke(marcin.cylke+github@gmail.com) | |
| 73 | * @version $Id: 6dd8bf03756f6e21105d4bb520491d7b2c6cbf5c $ | |
| 74 | */ | |
| 75 | 6 | enum State implements StringEnum { |
| 76 | /** | |
| 77 | * Pending state. | |
| 78 | */ | |
| 79 | 1 | PENDING("pending"), |
| 80 | /** | |
| 81 | * Success state. | |
| 82 | */ | |
| 83 | 1 | SUCCESS("success"), |
| 84 | /** | |
| 85 | * Error state. | |
| 86 | */ | |
| 87 | 1 | ERROR("error"), |
| 88 | /** | |
| 89 | * Failure state. | |
| 90 | */ | |
| 91 | 1 | FAILURE("failure"); |
| 92 | ||
| 93 | /** | |
| 94 | * Commit status state identifier string. | |
| 95 | */ | |
| 96 | private final transient String state; | |
| 97 | ||
| 98 | /** | |
| 99 | * Private ctor. | |
| 100 | * @param stat Commit status state identifier string | |
| 101 | */ | |
| 102 | State( | |
| 103 | final String stat | |
| 104 | 4 | ) { |
| 105 | 4 | this.state = stat; |
| 106 | 4 | } |
| 107 | ||
| 108 | @Override | |
| 109 | public String identifier() { | |
| 110 | 6 | return this.state; |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * Get enum value from identifier string. | |
| 115 | * @param ident Commit status state string | |
| 116 | * @return Corresponding State | |
| 117 | */ | |
| 118 | public static State forValue( | |
| 119 | final String ident | |
| 120 | ) { | |
| 121 | 4 | return State.valueOf(ident.toUpperCase(Locale.ENGLISH)); |
| 122 | } | |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Smart Status with extra features. | |
| 127 | * @author Chris Rebert (github@chrisrebert.com) | |
| 128 | * @version $Id: 6dd8bf03756f6e21105d4bb520491d7b2c6cbf5c $ | |
| 129 | * @since 0.24 | |
| 130 | */ | |
| 131 | @Immutable | |
| 132 | 0 | @ToString |
| 133 | @Loggable(Loggable.DEBUG) | |
| 134 | 0 | @EqualsAndHashCode(of = { "status", "jsn" }) |
| 135 | final class Smart implements Status { | |
| 136 | /** | |
| 137 | * Encapsulated status. | |
| 138 | */ | |
| 139 | private final transient Status status; | |
| 140 | /** | |
| 141 | * SmartJson object for convenient JSON parsing. | |
| 142 | */ | |
| 143 | private final transient SmartJson jsn; | |
| 144 | ||
| 145 | /** | |
| 146 | * Public ctor. | |
| 147 | * @param stat Status | |
| 148 | */ | |
| 149 | public Smart( | |
| 150 | final Status stat | |
| 151 | 17 | ) { |
| 152 | 17 | this.status = stat; |
| 153 | 17 | this.jsn = new SmartJson(stat); |
| 154 | 17 | } |
| 155 | ||
| 156 | /** | |
| 157 | * Get state. | |
| 158 | * @return State as enum | |
| 159 | * @throws IOException If there is an I/O problem | |
| 160 | */ | |
| 161 | public State state() throws IOException { | |
| 162 | 8 | return State.forValue(this.jsn.text("state")); |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * Get URL. | |
| 167 | * @return URL as string. | |
| 168 | * @throws IOException If there is an I/O problem | |
| 169 | */ | |
| 170 | public Optional<String> targetUrl() throws IOException { | |
| 171 | 9 | return Optional.fromNullable( |
| 172 | 3 | this.json().getString("target_url", null) |
| 173 | ); | |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * Get description. | |
| 178 | * @return Description as string. | |
| 179 | * @throws IOException If there is an I/O problem | |
| 180 | */ | |
| 181 | public String description() throws IOException { | |
| 182 | 6 | return this.json().getString("description", ""); |
| 183 | } | |
| 184 | ||
| 185 | /** | |
| 186 | * Get context. | |
| 187 | * @return Context as string | |
| 188 | * @throws IOException If there is an I/O problem | |
| 189 | */ | |
| 190 | public String context() throws IOException { | |
| 191 | 2 | return this.jsn.text("context"); |
| 192 | } | |
| 193 | ||
| 194 | /** | |
| 195 | * When this commit status was created. | |
| 196 | * @return Date of creation | |
| 197 | * @throws IOException If there is any I/O problem | |
| 198 | */ | |
| 199 | public Date createdAt() throws IOException { | |
| 200 | try { | |
| 201 | 3 | return new Github.Time( |
| 202 | 1 | this.jsn.text("created_at") |
| 203 | 1 | ).date(); |
| 204 | 0 | } catch (final ParseException ex) { |
| 205 | 0 | throw new IllegalStateException(ex); |
| 206 | } | |
| 207 | } | |
| 208 | ||
| 209 | /** | |
| 210 | * When this commit status was updated. | |
| 211 | * @return Date of update | |
| 212 | * @throws IOException If there is any I/O problem | |
| 213 | */ | |
| 214 | public Date updatedAt() throws IOException { | |
| 215 | try { | |
| 216 | 3 | return new Github.Time( |
| 217 | 1 | this.jsn.text("updated_at") |
| 218 | 1 | ).date(); |
| 219 | 0 | } catch (final ParseException ex) { |
| 220 | 0 | throw new IllegalStateException(ex); |
| 221 | } | |
| 222 | } | |
| 223 | ||
| 224 | /** | |
| 225 | * Get its creator. | |
| 226 | * @return Creator of the commit status | |
| 227 | * @throws IOException If there is any I/O problem | |
| 228 | */ | |
| 229 | public User creator() throws IOException { | |
| 230 | 3 | return this.status.commit().repo().github() |
| 231 | 1 | .users() |
| 232 | 1 | .get( |
| 233 | 1 | this.status.json() |
| 234 | 1 | .getJsonObject("creator") |
| 235 | 1 | .getString("login") |
| 236 | ); | |
| 237 | } | |
| 238 | ||
| 239 | @Override | |
| 240 | public int identifier() { | |
| 241 | 2 | return this.status.identifier(); |
| 242 | } | |
| 243 | ||
| 244 | @Override | |
| 245 | public String url() { | |
| 246 | 2 | return this.status.url(); |
| 247 | } | |
| 248 | ||
| 249 | @Override | |
| 250 | public Commit commit() { | |
| 251 | 2 | return this.status.commit(); |
| 252 | } | |
| 253 | ||
| 254 | @Override | |
| 255 | public JsonObject json() throws IOException { | |
| 256 | 12 | return this.status.json(); |
| 257 | } | |
| 258 | } | |
| 259 | } |