Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override and Exclude Known Team Names #48

Merged
merged 1 commit into from
Aug 30, 2023
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
Expand Up @@ -15,17 +15,46 @@
*/
package org.openrewrite.jenkins.github;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;

class ArtifactIdTeamNameGenerator implements TeamNameGenerator<TeamNameInput> {
private static final String EXCLUDE = "EXCLUDE";
private static final String ORG = "@jenkinsci/";
private final Map<String, String> artifactIdAdvice = loadAdvice();

@Override
public String generate(TeamNameInput input) {
String artifactId = input.getArtifactId();
String advice = artifactIdAdvice.get(artifactId);
if (EXCLUDE.equalsIgnoreCase(advice)) {
return "";
}
if (advice != null) {
return ORG + advice;
}
String withoutParent = artifactId;
if (artifactId.endsWith("-parent") || artifactId.endsWith("-plugin")) {
withoutParent = artifactId.substring(0, artifactId.lastIndexOf('-'));
}
return ("@jenkinsci/" + (withoutParent + "-plugin-developers")).toLowerCase(Locale.ROOT);
return (ORG + (withoutParent + "-plugin-developers")).toLowerCase(Locale.ROOT);
}

private static Map<String, String> loadAdvice() {
Properties p = new Properties();
try (InputStream is = ArtifactIdTeamNameGenerator.class.getResourceAsStream("teams.properties")) {
Map<String, String> o = new HashMap<>();
p.load(is);
for (Map.Entry<Object, Object> entry : p.entrySet()) {
o.put((String) entry.getKey(), (String) entry.getValue());
}
return o;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public boolean isValid(@Nullable String name) {
*/
private static Set<String> banned() {
Set<String> banned = new HashSet<>();
banned.add("@jenkinsci/custom-tools-plugin-developers");
banned.add("@jenkinsci/-plugin-developers");
return banned;
}
Expand Down
286 changes: 286 additions & 0 deletions src/main/resources/org/openrewrite/jenkins/github/teams.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
#
# Copyright 2023 the original author or authors.
# <p>
# Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
# <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.
#

ace-editor=EXCLUDE
adaptive-disconnector=EXCLUDE
allure-jenkins-plugin=allure-plugin-developers
AnchorChain=anchor-chain-plugin-developers
ApicaLoadtest=apica-loadtest-plugin-developers
appdynamics-dashboard=codecentric-appdynamics-plugin-developers
appscan=ibm-asoc-plugin-developers
archived-artifact-url-viewer=EXCLUDE
asakusa-satellite-plugin=EXCLUDE
assembla-auth=EXCLUDE
attention=EXCLUDE
aws-java-sdk-cloudformation=aws-java-sdk-plugin-developers
aws-java-sdk-codebuild=aws-java-sdk-plugin-developers
aws-java-sdk-ec2=aws-java-sdk-plugin-developers
aws-java-sdk-ecr=aws-java-sdk-plugin-developers
aws-java-sdk-ecs=aws-java-sdk-plugin-developers
aws-java-sdk-efs=aws-java-sdk-plugin-developers
aws-java-sdk-elasticbeanstalk=aws-java-sdk-plugin-developers
aws-java-sdk-iam=aws-java-sdk-plugin-developers
aws-java-sdk-kinesis=aws-java-sdk-plugin-developers
aws-java-sdk-logs=aws-java-sdk-plugin-developers
aws-java-sdk-minimal=aws-java-sdk-plugin-developers
aws-java-sdk-parent=aws-java-sdk-plugin-developers
aws-java-sdk-secretsmanager=aws-java-sdk-plugin-developers
aws-java-sdk-sns=aws-java-sdk-plugin-developers
aws-java-sdk-sqs=aws-java-sdk-plugin-developers
aws-java-sdk-ssm=aws-java-sdk-plugin-developers
aws-yum-parameter=EXCLUDE
backlog=EXCLUDE
backup-interrupt-plugin=EXCLUDE
bds-plugin=EXCLUDE
behave-testresults-publisher=EXCLUDE
bigpanda-jenkins=bigpanda-plugin-developers
bitbucket-oauth=EXCLUDE
bitbucket-scm-filter-aged-refs=EXCLUDE
bitbucket-scm-filter-jira-validator=EXCLUDE
bitbucket-scm-trait-commit-skip=EXCLUDE
BlameSubversion=EXCLUDE
BlazeMeterJenkinsPlugin=blazemeter-plugin-developers
blueocean-bitbucket-pipeline=blueocean-plugin-developers
blueocean-commons=blueocean-plugin-developers
blueocean-config=blueocean-plugin-developers
blueocean-core-js=blueocean-plugin-developers
blueocean-dashboard=blueocean-plugin-developers
blueocean-events=blueocean-plugin-developers
blueocean-github-pipeline=blueocean-plugin-developers
blueocean-git-pipeline=blueocean-plugin-developers
blueocean-i18n=blueocean-plugin-developers
blueocean-jira=blueocean-plugin-developers
blueocean-jwt=blueocean-plugin-developers
blueocean-personalization=blueocean-plugin-developers
blueocean-pipeline-api-impl=blueocean-plugin-developers
blueocean-pipeline-scm-api=blueocean-plugin-developers
blueocean-rest=blueocean-plugin-developers
blueocean-rest-impl=blueocean-plugin-developers
blueocean-web=blueocean-plugin-developers
bootstrap=EXCLUDE
browser-axis-plugin=EXCLUDE
bugzilla=EXCLUDE
build-environment=EXCLUDE
build-env-propagator=EXCLUDE
buildgraph-view=buildgraph-view-developers
build-requester=EXCLUDE
build-steps-from-json=EXCLUDE
build-token-root=EXCLUDE
build-view-column=EXCLUDE
built-on-column=builton-column-plugin-developers
carl=EXCLUDE
chosen-views-tabbar=EXCLUDE
cli-commander=EXCLUDE
clone-workspace-scm=jenkins-clone-workspace-scm-plugin-developers
cloudbees-bitbucket-branch-source=bitbucket-branch-source-plugin-developers
cluster-stats=EXCLUDE
cocoapods-integration=EXCLUDE
codedeploy=aws-codedeploy-plugin-developers
collabnet-automic-deploy=collabnet-uc4-deploy-plugin-developers
ColumnsPlugin=EXCLUDE
cucumber-perf=cucumber-performance-plugin-developers
cucumber-trends-report=cucumber-trend-report-plugin-developers
CustomHistory=custom-history-plugin-developers
custom-tools-plugin=customtools-plugin-developers
cygwin-process-killer=EXCLUDE
dark-theme=dark-theme-developers
declarative-pipeline-migration-assistant-api=convert-to-declarative-developers
declarative-pipeline-migration-assistant=convert-to-declarative-developers
declarative-pipeline-migration-assistant-parent=convert-to-declarative-developers
delete-log-plugin=EXCLUDE
delivery-pipeline-plugin=EXCLUDE
delta-cloud=EXCLUDE
dependencyanalyzer=EXCLUDE
dependency-check-jenkins-plugin=dependency-check-plugin-developers
deploydb=EXCLUDE
deployhub=deploy-hub-plugin-developers
description-column-plugin=EXCLUDE
design-library=EXCLUDE
drecycler=EXCLUDE
dtkit-api=dtkit-plugin-developers
dumpling=EXCLUDE
dynamic_extended_choice_parameter=dynamic-extended-choice-parameter-plugin-developers
dynatrace-dashboard=dynatrace-plugin-developers
ec2-cloud-axis=EXCLUDE
ec2-deployment-dashboard=EXCLUDE
embotics-vcommander=EXCLUDE
emmacoveragecolumn=EXCLUDE
emotional-jenkins-plugin=EXCLUDE
enhanced-old-build-discarder=EXCLUDE
environment-labels-setter=EXCLUDE
environment-manager=environment-manager-tools-plugin-developers
escaped-markup-plugin=EXCLUDE
event-announcer=EXCLUDE
excludeMatrixParent=exclude-matrix-parent-developers
exclusive-label-plugin=EXCLUDE
feature-branch-notifier=EXCLUDE
flow=EXCLUDE
GatekeeperPlugin=gatekeeper-plugin-developers
gerrit-code-review=gerrit-plugin-developers
github-organization-folder=EXCLUDE
github-scm-filter-aged-refs=scm-filter-aged-refs-plugin-developers
github-scm-filter-jira-validator=scm-filter-jira-validator-plugin-developers
github-scm-trait-commit-skip=scm-trait-commit-skip-plugin-developers
gitlab-merge-request-jenkins=gitlab-merge-request-builder-plugin-developers
google-api-client-plugin=EXCLUDE
google-git-notes-publisher=EXCLUDE
graphiteIntegrator=graphiteintegrator-developers
groovy-remote=EXCLUDE
handlebars=js-libs-developers
hp-operations-orchestration-automation-execution-plugin=EXCLUDE
http_request=http-request-plugin-developers
hudson-pview-plugin=EXCLUDE
hudson-wsclean-plugin=wsclean-plugin-developers
ibm-application-security=ibm-asoc-plugin-developers
icon-shim=EXCLUDE
idobata-notifier=EXCLUDE
inedo-buildmaster=buildmaster-plugin-developers
instance-identity=instance-identity-module-developers
internetmeme=internet-meme-plugin-developers
ios-device-connector=EXCLUDE
issue-link=EXCLUDE
itms-for-jira=itms-junit-report-publisher-plugin-developers
jbpm-embedded-plugin=EXCLUDE
jclouds-jenkins=jclouds-plugin-developers
jenkinsci-appspider-plugin=appspider-build-scanner-plugin-developers
jenkins-design-language=jenkins-design-language-developers
jenkins-flowdock-plugin=flowdock-plugin-developers
jenkins-jira-issue-updater=jira-issue-updater-plugin-developers
jenkins-multijob-plugin=tikal-multijob-plugin-developers
jenkins-reviewbot=EXCLUDE
jenkins-tag-cloud-plugin=tag-cloud-plugin-developers
jenkins-testswarm-plugin=testswarm-plugin-developers
jenkinswalldisplay=walldisplay-plugin-developers
job-parameter-summary=EXCLUDE
jobtemplates=EXCLUDE
jquery-detached=jquery-detached-developers
jslint=jslint-jenkins-plugin-developers
jucies=EXCLUDE
kanboard=kanboard-publisher-plugin-developers
keepSlaveOffline=keep-slave-offline-developers
kiuwanJenkinsPlugin=kiuwan-plugin-developers
kubernetes-pipeline-devops-steps=kubernetes-pipeline-plugin-developers
labmanager=EXCLUDE
lenientshutdown=lenient-shutdown-plugin-developers
list-git-branches-parameter=list-git-branches-plugin-developers
loaderio-jenkins-plugin=loaderio-plugin-developers
mailcommander=mail-commander-plugin-developers
matrix-combinations-parameter=matrix-combinations-plugin-developers
maven-release-cascade=EXCLUDE
mina-sshd-api-common=mina-sshd-api-plugin-developers
mina-sshd-api-core=mina-sshd-api-plugin-developers
mina-sshd-api-scp=mina-sshd-api-plugin-developers
mina-sshd-api-sftp=mina-sshd-api-plugin-developers
mission-control-view=mission-control-view-developers
momentjs=EXCLUDE
multi-branch-project-plugin=EXCLUDE
multi-module-tests-publisher=EXCLUDE
NegotiateSSO=negotiate-sso-plugin-developers
neoload-jenkins-plugin=neoload-plugin-developers
nexus-jenkins-plugin=nexus-platform-plugin-developers
nexus-task-runner=EXCLUDE
node-sharing-executor=foreman-node-sharing-plugin-developers
node-sharing-orchestrator=foreman-node-sharing-plugin-developers
node-sharing-parent=foreman-node-sharing-plugin-developers
nopmdcheck=EXCLUDE
nopmdverifytrac=EXCLUDE
numeraljs=EXCLUDE
octoperf=octoperf-jci-plugin-developers
openscada-jenkins-exporter=EXCLUDE
openshift-k8s-credentials=openshift-token-kubernetes-credentials-plugin-developers
paaslane-estimate=paaslane-plugin-developers
package-drone=EXCLUDE
package-parameter=EXCLUDE
parent-pom=EXCLUDE
pegdown-formatter=EXCLUDE
pending-changes=pendingchanges-plugin-developers
performance-signature-dynatrace=performance-signature-dynatrace-plugin-developers
performance-signature-dynatracesaas=performance-signature-dynatrace-plugin-developers
performance-signature-parent-pom=performance-signature-dynatrace-plugin-developers
performance-signature-ui=performance-signature-dynatrace-plugin-developers
performance-signature-viewer=performance-signature-dynatrace-plugin-developers
periodic-reincarnation=EXCLUDE
pipeline-aggregator-view=aggregated-pipeline-view-plugin-developers
pipeline-model-api=pipeline-model-definition-plugin-developers
pipeline-model-declarative-agent=pipeline-model-definition-plugin-developers
pipeline-model-extensions=pipeline-model-definition-plugin-developers
pipeline-model-parent=pipeline-model-definition-plugin-developers
pipeline-rest-api=pipeline-stage-view-plugin-developers
pipeline-stage-tags-metadata=pipeline-model-definition-plugin-developers
pipeline-utility-steps=workflow-utility-steps-plugin-developers
pom2config=EXCLUDE
pom=EXCLUDE
portshift-scanner=EXCLUDE
pragprog=EXCLUDE
prereq-buildstep=EXCLUDE
preSCMbuildstep=pre-scm-buildstep-plugin-developers
PrioritySorter=priority-sorter-plugin-developers
project-description-setter=EXCLUDE
project-health-report=EXCLUDE
project-inheritance=EXCLUDE
radiatorviewplugin=radiatorview-plugin-developers
rallyBuild=EXCLUDE
rapiddeploy-jenkins=rapiddeploy-plugin-developers
readonly-parameters=EXCLUDE
repository=maven-repository-plugin-developers
restricted-register=EXCLUDE
rocketchatnotifier=rocket-chat-notifier-plugin-developers
rubymotion=EXCLUDE
run-condition-extras=EXCLUDE
run-selector=EXCLUDE
scalable-amazon-ecs=EXCLUDE
search-all-results-plugin=EXCLUDE
seleniumhtmlreport=seleniumhtmlreport-developers
show-build-parameters=EXCLUDE
sicci_for_xcode=sicci-for-xcode-plugin-developers
signal-killer=signal-killer-developers
simpleclearcase=EXCLUDE
skype-notifier=skype-im-plugin-developers
skytap=skytap-cloud-plugin-developers
sladiator-notifier=EXCLUDE
slave-proxy=EXCLUDE
slave-status=EXCLUDE
snakeyaml-api=snakeyaml-plugin-developers
splunk-devops-extend=splunk-devops-plugin-developers
SSSCM=EXCLUDE
startup-trigger-plugin=startup-trigger-plugin-plugin-developers
StashBranchParameter=stash-branch-parameters-plugin-developers
suite-test-groups-publisher=EXCLUDE
summary_report=EXCLUDE
svn-workspace-cleaner=EXCLUDE
synergy=synergy_scm-plugin-developers
tag-profiler=EXCLUDE
tap=EXCLUDE
terminate-ssh-processes-plugin=EXCLUDE
testflo-for-jira-test-management-automation=testflo-test-results-publisher-plugin-developers
testng-plugin=testng-plugin-plugin-developers
teststudiomobiletesting=EXCLUDE
thinBackup=thin-backup-plugin-developers
throttle-concurrents=throttle-concurrent-builds-plugin-developers
tinfoil-scan=tinfoil-security-plugin-developers
tool-labels-plugin=EXCLUDE
TwilioNotifier=twilio-notifier-plugin-developers
uno-choice=active-choices-plugin-developers
update-sites-manager=EXCLUDE
url-auth=EXCLUDE
view-cloner=EXCLUDE
violation-columns=EXCLUDE
workplace-notifier=workplace-plugin-developers
writable-filesystem-monitor=EXCLUDE
xtrigger-api=xtrigger-lib-developers
yet-another-docker-plugin=EXCLUDE
zdevops=EXCLUDE
zmq-event-publisher=EXCLUDE
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void shouldNoOpIfInvalidTeamGenerated() {
<artifactId>plugin</artifactId>
<version>4.72</version>
</parent>
<artifactId>custom-tools-plugin</artifactId>
<artifactId>tool-labels-plugin</artifactId>
<version>0.1</version>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
package org.openrewrite.jenkins.github;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.CsvSource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static org.assertj.core.api.Assertions.assertThat;

class ArtifactIdTeamNameGeneratorTest {
Expand All @@ -38,4 +44,29 @@ void shouldGenerateExpectedTeamName(String artifactId, String expected) {
String actual = generator.generate(new TeamNameInput(artifactId));
assertThat(actual).isEqualTo(expected);
}

@ParameterizedTest
@CsvFileSource(resources = "/updatecenter-artifactIds.txt")
void shouldGenerateValidTeamName(String artifactId) {
String actual = generator.generate(new TeamNameInput(artifactId));
if (!actual.isEmpty()) {
boolean exists = exists(actual);
assertThat(exists).as("artifactId %s's team name is %s", artifactId, actual).isTrue();
}
}

private static boolean exists(String team) {
try (InputStream is = ArtifactIdTeamNameGeneratorTest.class.getResourceAsStream("/plugin-developers-teams.txt")) {
assertThat(is).isNotNull();
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
return br.lines()
.filter(s -> !s.isBlank())
.map(String::trim)
.map(s -> "@jenkinsci/" + s)
.anyMatch(s -> s.equals(team));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Loading