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

common-workflow-language / cwlviewer / #1997

13 May 2026 05:20PM UTC coverage: 70.25% (-0.08%) from 70.334%
#1997

Pull #751

github

kinow
Undo code deletion, but replace string concatenation by log+parameters
Pull Request #751: Bump org.springframework.boot:spring-boot-starter-parent from 3.1.4 to 4.1.0-RC1

119 of 196 new or added lines in 32 files covered. (60.71%)

20 existing lines in 4 files now uncovered.

1712 of 2437 relevant lines covered (70.25%)

0.7 hits per line

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

82.35
/src/main/java/org/commonwl/view/validation/AbstractGitValidator.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.commonwl.view.validation;
21

22
import java.net.URI;
23
import java.util.Arrays;
24
import java.util.List;
25
import org.apache.commons.lang3.StringUtils;
26
import org.commonwl.view.git.GitDetails;
27
import org.commonwl.view.workflow.WorkflowForm;
28
import org.springframework.validation.Errors;
29

30
/**
31
 * Abstract implementation of a Git validator.
32
 *
33
 * <p>Implementations must provide methods to retrieve the host and the base URL.
34
 */
35
public abstract class AbstractGitValidator implements GitUrlValidator {
1✔
36

37
  /**
38
   * Git host (e.g., github.com).
39
   *
40
   * @return Git host
41
   */
42
  protected abstract String host();
43

44
  /**
45
   * Git repository base URL (e.g., <a href="https://github.com/">...</a><owner>/<repo>.git).
46
   *
47
   * @param owner owner or organisation
48
   * @param repo repository name
49
   * @return a string representation of the Git repository base URL
50
   */
51
  protected abstract String repoBaseUrl(String owner, String repo);
52

53
  @Override
54
  public boolean supports(String url) {
55
    try {
56
      URI uri = URI.create(url);
1✔
57
      return host().equalsIgnoreCase(uri.getHost());
1✔
NEW
58
    } catch (Exception e) {
×
NEW
59
      return false;
×
60
    }
61
  }
62

63
  @Override
64
  public void validate(WorkflowForm form, Errors errors) {}
1✔
65

66
  @Override
67
  public GitDetails parse(String url, WorkflowForm form) {
68
    final URI uri = URI.create(url);
1✔
69

70
    List<String> parts = Arrays.stream(uri.getPath().split("/")).filter(p -> !p.isBlank()).toList();
1✔
71

72
    if (parts.size() < 2) return null;
1✔
73

74
    String owner = parts.get(0);
1✔
75
    String repo = parts.get(1);
1✔
76

77
    String repoUrl = repoBaseUrl(owner, repo);
1✔
78

79
    String branch = null;
1✔
80
    String path = null;
1✔
81

82
    // Detect branch/path from /tree/ or /blob/
83
    for (int i = 2; i < parts.size(); i++) {
1✔
84
      String p = parts.get(i);
1✔
85

86
      if ("tree".equals(p) || "blob".equals(p)) {
1✔
87
        if (i + 1 < parts.size()) {
1✔
88
          branch = parts.get(i + 1);
1✔
89
        }
90
        if (i + 2 < parts.size()) {
1✔
91
          path = String.join("/", parts.subList(i + 2, parts.size()));
1✔
92
        }
93
        break;
94
      }
95
    }
96

97
    // Optional GitHub-style fragment fallback (#branch/path)
98
    String fragment = uri.getFragment();
1✔
99
    if (fragment != null && !fragment.isBlank()) {
1✔
100
      String[] fragParts = fragment.split("/", 2);
1✔
101
      if (branch == null) {
1✔
NEW
102
        branch = fragParts[0];
×
103
      }
104
      if (path == null && fragParts.length > 1) {
1✔
NEW
105
        path = fragParts[1];
×
106
      }
107
    }
108

109
    if (form != null) {
1✔
110
      if (StringUtils.isNotBlank(form.getBranch())) {
1✔
NEW
111
        branch = form.getBranch();
×
112
      }
113
      if (StringUtils.isNotBlank(form.getPath())) {
1✔
NEW
114
        path = form.getPath();
×
115
      }
116
    }
117

118
    return new GitDetails(repoUrl, branch, path);
1✔
119
  }
120
}
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