Skip to content

Commit

Permalink
Remove unneeded code (jenkins-infra#4081)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored Sep 10, 2024
1 parent a61815c commit 266d4d1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 428 deletions.
7 changes: 1 addition & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ node('maven-21 || (java&&linux)') {

if (dryRun) {
try {
withCredentials([
usernamePassword(credentialsId: 'jiraUser', passwordVariable: 'JIRA_PASSWORD', usernameVariable: 'JIRA_USERNAME')
]) {
sh 'java -DdryRun=true' + javaArgs
}
sh 'java -DdryRun=true' + javaArgs
} catch(ignored) {
if (fileExists('checks-title.txt')) {
def title = readFile file: 'checks-title.txt', encoding: 'utf-8'
Expand All @@ -76,7 +72,6 @@ node('maven-21 || (java&&linux)') {
title: 'All checks passed'
} else {
withCredentials([
usernamePassword(credentialsId: 'jiraUser', passwordVariable: 'JIRA_PASSWORD', usernameVariable: 'JIRA_USERNAME'),
string(credentialsId: 'artifactoryAdminToken', variable: 'ARTIFACTORY_TOKEN'),
usernamePassword(credentialsId: 'jenkins-infra-bot-github-token', passwordVariable: 'GITHUB_TOKEN', usernameVariable: 'GITHUB_USERNAME')
]) {
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ A complete example with two trackers:
```yaml
issues:
- github: 'jenkinsci/configuration-as-code-plugin' # The preferred issue tracker
- jira: 'configuration-as-code-plugin' # A secondary issue tracker is the Jira component 'configuration-as-code-plugin'
- jira: '23170' # A secondary issue tracker is the Jira component id 23170 for 'configuration-as-code-plugin'
report: false # No new issues should be reported here
```

Jira component id can be found at: https://issues.jenkins.io/rest/api/2/project/JENKINS/components

When GitHub Issues is used, there would be some duplicated content in the file (between `github` and `issues` entries) which can be resolved by using a YAML reference.
Example:

Expand Down
2 changes: 1 addition & 1 deletion permissions/plugin-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: "repository"
github: "jenkinsci/maven-repository-plugin"
issues:
- jira: "maven-repository-plugin"
- jira: '15802' # maven-repository-plugin
paths:
- "jenkins/repository"
developers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class ArtifactoryPermissionsUpdater {

Map<String, Set<TeamDefinition>> teamsByName = loadTeams()

Map<String, Set<String>> pathsByGithub = new TreeMap()
Map<String, List> issueTrackersByPlugin = new TreeMap()
Map<String, Set<String>> pathsByGithub = new TreeMap<>()
Map<String, List> issueTrackersByPlugin = new TreeMap<>()
Map<String, List<Definition>> cdEnabledComponentsByGitHub = new TreeMap<>()
Map<String, List<String>> maintainersByComponent = new HashMap<>()

Expand Down Expand Up @@ -176,11 +176,11 @@ class ArtifactoryPermissionsUpdater {
issueTrackersByPlugin.put(definition.name, definition.issues.collect { tracker ->
if (tracker.isJira() || tracker.isGitHubIssues()) {
def ret = [type: tracker.getType(), reference: tracker.getReference()]
def viewUrl = tracker.getViewUrl(JiraAPI.getInstance())
def viewUrl = tracker.getViewUrl()
if (viewUrl) {
ret += [ viewUrl: viewUrl ]
}
def reportUrl = tracker.getReportUrl(JiraAPI.getInstance())
def reportUrl = tracker.getReportUrl()
if (reportUrl) {
ret += [ reportUrl: reportUrl ]
}
Expand Down Expand Up @@ -243,7 +243,7 @@ class ArtifactoryPermissionsUpdater {
if (!definition.cd?.exclusive) {
users definition.developers.collectEntries { developer ->
def existsInArtifactory = KnownUsers.existsInArtifactory(developer)
def existsInJira = KnownUsers.existsInJira(developer) || JiraAPI.getInstance().isUserPresent(developer)
def existsInJira = KnownUsers.existsInJira(developer)

if (!existsInArtifactory && !existsInJira) {
reportChecksApiDetails(developer + " needs to log in to Artifactory and Jira",
Expand Down Expand Up @@ -287,7 +287,7 @@ class ArtifactoryPermissionsUpdater {
}
} else {
definition.developers.each { developer ->
def existsInJira = KnownUsers.existsInJira(developer) || JiraAPI.getInstance().isUserPresent(developer)
def existsInJira = KnownUsers.existsInJira(developer)

if (!existsInJira) {
reportChecksApiDetails(developer + " needs to log in to Jira",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -32,10 +31,6 @@ public static class SecurityContacts {
* Some invalid input may result in both returning {@code false}, in that case other methods will throw exceptions.
*/
public static class IssueTracker {
public interface JiraComponentSource {
String getComponentId(String componentName) throws IOException;
}

private static final Logger LOGGER = Logger.getLogger(IssueTracker.class.getName());

public String jira;
Expand All @@ -50,6 +45,9 @@ public boolean isJira() {
LOGGER.log(Level.INFO, "Unexpected Jira component name, skipping: " + jira);
return false;
}

assertJiraIdFormatValid();

return true;
}

Expand All @@ -65,44 +63,29 @@ public boolean isGitHubIssues() {
}

@SuppressFBWarnings(value = "NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD",
justification = "All calls are guarded by jira null check in isJira()")
private String loadComponentId(JiraComponentSource source) throws IOException {
String jiraComponentId = jira;
justification = "All calls are guarded by jira null check in isJira()")
private void assertJiraIdFormatValid() {
if (!jira.matches("[0-9]+")) {
// CreateIssueDetails needs the numeric Jira component ID
jiraComponentId = source.getComponentId(jira);
if (jiraComponentId == null) {
LOGGER.warning("Failed to determine Jira component ID for '" + jira + "', the component may not exist");
return null;
}
throw new IllegalArgumentException("Jira component ID must be numeric, but got: " + jira);
}
return jiraComponentId;
}

public String getViewUrl(JiraComponentSource source) throws IOException {
public String getViewUrl() {
if (isJira()) {
final String id = loadComponentId(source);
if (id != null) {
return "https://issues.jenkins.io/issues/?jql=component=" + id;
}
return null;
return "https://issues.jenkins.io/issues/?jql=component=" + jira;
}
if (isGitHubIssues()) {
return "https://github.com/" + github + "/issues";
}
throw new IllegalStateException("Invalid issue tracker: " + github + " / " + jira);
}

public String getReportUrl(JiraComponentSource source) throws IOException {
public String getReportUrl() {
if (!report) {
return null;
}
if (isJira()) {
final String id = loadComponentId(source);
if (id != null) {
return "https://www.jenkins.io/participate/report-issue/redirect/#" + id;
}
return null;
return "https://www.jenkins.io/participate/report-issue/redirect/#" + jira;
}
if (isGitHubIssues()) {
return "https://github.com/" + github + "/issues/new/choose"; // The 'choose' URL works even when there are no issue templates
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class KnownUsers {
private static final String ARTIFACTORY_USER_NAMES_URL = System.getProperty("artifactoryUserNamesJsonListUrl", "https://reports.jenkins.io/artifactory-ldap-users-report.json");
private static final String JIRA_USER_NAMES_URL = System.getProperty("jiraUserNamesJsonListUrl", "https://reports.jenkins.io/jira-users-report.json");

private static Set<String> knownArtifactoryUsers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
private static Set<String> knownJiraUsers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
private static final Set<String> knownArtifactoryUsers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
private static final Set<String> knownJiraUsers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);

static {
try {
Expand Down
Loading

0 comments on commit 266d4d1

Please sign in to comment.