View Javadoc
1   /*
2    * The MIT License (MIT)
3    *
4    * Copyright (c) 2013-2026 The Coveralls Maven Plugin Project Contributors:
5    *     https://github.com/hazendaz/coveralls-maven-plugin/graphs/contributors
6    *
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   *
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
24   */
25  package org.eluder.coveralls.maven.plugin.service;
26  
27  import java.util.Map;
28  import java.util.Properties;
29  
30  /**
31   * Service implementation for Shippable.
32   * <p>
33   * https://shippable.com/
34   */
35  public class Shippable extends AbstractServiceSetup {
36  
37      /** The Constant SHIPPABLE_NAME. */
38      public static final String SHIPPABLE_NAME = "shippable";
39  
40      /** The Constant SHIPPABLE. */
41      public static final String SHIPPABLE = "SHIPPABLE";
42  
43      /** The Constant SHIPPABLE_BUILD_NUMBER. */
44      public static final String SHIPPABLE_BUILD_NUMBER = "SHIPPABLE_BUILD_NUMBER";
45  
46      /** The Constant SHIPPABLE_BUILD_ID. */
47      public static final String SHIPPABLE_BUILD_ID = "SHIPPABLE_BUILD_ID";
48  
49      /** The Constant SHIPPABLE_BRANCH. */
50      public static final String SHIPPABLE_BRANCH = "BRANCH";
51  
52      /** The Constant SHIPPABLE_COMMIT. */
53      public static final String SHIPPABLE_COMMIT = "COMMIT";
54  
55      /** The Constant SHIPPABLE_PULL_REQUEST. */
56      public static final String SHIPPABLE_PULL_REQUEST = "PULL_REQUEST";
57  
58      /**
59       * Instantiates a new shippable.
60       *
61       * @param env
62       *            the env
63       */
64      public Shippable(final Map<String, String> env) {
65          super(env);
66      }
67  
68      @Override
69      public boolean isSelected() {
70          return Boolean.parseBoolean(this.getProperty(Shippable.SHIPPABLE));
71      }
72  
73      @Override
74      public String getName() {
75          return Shippable.SHIPPABLE_NAME;
76      }
77  
78      @Override
79      public String getBuildNumber() {
80          return this.getProperty(Shippable.SHIPPABLE_BUILD_NUMBER);
81      }
82  
83      @Override
84      public String getBuildUrl() {
85          return "https://app.shippable.com/builds/" + this.getProperty(Shippable.SHIPPABLE_BUILD_ID);
86      }
87  
88      @Override
89      public String getBranch() {
90          return this.getProperty(Shippable.SHIPPABLE_BRANCH);
91      }
92  
93      @Override
94      public String getPullRequest() {
95          final var pullRequest = this.getProperty(Shippable.SHIPPABLE_PULL_REQUEST);
96          if ("false".equals(pullRequest)) {
97              return null;
98          }
99          return pullRequest;
100     }
101 
102     @Override
103     public Properties getEnvironment() {
104         final var environment = new Properties();
105         this.addProperty(environment, "shippable_build_number", this.getProperty(Shippable.SHIPPABLE_BUILD_NUMBER));
106         this.addProperty(environment, "shippable_build_id", this.getProperty(Shippable.SHIPPABLE_BUILD_ID));
107         this.addProperty(environment, "shippable_build_url", this.getBuildUrl());
108         this.addProperty(environment, "branch", this.getProperty(Shippable.SHIPPABLE_BRANCH));
109         this.addProperty(environment, "commit_sha", this.getProperty(Shippable.SHIPPABLE_COMMIT));
110         return environment;
111     }
112 
113 }