Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2025 the original author or authors.
* <p>
* Licensed under the Moderne Source Available License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://docs.moderne.io/licensing/moderne-source-available-license
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.github;

import org.jspecify.annotations.Nullable;

import java.util.*;

import static java.util.Arrays.asList;
import static java.util.Collections.*;

// Ecosystems absent from this map are deliberately left alone rather than mapped to a broader
// pattern such as the whole directory, which would grant ownership beyond what Dependabot covered.
final class DependabotEcosystemManifests {

static final String GITHUB_ACTIONS = "github-actions";

private static final Map<String, List<String>> MANIFESTS;

static {
Map<String, List<String>> manifests = new LinkedHashMap<>();
manifests.put("bundler", asList("Gemfile", "Gemfile.lock"));
manifests.put("cargo", asList("Cargo.toml", "Cargo.lock"));
manifests.put("composer", asList("composer.json", "composer.lock"));
manifests.put("devcontainers", asList(".devcontainer/devcontainer.json", ".devcontainer.json"));
manifests.put("docker", singletonList("Dockerfile"));
manifests.put("docker-compose", asList("docker-compose.yml", "docker-compose.yaml"));
manifests.put("elm", singletonList("elm.json"));
manifests.put("gitsubmodule", singletonList(".gitmodules"));
manifests.put("gomod", asList("go.mod", "go.sum"));
manifests.put("gradle", asList("build.gradle", "build.gradle.kts", "gradle/libs.versions.toml"));
manifests.put("helm", asList("Chart.yaml", "Chart.lock"));
manifests.put("maven", singletonList("pom.xml"));
manifests.put("mix", asList("mix.exs", "mix.lock"));
manifests.put("npm", asList("package.json", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"));
manifests.put("nuget", asList("*.csproj", "packages.config"));
manifests.put("pip", asList("requirements.txt", "pyproject.toml", "Pipfile", "Pipfile.lock"));
manifests.put("pub", asList("pubspec.yaml", "pubspec.lock"));
manifests.put("swift", asList("Package.swift", "Package.resolved"));
manifests.put("terraform", singletonList("*.tf"));
manifests.put("uv", asList("pyproject.toml", "uv.lock"));
MANIFESTS = unmodifiableMap(manifests);
}

private DependabotEcosystemManifests() {
}

static boolean isKnown(@Nullable String ecosystem) {
return GITHUB_ACTIONS.equals(ecosystem) || MANIFESTS.containsKey(ecosystem);
}

static List<String> patternsFor(@Nullable String ecosystem, String directory) {
String prefix = normalizeDirectory(directory);
if (GITHUB_ACTIONS.equals(ecosystem)) {
// A non-root directory points at a composite action definition rather than the workflows
return "/".equals(prefix) ?
singletonList("/.github/workflows/") :
asList(prefix + "action.yml", prefix + "action.yaml");
}
List<String> manifests = MANIFESTS.get(ecosystem);
if (manifests == null) {
return emptyList();
}
List<String> patterns = new ArrayList<>(manifests.size());
for (String manifest : manifests) {
patterns.add(prefix + manifest);
}
return patterns;
}

// Dependabot directories are repository-root relative and not searched recursively, so they
// map onto CODEOWNERS patterns anchored with a leading slash
private static String normalizeDirectory(String directory) {
String trimmed = directory.trim();
while (trimmed.startsWith("/")) {
trimmed = trimmed.substring(1);
}
while (trimmed.endsWith("/")) {
trimmed = trimmed.substring(0, trimmed.length() - 1);
}
return trimmed.isEmpty() ? "/" : "/" + trimmed + "/";
}
}
Loading
Loading