diff --git a/.mvn/checkstyle.xml b/.mvn/checkstyle.xml
deleted file mode 100644
index 2a0b0984..00000000
--- a/.mvn/checkstyle.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pom.xml b/pom.xml
index 8eb26f41..c0d94a35 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,31 +11,55 @@
gitlab-branch-source
${changelist}
hpi
-
- 999999-SNAPSHOT
- 2.361.4
- jenkinsci/${project.artifactId}-plugin
-
GitLab Branch Source Plugin
GitLab Provides branch source and folder organisation functionality for GitLab Repositories in Jenkins Source Plugin
+ https://github.com/jenkinsci/${project.artifactId}-plugin
+
MIT License
https://opensource.org/licenses/MIT
+
+
+ scm:git:https://github.com/${gitHubRepo}.git
+ scm:git:git@github.com:${gitHubRepo}.git
+ ${scmTag}
+ https://github.com/${gitHubRepo}
+
+
+
+ 999999-SNAPSHOT
+ 2.361.4
+ jenkinsci/${project.artifactId}-plugin
+ false
+
+
+
+
+
+ io.jenkins.tools.bom
+ bom-2.361.x
+ 2025.v816d28f1e04f
+ pom
+ import
+
+
+
+
- org.jenkins-ci.plugins
- apache-httpcomponents-client-4-api
+ io.jenkins.plugins
+ gitlab-api
org.jenkins-ci.plugins
- scm-api
+ apache-httpcomponents-client-4-api
- io.jenkins.plugins
- gitlab-api
+ org.jenkins-ci.plugins
+ branch-api
org.jenkins-ci.plugins
@@ -43,7 +67,7 @@
org.jenkins-ci.plugins
- plain-credentials
+ git
org.jenkins-ci.plugins
@@ -51,7 +75,25 @@
org.jenkins-ci.plugins
- git
+ plain-credentials
+
+
+ org.jenkins-ci.plugins
+ scm-api
+
+
+ org.jenkins-ci.plugins.workflow
+ workflow-job
+
+
+ io.jenkins
+ configuration-as-code
+ test
+
+
+ io.jenkins.configuration-as-code
+ test-harness
+ test
org.hamcrest
@@ -63,6 +105,11 @@
pipeline-build-step
test
+
+ org.jenkins-ci.plugins
+ pipeline-stage-step
+ test
+
org.jenkins-ci.plugins.workflow
workflow-api
@@ -80,32 +127,27 @@
org.jenkins-ci.plugins.workflow
- workflow-scm-step
+ workflow-durable-task-step
test
org.jenkins-ci.plugins.workflow
- workflow-step-api
+ workflow-multibranch
test
org.jenkins-ci.plugins.workflow
- workflow-support
+ workflow-scm-step
test
org.jenkins-ci.plugins.workflow
- workflow-multibranch
- test
-
-
- org.jenkins-ci.plugins
- pipeline-stage-step
+ workflow-step-api
test
org.jenkins-ci.plugins.workflow
- workflow-durable-task-step
+ workflow-support
test
@@ -113,86 +155,7 @@
mockito-core
test
-
- io.jenkins
- configuration-as-code
- test
-
-
- io.jenkins.configuration-as-code
- test-harness
- test
-
-
- org.jenkins-ci.plugins
- branch-api
-
-
- org.jenkins-ci.plugins.workflow
- workflow-job
-
-
-
-
- io.jenkins.tools.bom
- bom-2.361.x
- 2025.v816d28f1e04f
- import
- pom
-
-
-
-
- https://github.com/jenkinsci/${project.artifactId}-plugin
-
-
- scm:git:https://github.com/${gitHubRepo}.git
- scm:git:git@github.com:${gitHubRepo}.git
- https://github.com/${gitHubRepo}
- ${scmTag}
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 3.2.0
-
-
- com.puppycrawl.tools
- checkstyle
- 9.3
-
-
-
-
-
-
-
- maven-checkstyle-plugin
-
- ${project.basedir}/.mvn/checkstyle.xml
- true
-
- ${project.build.sourceDirectory}
-
-
- ${project.build.testSourceDirectory}
-
-
-
-
-
- check
-
-
-
-
-
-
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/AbstractGitLabSCMHeadEvent.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/AbstractGitLabSCMHeadEvent.java
index 40f8110a..fcfc894a 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/AbstractGitLabSCMHeadEvent.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/AbstractGitLabSCMHeadEvent.java
@@ -78,5 +78,4 @@ public boolean isMatch(@NonNull SCM scm) {
protected abstract Map headsFor(GitLabSCMSource source);
public abstract GitLabWebHookCause getCause();
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait.java
index 5496f7bd..337382a7 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchDiscoveryTrait.java
@@ -69,7 +69,6 @@ public int getStrategyId() {
@Restricted(NoExternalUse.class)
public boolean isBuildBranch() {
return (strategyId & 1) != 0;
-
}
/**
@@ -168,15 +167,13 @@ public ListBoxModel doFillStrategyIdItems() {
/**
* Trusts branches from the origin repository.
*/
- public static class BranchSCMHeadAuthority extends
- SCMHeadAuthority {
+ public static class BranchSCMHeadAuthority extends SCMHeadAuthority {
/**
* {@inheritDoc}
*/
@Override
- protected boolean checkTrusted(@NonNull SCMSourceRequest request,
- @NonNull BranchSCMHead head) {
+ protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull BranchSCMHead head) {
return true;
}
@@ -191,8 +188,7 @@ public static class DescriptorImpl extends SCMHeadAuthorityDescriptor {
* {@inheritDoc}
*/
@Override
- public boolean isApplicableToOrigin(
- @NonNull Class extends SCMHeadOrigin> originClass) {
+ public boolean isApplicableToOrigin(@NonNull Class extends SCMHeadOrigin> originClass) {
return SCMHeadOrigin.Default.class.isAssignableFrom(originClass);
}
@@ -204,8 +200,6 @@ public boolean isApplicableToOrigin(
public String getDisplayName() {
return Messages.BranchDiscoveryTrait_authorityDisplayName();
}
-
-
}
}
@@ -223,7 +217,7 @@ public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead he
for (MergeRequest m : ((GitLabSCMSourceRequest) request).getMergeRequests()) {
// only match if the merge request is an origin merge request
if (m.getSourceProjectId().equals(m.getTargetProjectId())
- && m.getSourceBranch().equalsIgnoreCase(head.getName())) {
+ && m.getSourceBranch().equalsIgnoreCase(head.getName())) {
return true;
}
}
@@ -245,7 +239,7 @@ public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead he
if (head instanceof BranchSCMHead && request instanceof GitLabSCMSourceRequest) {
for (MergeRequest m : ((GitLabSCMSourceRequest) request).getMergeRequests()) {
if (m.getSourceProjectId().equals(m.getTargetProjectId())
- && !m.getSourceBranch().equalsIgnoreCase(head.getName())) {
+ && !m.getSourceBranch().equalsIgnoreCase(head.getName())) {
return true;
}
}
@@ -254,4 +248,3 @@ public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead he
}
}
}
-
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchSCMRevision.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchSCMRevision.java
index ae03a2df..e39fba6a 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchSCMRevision.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BranchSCMRevision.java
@@ -8,4 +8,3 @@ public BranchSCMRevision(BranchSCMHead head, String hash) {
super(head, hash);
}
}
-
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java
index 222c44fb..1c2cde44 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java
@@ -62,7 +62,9 @@ public String getBuildStatusNameCustomPart() {
*
* @return build status name overwrite option
*/
- public boolean getBuildStatusNameOverwrite() { return buildStatusNameOverwrite; }
+ public boolean getBuildStatusNameOverwrite() {
+ return buildStatusNameOverwrite;
+ }
/**
* Our descriptor.
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabCauseUtils.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabCauseUtils.java
index 1c16f3c6..df7ba9ac 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabCauseUtils.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabCauseUtils.java
@@ -10,27 +10,27 @@ public static int defaultListSize(List> anyList) {
return anyList == null ? 0 : anyList.size();
}
- public static String defaultLabelString (LabelType labelType) {
+ public static String defaultLabelString(LabelType labelType) {
return labelType == null ? "" : labelType.toString();
}
- public static String defaultBooleanString(Boolean bool) {
+ public static String defaultBooleanString(Boolean bool) {
return bool == null ? "" : bool.toString();
}
- public static String defaultVisibilityString(AccessLevel accessLevel) {
+ public static String defaultVisibilityString(AccessLevel accessLevel) {
return accessLevel == null ? "" : accessLevel.toString();
}
- public static String defaultDateString(Date date) {
+ public static String defaultDateString(Date date) {
return date == null ? "" : date.toString();
}
- public static String defaultIntString(Integer val) {
+ public static String defaultIntString(Integer val) {
return val == null ? "" : val.toString();
}
- public static String defaultLongString(Long val) {
+ public static String defaultLongString(Long val) {
return val == null ? "" : val.toString();
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestCauseData.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestCauseData.java
index 3e9e00bb..848769bc 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestCauseData.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestCauseData.java
@@ -1,11 +1,5 @@
package io.jenkins.plugins.gitlabbranchsource.Cause;
-import java.util.HashMap;
-import java.util.Map;
-import org.gitlab4j.api.webhook.MergeRequestEvent;
-import org.kohsuke.stapler.export.Exported;
-import org.kohsuke.stapler.export.ExportedBean;
-
import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultBooleanString;
import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultDateString;
import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultIntString;
@@ -15,6 +9,12 @@
import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultVisibilityString;
import static org.apache.commons.lang.StringUtils.defaultString;
+import java.util.HashMap;
+import java.util.Map;
+import org.gitlab4j.api.webhook.MergeRequestEvent;
+import org.kohsuke.stapler.export.Exported;
+import org.kohsuke.stapler.export.ExportedBean;
+
@ExportedBean
public class GitLabMergeRequestCauseData {
@@ -22,110 +22,352 @@ public class GitLabMergeRequestCauseData {
public GitLabMergeRequestCauseData(MergeRequestEvent mergeRequestEvent) {
this.variables.put("GITLAB_OBJECT_KIND", defaultString(MergeRequestEvent.OBJECT_KIND));
- this.variables.put("GITLAB_USER_NAME", defaultString(mergeRequestEvent.getUser().getName()));
- this.variables.put("GITLAB_USER_USERNAME", defaultString(mergeRequestEvent.getUser().getUsername()));
- this.variables.put("GITLAB_USER_AVATAR_URL", defaultString(mergeRequestEvent.getUser().getAvatarUrl()));
- this.variables.put("GITLAB_PROJECT_ID", defaultLongString(mergeRequestEvent.getProject().getId()));
- this.variables.put("GITLAB_PROJECT_NAME", defaultString(mergeRequestEvent.getProject().getName()));
- this.variables.put("GITLAB_PROJECT_DESCRIPTION", defaultString(mergeRequestEvent.getProject().getDescription()));
- this.variables.put("GITLAB_PROJECT_WEB_URL", defaultString(mergeRequestEvent.getProject().getWebUrl()));
- this.variables.put("GITLAB_PROJECT_AVATAR_URL", defaultString(mergeRequestEvent.getProject().getAvatarUrl()));
- this.variables.put("GITLAB_PROJECT_GIT_SSH_URL", defaultString(mergeRequestEvent.getProject().getGitSshUrl()));
- this.variables.put("GITLAB_PROJECT_GIT_HTTP_URL", defaultString(mergeRequestEvent.getProject().getGitHttpUrl()));
- this.variables.put("GITLAB_PROJECT_NAMESPACE", defaultString(mergeRequestEvent.getProject().getNamespace()));
- this.variables.put("GITLAB_PROJECT_VISIBILITY_LEVEL", defaultVisibilityString(mergeRequestEvent.getProject().getVisibilityLevel()));
- this.variables.put("GITLAB_PROJECT_PATH_NAMESPACE", defaultString(mergeRequestEvent.getProject().getPathWithNamespace()));
- this.variables.put("GITLAB_PROJECT_CI_CONFIG_PATH", defaultString(mergeRequestEvent.getProject().getCiConfigPath()));
- this.variables.put("GITLAB_PROJECT_DEFAULT_BRANCH", defaultString(mergeRequestEvent.getProject().getDefaultBranch()));
- this.variables.put("GITLAB_PROJECT_HOMEPAGE", defaultString(mergeRequestEvent.getProject().getHomepage()));
- this.variables.put("GITLAB_PROJECT_URL", defaultString(mergeRequestEvent.getProject().getUrl()));
- this.variables.put("GITLAB_PROJECT_SSH_URL", defaultString(mergeRequestEvent.getProject().getSshUrl()));
- this.variables.put("GITLAB_PROJECT_HTTP_URL", defaultString(mergeRequestEvent.getProject().getHttpUrl()));
- this.variables.put("GITLAB_REPO_NAME", defaultString(mergeRequestEvent.getRepository().getName()));
- this.variables.put("GITLAB_REPO_URL", defaultString(mergeRequestEvent.getRepository().getUrl()));
- this.variables.put("GITLAB_REPO_DESCRIPTION", defaultString(mergeRequestEvent.getRepository().getDescription()));
- this.variables.put("GITLAB_REPO_HOMEPAGE", defaultString(mergeRequestEvent.getRepository().getHomepage()));
- this.variables.put("GITLAB_REPO_GIT_SSH_URL", defaultString(mergeRequestEvent.getRepository().getGit_ssh_url()));
- this.variables.put("GITLAB_REPO_GIT_HTTP_URL", defaultString(mergeRequestEvent.getRepository().getGit_http_url()));
- this.variables.put("GITLAB_REPO_VISIBILITY_LEVEL", defaultVisibilityString(mergeRequestEvent.getRepository().getVisibility_level()));
- this.variables.put("GITLAB_OA_ID", defaultLongString(mergeRequestEvent.getObjectAttributes().getId()));
- this.variables.put("GITLAB_OA_TARGET_BRANCH", defaultString(mergeRequestEvent.getObjectAttributes().getTargetBranch()));
- this.variables.put("GITLAB_OA_SOURCE_BRANCH", defaultString(mergeRequestEvent.getObjectAttributes().getSourceBranch()));
- this.variables.put("GITLAB_OA_SOURCE_PROJECT_ID", defaultLongString(mergeRequestEvent.getObjectAttributes().getSourceProjectId()));
- this.variables.put("GITLAB_OA_AUTHOR_ID", defaultLongString(mergeRequestEvent.getObjectAttributes().getAuthorId()));
- this.variables.put("GITLAB_OA_ASSIGNEE_ID", defaultLongString(mergeRequestEvent.getObjectAttributes().getAssigneeId()));
- this.variables.put("GITLAB_OA_TITLE", defaultString(mergeRequestEvent.getObjectAttributes().getTitle()));
- this.variables.put("GITLAB_OA_CREATED_AT", defaultDateString(mergeRequestEvent.getObjectAttributes().getCreatedAt()));
- this.variables.put("GITLAB_OA_UPDATED_AT", defaultDateString(mergeRequestEvent.getObjectAttributes().getUpdatedAt()));
- this.variables.put("GITLAB_OA_MILESTONE_ID", defaultLongString(mergeRequestEvent.getObjectAttributes().getMilestoneId()));
- this.variables.put("GITLAB_OA_STATE", defaultString(mergeRequestEvent.getObjectAttributes().getState()));
- this.variables.put("GITLAB_OA_MERGE_STATUS", defaultString(mergeRequestEvent.getObjectAttributes().getMergeStatus()));
- this.variables.put("GITLAB_OA_TARGET_PROJECT_ID", defaultLongString(mergeRequestEvent.getObjectAttributes().getTargetProjectId()));
- this.variables.put("GITLAB_OA_IID", defaultLongString(mergeRequestEvent.getObjectAttributes().getIid()));
- this.variables.put("GITLAB_OA_DESCRIPTION", defaultString(mergeRequestEvent.getObjectAttributes().getDescription()));
- this.variables.put("GITLAB_OA_SOURCE_NAME", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getName()));
- this.variables.put("GITLAB_OA_SOURCE_DESCRIPTION", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getDescription()));
- this.variables.put("GITLAB_OA_SOURCE_WEB_URL", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getWebUrl()));
- this.variables.put("GITLAB_OA_SOURCE_AVATAR_URL", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getAvatarUrl()));
- this.variables.put("GITLAB_OA_SOURCE_GIT_SSH_URL", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getGitSshUrl()));
- this.variables.put("GITLAB_OA_SOURCE_GIT_HTTP_URL", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getGitHttpUrl()));
- this.variables.put("GITLAB_OA_SOURCE_NAMESPACE", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getNamespace()));
- this.variables.put("GITLAB_OA_SOURCE_VISIBILITY_LEVEL", defaultVisibilityString(mergeRequestEvent.getObjectAttributes().getSource().getVisibilityLevel()));
- this.variables.put("GITLAB_OA_SOURCE_PATH_WITH_NAMESPACE", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getPathWithNamespace()));
- this.variables.put("GITLAB_OA_SOURCE_DEFAULT_BRANCH", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getDefaultBranch()));
- this.variables.put("GITLAB_OA_SOURCE_HOMEPAGE", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getHomepage()));
- this.variables.put("GITLAB_OA_SOURCE_URL", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getUrl()));
- this.variables.put("GITLAB_OA_SOURCE_SSH_URL", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getSshUrl()));
- this.variables.put("GITLAB_OA_SOURCE_HTTP_URL", defaultString(mergeRequestEvent.getObjectAttributes().getSource().getHttpUrl()));
- this.variables.put("GITLAB_OA_TARGET_NAME", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getName()));
- this.variables.put("GITLAB_OA_TARGET_DESCRIPTION", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getDescription()));
- this.variables.put("GITLAB_OA_TARGET_WEB_URL", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getWebUrl()));
- this.variables.put("GITLAB_OA_TARGET_AVATAR_URL", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getAvatarUrl()));
- this.variables.put("GITLAB_OA_TARGET_GIT_SSH_URL", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getGitSshUrl()));
- this.variables.put("GITLAB_OA_TARGET_GIT_HTTP_URL", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getGitHttpUrl()));
- this.variables.put("GITLAB_OA_TARGET_NAMESPACE", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getNamespace()));
- this.variables.put("GITLAB_OA_TARGET_VISIBILITY_LEVEL", defaultVisibilityString(mergeRequestEvent.getObjectAttributes().getTarget().getVisibilityLevel()));
- this.variables.put("GITLAB_OA_TARGET_PATH_WITH_NAMESPACE", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getPathWithNamespace()));
- this.variables.put("GITLAB_OA_TARGET_DEFAULT_BRANCH", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getDefaultBranch()));
- this.variables.put("GITLAB_OA_TARGET_HOMEPAGE", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getHomepage()));
- this.variables.put("GITLAB_OA_TARGE_URL", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getUrl()));
- this.variables.put("GITLAB_OA_TARGET_SSH_URL", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getSshUrl()));
- this.variables.put("GITLAB_OA_TARGET_HTTP_URL", defaultString(mergeRequestEvent.getObjectAttributes().getTarget().getHttpUrl()));
- this.variables.put("GITLAB_OA_LAST_COMMIT_ID", defaultString(mergeRequestEvent.getObjectAttributes().getLastCommit().getId()));
- this.variables.put("GITLAB_OA_LAST_COMMIT_MESSAGE", defaultString(mergeRequestEvent.getObjectAttributes().getLastCommit().getMessage()));
- this.variables.put("GITLAB_OA_LAST_COMMIT_TIMESTAMP", defaultDateString(mergeRequestEvent.getObjectAttributes().getLastCommit().getTimestamp()));
- this.variables.put("GITLAB_OA_LAST_COMMIT_URL", defaultString(mergeRequestEvent.getObjectAttributes().getLastCommit().getUrl()));
- this.variables.put("GITLAB_OA_LAST_COMMIT_AUTHOR_NAME", defaultString(mergeRequestEvent.getObjectAttributes().getLastCommit().getAuthor().getName()));
- this.variables.put("GITLAB_OA_LAST_COMMIT_AUTHOR_EMAIL", defaultString(mergeRequestEvent.getObjectAttributes().getLastCommit().getAuthor().getEmail()));
- this.variables.put("GITLAB_OA_WIP", defaultBooleanString(mergeRequestEvent.getObjectAttributes().getWorkInProgress()));
- this.variables.put("GITLAB_OA_URL", defaultString(mergeRequestEvent.getObjectAttributes().getUrl()));
- this.variables.put("GITLAB_OA_ACTION", defaultString(mergeRequestEvent.getObjectAttributes().getAction()));
- if(mergeRequestEvent.getObjectAttributes().getAssignee() != null) {
- this.variables.put("GITLAB_OA_ASSIGNEE_NAME", defaultString(mergeRequestEvent.getObjectAttributes().getAssignee().getName()));
- this.variables.put("GITLAB_OA_ASSIGNEE_USERNAME", defaultString(mergeRequestEvent.getObjectAttributes().getAssignee().getUsername()));
- this.variables.put("GITLAB_OA_ASSIGNEE_AVATAR_URL", defaultString(mergeRequestEvent.getObjectAttributes().getAssignee().getAvatarUrl()));
+ this.variables.put(
+ "GITLAB_USER_NAME", defaultString(mergeRequestEvent.getUser().getName()));
+ this.variables.put(
+ "GITLAB_USER_USERNAME",
+ defaultString(mergeRequestEvent.getUser().getUsername()));
+ this.variables.put(
+ "GITLAB_USER_AVATAR_URL",
+ defaultString(mergeRequestEvent.getUser().getAvatarUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_ID",
+ defaultLongString(mergeRequestEvent.getProject().getId()));
+ this.variables.put(
+ "GITLAB_PROJECT_NAME",
+ defaultString(mergeRequestEvent.getProject().getName()));
+ this.variables.put(
+ "GITLAB_PROJECT_DESCRIPTION",
+ defaultString(mergeRequestEvent.getProject().getDescription()));
+ this.variables.put(
+ "GITLAB_PROJECT_WEB_URL",
+ defaultString(mergeRequestEvent.getProject().getWebUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_AVATAR_URL",
+ defaultString(mergeRequestEvent.getProject().getAvatarUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_GIT_SSH_URL",
+ defaultString(mergeRequestEvent.getProject().getGitSshUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_GIT_HTTP_URL",
+ defaultString(mergeRequestEvent.getProject().getGitHttpUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_NAMESPACE",
+ defaultString(mergeRequestEvent.getProject().getNamespace()));
+ this.variables.put(
+ "GITLAB_PROJECT_VISIBILITY_LEVEL",
+ defaultVisibilityString(mergeRequestEvent.getProject().getVisibilityLevel()));
+ this.variables.put(
+ "GITLAB_PROJECT_PATH_NAMESPACE",
+ defaultString(mergeRequestEvent.getProject().getPathWithNamespace()));
+ this.variables.put(
+ "GITLAB_PROJECT_CI_CONFIG_PATH",
+ defaultString(mergeRequestEvent.getProject().getCiConfigPath()));
+ this.variables.put(
+ "GITLAB_PROJECT_DEFAULT_BRANCH",
+ defaultString(mergeRequestEvent.getProject().getDefaultBranch()));
+ this.variables.put(
+ "GITLAB_PROJECT_HOMEPAGE",
+ defaultString(mergeRequestEvent.getProject().getHomepage()));
+ this.variables.put(
+ "GITLAB_PROJECT_URL",
+ defaultString(mergeRequestEvent.getProject().getUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_SSH_URL",
+ defaultString(mergeRequestEvent.getProject().getSshUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_HTTP_URL",
+ defaultString(mergeRequestEvent.getProject().getHttpUrl()));
+ this.variables.put(
+ "GITLAB_REPO_NAME",
+ defaultString(mergeRequestEvent.getRepository().getName()));
+ this.variables.put(
+ "GITLAB_REPO_URL",
+ defaultString(mergeRequestEvent.getRepository().getUrl()));
+ this.variables.put(
+ "GITLAB_REPO_DESCRIPTION",
+ defaultString(mergeRequestEvent.getRepository().getDescription()));
+ this.variables.put(
+ "GITLAB_REPO_HOMEPAGE",
+ defaultString(mergeRequestEvent.getRepository().getHomepage()));
+ this.variables.put(
+ "GITLAB_REPO_GIT_SSH_URL",
+ defaultString(mergeRequestEvent.getRepository().getGit_ssh_url()));
+ this.variables.put(
+ "GITLAB_REPO_GIT_HTTP_URL",
+ defaultString(mergeRequestEvent.getRepository().getGit_http_url()));
+ this.variables.put(
+ "GITLAB_REPO_VISIBILITY_LEVEL",
+ defaultVisibilityString(mergeRequestEvent.getRepository().getVisibility_level()));
+ this.variables.put(
+ "GITLAB_OA_ID",
+ defaultLongString(mergeRequestEvent.getObjectAttributes().getId()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_BRANCH",
+ defaultString(mergeRequestEvent.getObjectAttributes().getTargetBranch()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_BRANCH",
+ defaultString(mergeRequestEvent.getObjectAttributes().getSourceBranch()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_PROJECT_ID",
+ defaultLongString(mergeRequestEvent.getObjectAttributes().getSourceProjectId()));
+ this.variables.put(
+ "GITLAB_OA_AUTHOR_ID",
+ defaultLongString(mergeRequestEvent.getObjectAttributes().getAuthorId()));
+ this.variables.put(
+ "GITLAB_OA_ASSIGNEE_ID",
+ defaultLongString(mergeRequestEvent.getObjectAttributes().getAssigneeId()));
+ this.variables.put(
+ "GITLAB_OA_TITLE",
+ defaultString(mergeRequestEvent.getObjectAttributes().getTitle()));
+ this.variables.put(
+ "GITLAB_OA_CREATED_AT",
+ defaultDateString(mergeRequestEvent.getObjectAttributes().getCreatedAt()));
+ this.variables.put(
+ "GITLAB_OA_UPDATED_AT",
+ defaultDateString(mergeRequestEvent.getObjectAttributes().getUpdatedAt()));
+ this.variables.put(
+ "GITLAB_OA_MILESTONE_ID",
+ defaultLongString(mergeRequestEvent.getObjectAttributes().getMilestoneId()));
+ this.variables.put(
+ "GITLAB_OA_STATE",
+ defaultString(mergeRequestEvent.getObjectAttributes().getState()));
+ this.variables.put(
+ "GITLAB_OA_MERGE_STATUS",
+ defaultString(mergeRequestEvent.getObjectAttributes().getMergeStatus()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_PROJECT_ID",
+ defaultLongString(mergeRequestEvent.getObjectAttributes().getTargetProjectId()));
+ this.variables.put(
+ "GITLAB_OA_IID",
+ defaultLongString(mergeRequestEvent.getObjectAttributes().getIid()));
+ this.variables.put(
+ "GITLAB_OA_DESCRIPTION",
+ defaultString(mergeRequestEvent.getObjectAttributes().getDescription()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_NAME",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getName()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_DESCRIPTION",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getDescription()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_WEB_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getWebUrl()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_AVATAR_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getAvatarUrl()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_GIT_SSH_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getGitSshUrl()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_GIT_HTTP_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getGitHttpUrl()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_NAMESPACE",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getNamespace()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_VISIBILITY_LEVEL",
+ defaultVisibilityString(
+ mergeRequestEvent.getObjectAttributes().getSource().getVisibilityLevel()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_PATH_WITH_NAMESPACE",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getPathWithNamespace()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_DEFAULT_BRANCH",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getDefaultBranch()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_HOMEPAGE",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getHomepage()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getUrl()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_SSH_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getSshUrl()));
+ this.variables.put(
+ "GITLAB_OA_SOURCE_HTTP_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getSource().getHttpUrl()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_NAME",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getName()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_DESCRIPTION",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getDescription()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_WEB_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getWebUrl()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_AVATAR_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getAvatarUrl()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_GIT_SSH_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getGitSshUrl()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_GIT_HTTP_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getGitHttpUrl()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_NAMESPACE",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getNamespace()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_VISIBILITY_LEVEL",
+ defaultVisibilityString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getVisibilityLevel()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_PATH_WITH_NAMESPACE",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getPathWithNamespace()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_DEFAULT_BRANCH",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getDefaultBranch()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_HOMEPAGE",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getHomepage()));
+ this.variables.put(
+ "GITLAB_OA_TARGE_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getUrl()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_SSH_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getSshUrl()));
+ this.variables.put(
+ "GITLAB_OA_TARGET_HTTP_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getTarget().getHttpUrl()));
+ this.variables.put(
+ "GITLAB_OA_LAST_COMMIT_ID",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getLastCommit().getId()));
+ this.variables.put(
+ "GITLAB_OA_LAST_COMMIT_MESSAGE",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getLastCommit().getMessage()));
+ this.variables.put(
+ "GITLAB_OA_LAST_COMMIT_TIMESTAMP",
+ defaultDateString(
+ mergeRequestEvent.getObjectAttributes().getLastCommit().getTimestamp()));
+ this.variables.put(
+ "GITLAB_OA_LAST_COMMIT_URL",
+ defaultString(
+ mergeRequestEvent.getObjectAttributes().getLastCommit().getUrl()));
+ this.variables.put(
+ "GITLAB_OA_LAST_COMMIT_AUTHOR_NAME",
+ defaultString(mergeRequestEvent
+ .getObjectAttributes()
+ .getLastCommit()
+ .getAuthor()
+ .getName()));
+ this.variables.put(
+ "GITLAB_OA_LAST_COMMIT_AUTHOR_EMAIL",
+ defaultString(mergeRequestEvent
+ .getObjectAttributes()
+ .getLastCommit()
+ .getAuthor()
+ .getEmail()));
+ this.variables.put(
+ "GITLAB_OA_WIP",
+ defaultBooleanString(mergeRequestEvent.getObjectAttributes().getWorkInProgress()));
+ this.variables.put(
+ "GITLAB_OA_URL",
+ defaultString(mergeRequestEvent.getObjectAttributes().getUrl()));
+ this.variables.put(
+ "GITLAB_OA_ACTION",
+ defaultString(mergeRequestEvent.getObjectAttributes().getAction()));
+ if (mergeRequestEvent.getObjectAttributes().getAssignee() != null) {
+ this.variables.put(
+ "GITLAB_OA_ASSIGNEE_NAME",
+ defaultString(mergeRequestEvent
+ .getObjectAttributes()
+ .getAssignee()
+ .getName()));
+ this.variables.put(
+ "GITLAB_OA_ASSIGNEE_USERNAME",
+ defaultString(mergeRequestEvent
+ .getObjectAttributes()
+ .getAssignee()
+ .getUsername()));
+ this.variables.put(
+ "GITLAB_OA_ASSIGNEE_AVATAR_URL",
+ defaultString(mergeRequestEvent
+ .getObjectAttributes()
+ .getAssignee()
+ .getAvatarUrl()));
}
int totalLabels = defaultListSize(mergeRequestEvent.getLabels());
this.variables.put("GITLAB_LABELS_COUNT", defaultIntString(totalLabels));
- for(int i = 0; i < totalLabels; i++) {
- this.variables.put("GITLAB_LABEL_ID_" + i, defaultLongString(mergeRequestEvent.getLabels().get(i).getId()));
- this.variables.put("GITLAB_LABEL_TITLE_" + i, defaultString(mergeRequestEvent.getLabels().get(i).getTitle()));
- this.variables.put("GITLAB_LABEL_COLOR_" + i, defaultString(mergeRequestEvent.getLabels().get(i).getColor()));
- this.variables.put("GITLAB_LABEL_PROJECT_ID_" + i, defaultLongString(mergeRequestEvent.getLabels().get(i).getProjectId()));
- this.variables.put("GITLAB_LABEL_CREATED_AT_" + i, defaultDateString(mergeRequestEvent.getLabels().get(i).getCreatedAt()));
- this.variables.put("GITLAB_LABEL_UPDATED_AT_" + i, defaultDateString(mergeRequestEvent.getLabels().get(i).getUpdatedAt()));
- this.variables.put("GITLAB_LABEL_TEMPLATE_" + i, defaultBooleanString(mergeRequestEvent.getLabels().get(i).getTemplate()));
- this.variables.put("GITLAB_LABEL_DESCRIPTION_" + i, defaultString(mergeRequestEvent.getLabels().get(i).getDescription()));
- this.variables.put("GITLAB_LABEL_TYPE_" + i, defaultLabelString(mergeRequestEvent.getLabels().get(i).getType()));
- this.variables.put("GITLAB_LABEL_GROUP_ID_" + i, defaultLongString(mergeRequestEvent.getLabels().get(i).getGroupId()));
+ for (int i = 0; i < totalLabels; i++) {
+ this.variables.put(
+ "GITLAB_LABEL_ID_" + i,
+ defaultLongString(mergeRequestEvent.getLabels().get(i).getId()));
+ this.variables.put(
+ "GITLAB_LABEL_TITLE_" + i,
+ defaultString(mergeRequestEvent.getLabels().get(i).getTitle()));
+ this.variables.put(
+ "GITLAB_LABEL_COLOR_" + i,
+ defaultString(mergeRequestEvent.getLabels().get(i).getColor()));
+ this.variables.put(
+ "GITLAB_LABEL_PROJECT_ID_" + i,
+ defaultLongString(mergeRequestEvent.getLabels().get(i).getProjectId()));
+ this.variables.put(
+ "GITLAB_LABEL_CREATED_AT_" + i,
+ defaultDateString(mergeRequestEvent.getLabels().get(i).getCreatedAt()));
+ this.variables.put(
+ "GITLAB_LABEL_UPDATED_AT_" + i,
+ defaultDateString(mergeRequestEvent.getLabels().get(i).getUpdatedAt()));
+ this.variables.put(
+ "GITLAB_LABEL_TEMPLATE_" + i,
+ defaultBooleanString(mergeRequestEvent.getLabels().get(i).getTemplate()));
+ this.variables.put(
+ "GITLAB_LABEL_DESCRIPTION_" + i,
+ defaultString(mergeRequestEvent.getLabels().get(i).getDescription()));
+ this.variables.put(
+ "GITLAB_LABEL_TYPE_" + i,
+ defaultLabelString(mergeRequestEvent.getLabels().get(i).getType()));
+ this.variables.put(
+ "GITLAB_LABEL_GROUP_ID_" + i,
+ defaultLongString(mergeRequestEvent.getLabels().get(i).getGroupId()));
}
- if(mergeRequestEvent.getChanges().getUpdatedById() != null) {
- this.variables.put("GITLAB_CHANGES_UPDATED_BY_ID_PREV", defaultLongString(mergeRequestEvent.getChanges().getUpdatedById().getPrevious()));
- this.variables.put("GITLAB_CHANGES_UPDATED_BY_ID_CURR", defaultLongString(mergeRequestEvent.getChanges().getUpdatedById().getCurrent()));
+ if (mergeRequestEvent.getChanges().getUpdatedById() != null) {
+ this.variables.put(
+ "GITLAB_CHANGES_UPDATED_BY_ID_PREV",
+ defaultLongString(
+ mergeRequestEvent.getChanges().getUpdatedById().getPrevious()));
+ this.variables.put(
+ "GITLAB_CHANGES_UPDATED_BY_ID_CURR",
+ defaultLongString(
+ mergeRequestEvent.getChanges().getUpdatedById().getCurrent()));
}
- if(mergeRequestEvent.getChanges().getUpdatedAt() != null) {
- this.variables.put("GITLAB_CHANGES_UPDATED_AT_PREV", defaultDateString(mergeRequestEvent.getChanges().getUpdatedAt().getPrevious()));
- this.variables.put("GITLAB_CHANGES_UPDATED_AT_CURR", defaultDateString(mergeRequestEvent.getChanges().getUpdatedAt().getPrevious()));
+ if (mergeRequestEvent.getChanges().getUpdatedAt() != null) {
+ this.variables.put(
+ "GITLAB_CHANGES_UPDATED_AT_PREV",
+ defaultDateString(
+ mergeRequestEvent.getChanges().getUpdatedAt().getPrevious()));
+ this.variables.put(
+ "GITLAB_CHANGES_UPDATED_AT_CURR",
+ defaultDateString(
+ mergeRequestEvent.getChanges().getUpdatedAt().getPrevious()));
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestNoteData.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestNoteData.java
index c42a68b9..b8fb3a6d 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestNoteData.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestNoteData.java
@@ -1,21 +1,23 @@
package io.jenkins.plugins.gitlabbranchsource.Cause;
+import static org.apache.commons.lang.StringUtils.defaultString;
+
import java.util.HashMap;
import java.util.Map;
import org.gitlab4j.api.webhook.NoteEvent;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
-import static org.apache.commons.lang.StringUtils.defaultString;
-
@ExportedBean
public class GitLabMergeRequestNoteData {
private final Map variables = new HashMap<>();
public GitLabMergeRequestNoteData(NoteEvent noteEvent) {
- this.variables.put("GITLAB_OBJECT_KIND", defaultString(NoteEvent.OBJECT_KIND));
- this.variables.put("GITLAB_COMMENT_TRIGGER", defaultString(noteEvent.getObjectAttributes().getNote()));
+ this.variables.put("GITLAB_OBJECT_KIND", defaultString(NoteEvent.OBJECT_KIND));
+ this.variables.put(
+ "GITLAB_COMMENT_TRIGGER",
+ defaultString(noteEvent.getObjectAttributes().getNote()));
}
@Exported
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabPushCauseData.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabPushCauseData.java
index e65aadca..f3b4ec72 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabPushCauseData.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabPushCauseData.java
@@ -1,16 +1,16 @@
package io.jenkins.plugins.gitlabbranchsource.Cause;
+import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultIntString;
+import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultLongString;
+import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultVisibilityString;
+import static org.apache.commons.lang.StringUtils.defaultString;
+
import java.util.HashMap;
import java.util.Map;
import org.gitlab4j.api.webhook.PushEvent;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
-import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultIntString;
-import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultLongString;
-import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultVisibilityString;
-import static org.apache.commons.lang.StringUtils.defaultString;
-
@ExportedBean
public class GitLabPushCauseData {
@@ -26,29 +26,64 @@ public GitLabPushCauseData(PushEvent pushEvent) {
this.variables.put("GITLAB_USER_NAME", defaultString(pushEvent.getUserName()));
this.variables.put("GITLAB_USER_EMAIL", defaultString(pushEvent.getUserEmail()));
this.variables.put("GITLAB_PROJECT_ID", defaultLongString(pushEvent.getProjectId()));
- this.variables.put("GITLAB_PROJECT_ID_2", defaultLongString(pushEvent.getProject().getId()));
- this.variables.put("GITLAB_PROJECT_NAME", defaultString(pushEvent.getProject().getName()));
- this.variables.put("GITLAB_PROJECT_DESCRIPTION", defaultString(pushEvent.getProject().getDescription()));
- this.variables.put("GITLAB_PROJECT_WEB_URL", defaultString(pushEvent.getProject().getWebUrl()));
- this.variables.put("GITLAB_PROJECT_AVATAR_URL", defaultString(pushEvent.getProject().getAvatarUrl()));
- this.variables.put("GITLAB_PROJECT_GIT_SSH_URL", defaultString(pushEvent.getProject().getGitSshUrl()));
- this.variables.put("GITLAB_PROJECT_GIT_HTTP_URL", defaultString(pushEvent.getProject().getGitHttpUrl()));
- this.variables.put("GITLAB_PROJECT_NAMESPACE", defaultString(pushEvent.getProject().getNamespace()));
- this.variables.put("GITLAB_PROJECT_VISIBILITY_LEVEL", defaultVisibilityString(pushEvent.getProject().getVisibilityLevel()));
- this.variables.put("GITLAB_PROJECT_PATH_NAMESPACE", defaultString(pushEvent.getProject().getPathWithNamespace()));
- this.variables.put("GITLAB_PROJECT_CI_CONFIG_PATH", defaultString(pushEvent.getProject().getCiConfigPath()));
- this.variables.put("GITLAB_PROJECT_DEFAULT_BRANCH", defaultString(pushEvent.getProject().getDefaultBranch()));
- this.variables.put("GITLAB_PROJECT_HOMEPAGE", defaultString(pushEvent.getProject().getHomepage()));
- this.variables.put("GITLAB_PROJECT_URL", defaultString(pushEvent.getProject().getUrl()));
- this.variables.put("GITLAB_PROJECT_SSH_URL", defaultString(pushEvent.getProject().getSshUrl()));
- this.variables.put("GITLAB_PROJECT_HTTP_URL", defaultString(pushEvent.getProject().getHttpUrl()));
- this.variables.put("GITLAB_REPO_NAME", defaultString(pushEvent.getRepository().getName()));
- this.variables.put("GITLAB_REPO_URL", defaultString(pushEvent.getRepository().getUrl()));
- this.variables.put("GITLAB_REPO_DESCRIPTION", defaultString(pushEvent.getRepository().getDescription()));
- this.variables.put("GITLAB_REPO_HOMEPAGE", defaultString(pushEvent.getRepository().getHomepage()));
- this.variables.put("GITLAB_REPO_GIT_SSH_URL", defaultString(pushEvent.getRepository().getGit_ssh_url()));
- this.variables.put("GITLAB_REPO_GIT_HTTP_URL", defaultString(pushEvent.getRepository().getGit_http_url()));
- this.variables.put("GITLAB_REPO_VISIBILITY_LEVEL", defaultVisibilityString(pushEvent.getRepository().getVisibility_level()));
+ this.variables.put(
+ "GITLAB_PROJECT_ID_2", defaultLongString(pushEvent.getProject().getId()));
+ this.variables.put(
+ "GITLAB_PROJECT_NAME", defaultString(pushEvent.getProject().getName()));
+ this.variables.put(
+ "GITLAB_PROJECT_DESCRIPTION",
+ defaultString(pushEvent.getProject().getDescription()));
+ this.variables.put(
+ "GITLAB_PROJECT_WEB_URL", defaultString(pushEvent.getProject().getWebUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_AVATAR_URL",
+ defaultString(pushEvent.getProject().getAvatarUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_GIT_SSH_URL",
+ defaultString(pushEvent.getProject().getGitSshUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_GIT_HTTP_URL",
+ defaultString(pushEvent.getProject().getGitHttpUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_NAMESPACE", defaultString(pushEvent.getProject().getNamespace()));
+ this.variables.put(
+ "GITLAB_PROJECT_VISIBILITY_LEVEL",
+ defaultVisibilityString(pushEvent.getProject().getVisibilityLevel()));
+ this.variables.put(
+ "GITLAB_PROJECT_PATH_NAMESPACE",
+ defaultString(pushEvent.getProject().getPathWithNamespace()));
+ this.variables.put(
+ "GITLAB_PROJECT_CI_CONFIG_PATH",
+ defaultString(pushEvent.getProject().getCiConfigPath()));
+ this.variables.put(
+ "GITLAB_PROJECT_DEFAULT_BRANCH",
+ defaultString(pushEvent.getProject().getDefaultBranch()));
+ this.variables.put(
+ "GITLAB_PROJECT_HOMEPAGE", defaultString(pushEvent.getProject().getHomepage()));
+ this.variables.put(
+ "GITLAB_PROJECT_URL", defaultString(pushEvent.getProject().getUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_SSH_URL", defaultString(pushEvent.getProject().getSshUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_HTTP_URL", defaultString(pushEvent.getProject().getHttpUrl()));
+ this.variables.put(
+ "GITLAB_REPO_NAME", defaultString(pushEvent.getRepository().getName()));
+ this.variables.put(
+ "GITLAB_REPO_URL", defaultString(pushEvent.getRepository().getUrl()));
+ this.variables.put(
+ "GITLAB_REPO_DESCRIPTION",
+ defaultString(pushEvent.getRepository().getDescription()));
+ this.variables.put(
+ "GITLAB_REPO_HOMEPAGE", defaultString(pushEvent.getRepository().getHomepage()));
+ this.variables.put(
+ "GITLAB_REPO_GIT_SSH_URL",
+ defaultString(pushEvent.getRepository().getGit_ssh_url()));
+ this.variables.put(
+ "GITLAB_REPO_GIT_HTTP_URL",
+ defaultString(pushEvent.getRepository().getGit_http_url()));
+ this.variables.put(
+ "GITLAB_REPO_VISIBILITY_LEVEL",
+ defaultVisibilityString(pushEvent.getRepository().getVisibility_level()));
this.variables.put("GITLAB_COMMIT_COUNT", defaultIntString(pushEvent.getTotalCommitsCount()));
this.variables.put("GITLAB_REQUEST_URL", defaultString(pushEvent.getRequestUrl()));
this.variables.put("GITLAB_REQUEST_STRING", defaultString(pushEvent.getRequestQueryString()));
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabTagPushCauseData.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabTagPushCauseData.java
index a58e4e21..56b48def 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabTagPushCauseData.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabTagPushCauseData.java
@@ -1,16 +1,16 @@
package io.jenkins.plugins.gitlabbranchsource.Cause;
+import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultIntString;
+import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultLongString;
+import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultVisibilityString;
+import static org.apache.commons.lang.StringUtils.defaultString;
+
import java.util.HashMap;
import java.util.Map;
import org.gitlab4j.api.webhook.TagPushEvent;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
-import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultIntString;
-import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultLongString;
-import static io.jenkins.plugins.gitlabbranchsource.Cause.GitLabCauseUtils.defaultVisibilityString;
-import static org.apache.commons.lang.StringUtils.defaultString;
-
@ExportedBean
public class GitLabTagPushCauseData {
@@ -26,29 +26,71 @@ public GitLabTagPushCauseData(TagPushEvent tagPushEvent) {
this.variables.put("GITLAB_USER_NAME", defaultString(tagPushEvent.getUserName()));
this.variables.put("GITLAB_USER_EMAIL", defaultString(tagPushEvent.getUserEmail()));
this.variables.put("GITLAB_PROJECT_ID", defaultLongString(tagPushEvent.getProjectId()));
- this.variables.put("GITLAB_PROJECT_ID_2", defaultLongString(tagPushEvent.getProject().getId()));
- this.variables.put("GITLAB_PROJECT_NAME", defaultString(tagPushEvent.getProject().getName()));
- this.variables.put("GITLAB_PROJECT_DESCRIPTION", defaultString(tagPushEvent.getProject().getDescription()));
- this.variables.put("GITLAB_PROJECT_WEB_URL", defaultString(tagPushEvent.getProject().getWebUrl()));
- this.variables.put("GITLAB_PROJECT_AVATAR_URL", defaultString(tagPushEvent.getProject().getAvatarUrl()));
- this.variables.put("GITLAB_PROJECT_GIT_SSH_URL", defaultString(tagPushEvent.getProject().getGitSshUrl()));
- this.variables.put("GITLAB_PROJECT_GIT_HTTP_URL", defaultString(tagPushEvent.getProject().getGitHttpUrl()));
- this.variables.put("GITLAB_PROJECT_NAMESPACE", defaultString(tagPushEvent.getProject().getNamespace()));
- this.variables.put("GITLAB_PROJECT_VISIBILITY_LEVEL", defaultVisibilityString(tagPushEvent.getProject().getVisibilityLevel()));
- this.variables.put("GITLAB_PROJECT_PATH_NAMESPACE", defaultString(tagPushEvent.getProject().getPathWithNamespace()));
- this.variables.put("GITLAB_PROJECT_CI_CONFIG_PATH", defaultString(tagPushEvent.getProject().getCiConfigPath()));
- this.variables.put("GITLAB_PROJECT_DEFAULT_BRANCH", defaultString(tagPushEvent.getProject().getDefaultBranch()));
- this.variables.put("GITLAB_PROJECT_HOMEPAGE", defaultString(tagPushEvent.getProject().getHomepage()));
- this.variables.put("GITLAB_PROJECT_URL", defaultString(tagPushEvent.getProject().getUrl()));
- this.variables.put("GITLAB_PROJECT_SSH_URL", defaultString(tagPushEvent.getProject().getSshUrl()));
- this.variables.put("GITLAB_PROJECT_HTTP_URL", defaultString(tagPushEvent.getProject().getHttpUrl()));
- this.variables.put("GITLAB_REPO_NAME", defaultString(tagPushEvent.getRepository().getName()));
- this.variables.put("GITLAB_REPO_URL", defaultString(tagPushEvent.getRepository().getUrl()));
- this.variables.put("GITLAB_REPO_DESCRIPTION", defaultString(tagPushEvent.getRepository().getDescription()));
- this.variables.put("GITLAB_REPO_HOMEPAGE", defaultString(tagPushEvent.getRepository().getHomepage()));
- this.variables.put("GITLAB_REPO_GIT_SSH_URL", defaultString(tagPushEvent.getRepository().getGit_ssh_url()));
- this.variables.put("GITLAB_REPO_GIT_HTTP_URL", defaultString(tagPushEvent.getRepository().getGit_http_url()));
- this.variables.put("GITLAB_REPO_VISIBILITY_LEVEL", defaultVisibilityString(tagPushEvent.getRepository().getVisibility_level()));
+ this.variables.put(
+ "GITLAB_PROJECT_ID_2",
+ defaultLongString(tagPushEvent.getProject().getId()));
+ this.variables.put(
+ "GITLAB_PROJECT_NAME", defaultString(tagPushEvent.getProject().getName()));
+ this.variables.put(
+ "GITLAB_PROJECT_DESCRIPTION",
+ defaultString(tagPushEvent.getProject().getDescription()));
+ this.variables.put(
+ "GITLAB_PROJECT_WEB_URL",
+ defaultString(tagPushEvent.getProject().getWebUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_AVATAR_URL",
+ defaultString(tagPushEvent.getProject().getAvatarUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_GIT_SSH_URL",
+ defaultString(tagPushEvent.getProject().getGitSshUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_GIT_HTTP_URL",
+ defaultString(tagPushEvent.getProject().getGitHttpUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_NAMESPACE",
+ defaultString(tagPushEvent.getProject().getNamespace()));
+ this.variables.put(
+ "GITLAB_PROJECT_VISIBILITY_LEVEL",
+ defaultVisibilityString(tagPushEvent.getProject().getVisibilityLevel()));
+ this.variables.put(
+ "GITLAB_PROJECT_PATH_NAMESPACE",
+ defaultString(tagPushEvent.getProject().getPathWithNamespace()));
+ this.variables.put(
+ "GITLAB_PROJECT_CI_CONFIG_PATH",
+ defaultString(tagPushEvent.getProject().getCiConfigPath()));
+ this.variables.put(
+ "GITLAB_PROJECT_DEFAULT_BRANCH",
+ defaultString(tagPushEvent.getProject().getDefaultBranch()));
+ this.variables.put(
+ "GITLAB_PROJECT_HOMEPAGE",
+ defaultString(tagPushEvent.getProject().getHomepage()));
+ this.variables.put(
+ "GITLAB_PROJECT_URL", defaultString(tagPushEvent.getProject().getUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_SSH_URL",
+ defaultString(tagPushEvent.getProject().getSshUrl()));
+ this.variables.put(
+ "GITLAB_PROJECT_HTTP_URL",
+ defaultString(tagPushEvent.getProject().getHttpUrl()));
+ this.variables.put(
+ "GITLAB_REPO_NAME", defaultString(tagPushEvent.getRepository().getName()));
+ this.variables.put(
+ "GITLAB_REPO_URL", defaultString(tagPushEvent.getRepository().getUrl()));
+ this.variables.put(
+ "GITLAB_REPO_DESCRIPTION",
+ defaultString(tagPushEvent.getRepository().getDescription()));
+ this.variables.put(
+ "GITLAB_REPO_HOMEPAGE",
+ defaultString(tagPushEvent.getRepository().getHomepage()));
+ this.variables.put(
+ "GITLAB_REPO_GIT_SSH_URL",
+ defaultString(tagPushEvent.getRepository().getGit_ssh_url()));
+ this.variables.put(
+ "GITLAB_REPO_GIT_HTTP_URL",
+ defaultString(tagPushEvent.getRepository().getGit_http_url()));
+ this.variables.put(
+ "GITLAB_REPO_VISIBILITY_LEVEL",
+ defaultVisibilityString(tagPushEvent.getRepository().getVisibility_level()));
this.variables.put("GITLAB_COMMIT_COUNT", defaultIntString(tagPushEvent.getTotalCommitsCount()));
this.variables.put("GITLAB_REQUEST_URL", defaultString(tagPushEvent.getRequestUrl()));
this.variables.put("GITLAB_REQUEST_STRING", defaultString(tagPushEvent.getRequestQueryString()));
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Environment/GitLabWebHookEnvironmentContributor.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Environment/GitLabWebHookEnvironmentContributor.java
index c1c376bc..9d054fb1 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/Environment/GitLabWebHookEnvironmentContributor.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/Environment/GitLabWebHookEnvironmentContributor.java
@@ -21,17 +21,18 @@ public void buildEnvironmentFor(@NonNull Run r, @NonNull EnvVars envs, @NonNull
if (r instanceof WorkflowRun) {
gitLabWebHookCause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class);
- gitLabMergeRequestCommentCause = (GitLabMergeRequestCommentCause)
- r.getCause(GitLabMergeRequestCommentCause.class);
+ gitLabMergeRequestCommentCause =
+ (GitLabMergeRequestCommentCause) r.getCause(GitLabMergeRequestCommentCause.class);
}
envs.override("GITLAB_OBJECT_KIND", "none");
if (gitLabWebHookCause != null) {
- if(gitLabWebHookCause.getGitLabPushCauseData() != null) {
+ if (gitLabWebHookCause.getGitLabPushCauseData() != null) {
envs.overrideAll(gitLabWebHookCause.getGitLabPushCauseData().getBuildVariables());
- } else if(gitLabWebHookCause.getGitLabMergeRequestCauseData() != null) {
- envs.overrideAll(gitLabWebHookCause.getGitLabMergeRequestCauseData().getBuildVariables());
- } else if(gitLabWebHookCause.getGitLabTagPushCauseData() != null) {
+ } else if (gitLabWebHookCause.getGitLabMergeRequestCauseData() != null) {
+ envs.overrideAll(
+ gitLabWebHookCause.getGitLabMergeRequestCauseData().getBuildVariables());
+ } else if (gitLabWebHookCause.getGitLabTagPushCauseData() != null) {
envs.overrideAll(gitLabWebHookCause.getGitLabTagPushCauseData().getBuildVariables());
}
}
@@ -43,7 +44,8 @@ public void buildEnvironmentFor(@NonNull Run r, @NonNull EnvVars envs, @NonNull
if (gitLabMergeRequestCommentCause != null) {
if (gitLabMergeRequestCommentCause.getGitLabMergeRequestNoteData() != null) {
Map buildVariables = gitLabMergeRequestCommentCause
- .getGitLabMergeRequestNoteData().getBuildVariables();
+ .getGitLabMergeRequestNoteData()
+ .getBuildVariables();
envs.overrideAll(buildVariables);
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait.java
index 0849d4aa..12c8ea94 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait.java
@@ -42,7 +42,9 @@ public class ForkMergeRequestDiscoveryTrait extends SCMSourceTrait {
* The authority.
*/
@NonNull
- private final SCMHeadAuthority super GitLabSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust;
+ private final SCMHeadAuthority<
+ ? super GitLabSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision>
+ trust;
/**
* Build MR for Forks that are not Mirrors
*/
@@ -56,8 +58,14 @@ public class ForkMergeRequestDiscoveryTrait extends SCMSourceTrait {
* @param buildMRForksNotMirror the buildMRForksNotMirror flag
*/
@DataBoundConstructor
- public ForkMergeRequestDiscoveryTrait(int strategyId,
- @NonNull SCMHeadAuthority super GitLabSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust,
+ public ForkMergeRequestDiscoveryTrait(
+ int strategyId,
+ @NonNull
+ SCMHeadAuthority<
+ ? super GitLabSCMSourceRequest,
+ ? extends ChangeRequestSCMHead2,
+ ? extends SCMRevision>
+ trust,
boolean buildMRForksNotMirror) {
this.strategyId = strategyId;
this.trust = trust;
@@ -72,11 +80,20 @@ public ForkMergeRequestDiscoveryTrait(int strategyId,
* @param trust the authority.
* @param buildMRForksNotMirror the buildMRForksNotMirror flag
*/
- public ForkMergeRequestDiscoveryTrait(@NonNull Set strategies,
- @NonNull SCMHeadAuthority super GitLabSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust,
+ public ForkMergeRequestDiscoveryTrait(
+ @NonNull Set strategies,
+ @NonNull
+ SCMHeadAuthority<
+ ? super GitLabSCMSourceRequest,
+ ? extends ChangeRequestSCMHead2,
+ ? extends SCMRevision>
+ trust,
boolean buildMRForksNotMirror) {
- this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
- + (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0), trust, buildMRForksNotMirror);
+ this(
+ (strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
+ + (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0),
+ trust,
+ buildMRForksNotMirror);
}
/**
@@ -101,8 +118,7 @@ public Set getStrategies() {
case 2:
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD);
case 3:
- return EnumSet
- .of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
+ return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
default:
return EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
}
@@ -114,7 +130,8 @@ public Set getStrategies() {
* @return the authority.
*/
@NonNull
- public SCMHeadAuthority super GitLabSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> getTrust() {
+ public SCMHeadAuthority super GitLabSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision>
+ getTrust() {
return trust;
}
@@ -236,22 +253,19 @@ public List getTrustDescriptors() {
/**
* An {@link SCMHeadAuthority} that trusts nothing.
*/
- public static class TrustNobody extends
- SCMHeadAuthority {
+ public static class TrustNobody extends SCMHeadAuthority {
/**
* Constructor.
*/
@DataBoundConstructor
- public TrustNobody() {
- }
+ public TrustNobody() {}
/**
* {@inheritDoc}
*/
@Override
- public boolean checkTrusted(@NonNull SCMSourceRequest request,
- @NonNull ChangeRequestSCMHead2 head) {
+ public boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull ChangeRequestSCMHead2 head) {
return false;
}
@@ -266,8 +280,7 @@ public static class DescriptorImpl extends SCMHeadAuthorityDescriptor {
* {@inheritDoc}
*/
@Override
- public boolean isApplicableToOrigin(
- @NonNull Class extends SCMHeadOrigin> originClass) {
+ public boolean isApplicableToOrigin(@NonNull Class extends SCMHeadOrigin> originClass) {
return SCMHeadOrigin.Fork.class.isAssignableFrom(originClass);
}
@@ -279,7 +292,6 @@ public boolean isApplicableToOrigin(
public String getDisplayName() {
return Messages.ForkMergeRequestDiscoveryTrait_nobodyDisplayName();
}
-
}
}
@@ -287,22 +299,19 @@ public String getDisplayName() {
* An {@link SCMHeadAuthority} that trusts Members to the project.
*/
public static class TrustMembers
- extends
- SCMHeadAuthority {
+ extends SCMHeadAuthority {
/**
* Constructor.
*/
@DataBoundConstructor
- public TrustMembers() {
- }
+ public TrustMembers() {}
/**
* {@inheritDoc}
*/
@Override
- protected boolean checkTrusted(@NonNull GitLabSCMSourceRequest request,
- @NonNull MergeRequestSCMHead head) {
+ protected boolean checkTrusted(@NonNull GitLabSCMSourceRequest request, @NonNull MergeRequestSCMHead head) {
if (head.getOrigin().equals(SCMHeadOrigin.DEFAULT)) {
return false;
}
@@ -330,11 +339,9 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
- public boolean isApplicableToOrigin(
- @NonNull Class extends SCMHeadOrigin> originClass) {
+ public boolean isApplicableToOrigin(@NonNull Class extends SCMHeadOrigin> originClass) {
return SCMHeadOrigin.Fork.class.isAssignableFrom(originClass);
}
-
}
}
@@ -343,22 +350,19 @@ public boolean isApplicableToOrigin(
* project.
*/
public static class TrustPermission
- extends
- SCMHeadAuthority {
+ extends SCMHeadAuthority {
/**
* Constructor.
*/
@DataBoundConstructor
- public TrustPermission() {
- }
+ public TrustPermission() {}
/**
* {@inheritDoc}
*/
@Override
- protected boolean checkTrusted(@NonNull GitLabSCMSourceRequest request,
- @NonNull MergeRequestSCMHead head) {
+ protected boolean checkTrusted(@NonNull GitLabSCMSourceRequest request, @NonNull MergeRequestSCMHead head) {
if (!head.getOrigin().equals(SCMHeadOrigin.DEFAULT)) {
AccessLevel permission = request.getPermission(head.getOriginOwner());
if (permission != null) {
@@ -395,8 +399,7 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
- public boolean isApplicableToOrigin(
- @NonNull Class extends SCMHeadOrigin> originClass) {
+ public boolean isApplicableToOrigin(@NonNull Class extends SCMHeadOrigin> originClass) {
return SCMHeadOrigin.Fork.class.isAssignableFrom(originClass);
}
}
@@ -405,22 +408,19 @@ public boolean isApplicableToOrigin(
/**
* An {@link SCMHeadAuthority} that trusts everyone.
*/
- public static class TrustEveryone extends
- SCMHeadAuthority {
+ public static class TrustEveryone extends SCMHeadAuthority {
/**
* Constructor.
*/
@DataBoundConstructor
- public TrustEveryone() {
- }
+ public TrustEveryone() {}
/**
* {@inheritDoc}
*/
@Override
- protected boolean checkTrusted(@NonNull SCMSourceRequest request,
- @NonNull ChangeRequestSCMHead2 head) {
+ protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull ChangeRequestSCMHead2 head) {
return true;
}
@@ -444,11 +444,9 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
- public boolean isApplicableToOrigin(
- @NonNull Class extends SCMHeadOrigin> originClass) {
+ public boolean isApplicableToOrigin(@NonNull Class extends SCMHeadOrigin> originClass) {
return SCMHeadOrigin.Fork.class.isAssignableFrom(originClass);
}
}
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabAvatarTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabAvatarTrait.java
index 5f147467..a5904729 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabAvatarTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabAvatarTrait.java
@@ -21,7 +21,7 @@ public class GitLabAvatarTrait extends SCMSourceTrait {
*/
@DataBoundConstructor
public GitLabAvatarTrait() {
- //empty
+ // empty
}
@DataBoundSetter
@@ -62,7 +62,5 @@ public Class extends SCMSourceContext> getContextClass() {
public Class extends SCMSource> getSourceClass() {
return GitLabSCMSource.class;
}
-
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabHookCreator.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabHookCreator.java
index 80a28569..fce33827 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabHookCreator.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabHookCreator.java
@@ -1,5 +1,7 @@
package io.jenkins.plugins.gitlabbranchsource;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getProxyConfig;
+
import com.damnhandy.uri.template.UriTemplate;
import com.damnhandy.uri.template.UriTemplateBuilder;
import io.jenkins.plugins.gitlabserverconfig.credentials.PersonalAccessToken;
@@ -17,14 +19,12 @@
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.SystemHook;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getProxyConfig;
-
public class GitLabHookCreator {
public static final Logger LOGGER = Logger.getLogger(GitLabHookCreator.class.getName());
- public static void register(SCMNavigatorOwner owner, GitLabSCMNavigator navigator,
- GitLabHookRegistration systemhookMode) {
+ public static void register(
+ SCMNavigatorOwner owner, GitLabSCMNavigator navigator, GitLabHookRegistration systemhookMode) {
PersonalAccessToken credentials;
GitLabServer server = GitLabServers.get().findServer(navigator.getServerName());
if (server == null) {
@@ -57,8 +57,8 @@ public static void register(SCMNavigatorOwner owner, GitLabSCMNavigator navigato
}
}
- public static void register(GitLabSCMSource source,
- GitLabHookRegistration webhookMode, GitLabHookRegistration systemhookMode) {
+ public static void register(
+ GitLabSCMSource source, GitLabHookRegistration webhookMode, GitLabHookRegistration systemhookMode) {
PersonalAccessToken credentials = null;
GitLabServer server = GitLabServers.get().findServer(source.getServerName());
if (server == null) {
@@ -92,13 +92,18 @@ public static void register(GitLabSCMSource source,
}
if (credentials != null) {
try {
- GitLabApi gitLabApi = new GitLabApi(server.getServerUrl(),
- credentials.getToken().getPlainText(), null, getProxyConfig(server.getServerUrl()));
+ GitLabApi gitLabApi = new GitLabApi(
+ server.getServerUrl(),
+ credentials.getToken().getPlainText(),
+ null,
+ getProxyConfig(server.getServerUrl()));
createWebHookWhenMissing(gitLabApi, source.getProjectPath(), hookUrl, secretToken);
} catch (GitLabApiException e) {
- LOGGER.log(Level.WARNING,
- "Could not manage project hooks for " + source.getProjectPath() + " on "
- + server.getServerUrl(), e);
+ LOGGER.log(
+ Level.WARNING,
+ "Could not manage project hooks for " + source.getProjectPath() + " on "
+ + server.getServerUrl(),
+ e);
}
}
switch (systemhookMode) {
@@ -128,20 +133,24 @@ public static void register(GitLabSCMSource source,
}
}
- public static void createSystemHookWhenMissing(GitLabServer server,
- PersonalAccessToken credentials) {
+ public static void createSystemHookWhenMissing(GitLabServer server, PersonalAccessToken credentials) {
String systemHookUrl = getHookUrl(server, false);
try {
- GitLabApi gitLabApi = new GitLabApi(server.getServerUrl(),
- credentials.getToken().getPlainText(), null, getProxyConfig(server.getServerUrl()));
- SystemHook systemHook = gitLabApi.getSystemHooksApi()
- .getSystemHookStream()
- .filter(hook -> systemHookUrl.equals(hook.getUrl()))
- .findFirst()
- .orElse(null);
+ GitLabApi gitLabApi = new GitLabApi(
+ server.getServerUrl(),
+ credentials.getToken().getPlainText(),
+ null,
+ getProxyConfig(server.getServerUrl()));
+ SystemHook systemHook = gitLabApi
+ .getSystemHooksApi()
+ .getSystemHookStream()
+ .filter(hook -> systemHookUrl.equals(hook.getUrl()))
+ .findFirst()
+ .orElse(null);
if (systemHook == null) {
- gitLabApi.getSystemHooksApi().addSystemHook(systemHookUrl, server.getSecretTokenAsPlainText(),
- false, false, false);
+ gitLabApi
+ .getSystemHooksApi()
+ .addSystemHook(systemHookUrl, server.getSecretTokenAsPlainText(), false, false, false);
}
} catch (GitLabApiException e) {
LOGGER.log(Level.INFO, "User is not admin so cannot set system hooks", e);
@@ -184,20 +193,18 @@ static void checkURL(String url) {
try {
URL anURL = new URL(url);
if ("localhost".equals(anURL.getHost())) {
- throw new IllegalStateException(
- "Jenkins URL cannot start with http://localhost \nURL is: " + url);
+ throw new IllegalStateException("Jenkins URL cannot start with http://localhost \nURL is: " + url);
}
if (!anURL.getHost().contains(".")) {
throw new IllegalStateException(
- "You must use a fully qualified domain name for Jenkins URL, this is required by GitLab"
- + "\nURL is: " + url);
+ "You must use a fully qualified domain name for Jenkins URL, this is required by GitLab"
+ + "\nURL is: " + url);
}
} catch (MalformedURLException e) {
throw new IllegalStateException("Bad Jenkins URL\nURL is: " + url);
}
}
-
public static ProjectHook createWebHook() {
ProjectHook enabledHooks = new ProjectHook();
enabledHooks.setPushEvents(true);
@@ -207,19 +214,21 @@ public static ProjectHook createWebHook() {
return enabledHooks;
}
- public static String createWebHookWhenMissing(GitLabApi gitLabApi, String project,
- String hookUrl, String secretToken)
- throws GitLabApiException {
- ProjectHook projectHook = gitLabApi.getProjectApi().getHooksStream(project)
- .filter(hook -> hookUrl.equals(hook.getUrl()))
- .findFirst()
- .orElseGet(GitLabHookCreator::createWebHook);
+ public static String createWebHookWhenMissing(
+ GitLabApi gitLabApi, String project, String hookUrl, String secretToken) throws GitLabApiException {
+ ProjectHook projectHook = gitLabApi
+ .getProjectApi()
+ .getHooksStream(project)
+ .filter(hook -> hookUrl.equals(hook.getUrl()))
+ .findFirst()
+ .orElseGet(GitLabHookCreator::createWebHook);
if (projectHook.getId() == null) {
gitLabApi.getProjectApi().addHook(project, hookUrl, projectHook, false, secretToken);
return "created";
}
- // Primarily done due to legacy reason, secret token might not be configured in previous releases. So setting up hook url with the token.
- if(!isTokenEqual(projectHook.getToken(), secretToken)) {
+ // Primarily done due to legacy reason, secret token might not be configured in previous releases. So setting up
+ // hook url with the token.
+ if (!isTokenEqual(projectHook.getToken(), secretToken)) {
projectHook.setToken(secretToken);
gitLabApi.getProjectApi().modifyHook(projectHook);
return "modified";
@@ -228,10 +237,10 @@ public static String createWebHookWhenMissing(GitLabApi gitLabApi, String projec
}
public static boolean isTokenEqual(String str1, String str2) {
- if(str1 == null && str2.isEmpty()) {
+ if (str1 == null && str2.isEmpty()) {
return true;
}
- if(str1 == null) {
+ if (str1 == null) {
return false;
}
return str1.equals(str2);
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java
index 0addc2c0..eedd8783 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java
@@ -27,12 +27,10 @@ public GitLabMergeRequestCommentTrigger(NoteEvent payload) {
@Override
public void isMatch() {
- if (getPayload().getObjectAttributes().getNoteableType()
- .equals(NoteEvent.NoteableType.MERGE_REQUEST)) {
+ if (getPayload().getObjectAttributes().getNoteableType().equals(NoteEvent.NoteableType.MERGE_REQUEST)) {
Long mergeRequestId = getPayload().getMergeRequest().getIid();
- final Pattern mergeRequestJobNamePattern = Pattern
- .compile("^MR-" + mergeRequestId + "\\b.*$",
- Pattern.CASE_INSENSITIVE);
+ final Pattern mergeRequestJobNamePattern =
+ Pattern.compile("^MR-" + mergeRequestId + "\\b.*$", Pattern.CASE_INSENSITIVE);
final String commentBody = getPayload().getObjectAttributes().getNote();
final String commentUrl = getPayload().getObjectAttributes().getUrl();
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
@@ -49,36 +47,46 @@ public void isMatch() {
}
GitLabSCMSource gitLabSCMSource = (GitLabSCMSource) source;
final GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(
- null, SCMHeadObserver.none())
+ null, SCMHeadObserver.none())
.withTraits(gitLabSCMSource.getTraits());
if (!sourceContext.mrCommentTriggerEnabled()) {
continue;
}
- if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest().getTargetProjectId()
+ if (gitLabSCMSource.getProjectId()
+ == getPayload().getMergeRequest().getTargetProjectId()
&& isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) {
for (Job, ?> job : owner.getAllJobs()) {
- if (MultiBranchProject.class.isAssignableFrom(job.getParent().getClass()) ) {
+ if (MultiBranchProject.class.isAssignableFrom(
+ job.getParent().getClass())) {
MultiBranchProject parentJob = (MultiBranchProject) job.getParent();
if (parentJob.getSCMSource(gitLabSCMSource.getId()) == gitLabSCMSource
- && mergeRequestJobNamePattern.matcher(job.getName()).matches()) {
+ && mergeRequestJobNamePattern
+ .matcher(job.getName())
+ .matches()) {
String expectedCommentBody = sourceContext.getCommentBody();
- Pattern pattern = Pattern.compile(expectedCommentBody,
- Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
- if (commentBody == null || pattern.matcher(commentBody)
- .matches()) {
- ParameterizedJobMixIn.scheduleBuild2(job, 0,
- new CauseAction(
- new GitLabMergeRequestCommentCause(commentUrl, getPayload())));
- LOGGER.log(Level.INFO,
+ Pattern pattern = Pattern.compile(
+ expectedCommentBody, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
+ if (commentBody == null
+ || pattern.matcher(commentBody).matches()) {
+ ParameterizedJobMixIn.scheduleBuild2(
+ job,
+ 0,
+ new CauseAction(new GitLabMergeRequestCommentCause(
+ commentUrl, getPayload())));
+ LOGGER.log(
+ Level.INFO,
"Triggered build for {0} due to MR comment on {1}",
new Object[] {
- job.getFullName(),
- getPayload().getProject().getPathWithNamespace()
+ job.getFullName(),
+ getPayload()
+ .getProject()
+ .getPathWithNamespace()
});
} else {
- LOGGER.log(Level.INFO,
+ LOGGER.log(
+ Level.INFO,
"MR comment does not match the trigger build string ({0}) for {1}",
- new Object[] { expectedCommentBody, job.getFullName() });
+ new Object[] {expectedCommentBody, job.getFullName()});
}
break;
}
@@ -89,10 +97,9 @@ && isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigge
}
}
if (!jobFound) {
- LOGGER.log(Level.INFO, "MR comment on {0} did not match any job",
- new Object[] {
- getPayload().getProject().getPathWithNamespace()
- });
+ LOGGER.log(Level.INFO, "MR comment on {0} did not match any job", new Object[] {
+ getPayload().getProject().getPathWithNamespace()
+ });
}
}
}
@@ -103,8 +110,8 @@ private boolean isTrustedMember(GitLabSCMSource gitLabSCMSource, boolean check)
if (!check) {
return true;
}
- AccessLevel permission = gitLabSCMSource.getMembers()
- .get(getPayload().getUser().getUsername());
+ AccessLevel permission =
+ gitLabSCMSource.getMembers().get(getPayload().getUser().getUsername());
if (permission != null) {
switch (permission) {
case MAINTAINER:
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestSCMEvent.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestSCMEvent.java
index c62f558a..15e2cd72 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestSCMEvent.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestSCMEvent.java
@@ -18,165 +18,166 @@
import org.gitlab4j.api.webhook.MergeRequestEvent;
public class GitLabMergeRequestSCMEvent extends AbstractGitLabSCMHeadEvent {
- public static final Logger LOGGER = Logger.getLogger(GitLabMergeRequestSCMEvent.class.getName());
+ public static final Logger LOGGER = Logger.getLogger(GitLabMergeRequestSCMEvent.class.getName());
- public GitLabMergeRequestSCMEvent(MergeRequestEvent mrEvent, String origin) {
- super(typeOf(mrEvent), mrEvent, origin);
- }
-
- // TODO: Take care of "locked" state
- private static Type typeOf(MergeRequestEvent mrEvent) {
- if (mrEvent.getObjectAttributes().getState().equals("closed")) {
- return Type.REMOVED;
- } else if (mrEvent.getObjectAttributes().getState().equals("opened")
- && mrEvent.getObjectAttributes().getCreatedAt()
- .equals(mrEvent.getObjectAttributes().getUpdatedAt())) {
- return Type.CREATED;
- }
- return Type.UPDATED;
- }
+ public GitLabMergeRequestSCMEvent(MergeRequestEvent mrEvent, String origin) {
+ super(typeOf(mrEvent), mrEvent, origin);
+ }
- @Override
- public String descriptionFor(@NonNull SCMNavigator navigator) {
- String state = getPayload().getObjectAttributes().getState();
- LOGGER.log(Level.FINE, "descriptionFor() event:{0} state:{1} action:{2} project:{3}",
- new Object[] {
- getPayload().getObjectAttributes().getIid(),
- String.valueOf(state),
- getPayload().getObjectAttributes().getAction(),
- getPayload().getProject().getName()
- });
- if (state != null) {
- switch (state) {
- case "opened":
- case "reopened":
- case "closed":
- return "Merge request !" + getPayload().getObjectAttributes().getIid()
- + " state:" + state
- + " action:" + getPayload().getObjectAttributes().getAction()
- + " in project " + getPayload().getProject().getName()
- + " changes:" + getPayload().getChanges().toString();
- }
- }
- return "Merge request !" + getPayload().getObjectAttributes().getIid()
- + " event in project " + getPayload().getProject().getName();
+ // TODO: Take care of "locked" state
+ private static Type typeOf(MergeRequestEvent mrEvent) {
+ if (mrEvent.getObjectAttributes().getState().equals("closed")) {
+ return Type.REMOVED;
+ } else if (mrEvent.getObjectAttributes().getState().equals("opened")
+ && mrEvent.getObjectAttributes()
+ .getCreatedAt()
+ .equals(mrEvent.getObjectAttributes().getUpdatedAt())) {
+ return Type.CREATED;
}
+ return Type.UPDATED;
+ }
- @Override
- public boolean isMatch(@NonNull GitLabSCMNavigator navigator) {
- return navigator.getNavigatorProjects()
- .contains(getPayload().getProject().getPathWithNamespace());
+ @Override
+ public String descriptionFor(@NonNull SCMNavigator navigator) {
+ String state = getPayload().getObjectAttributes().getState();
+ LOGGER.log(Level.FINE, "descriptionFor() event:{0} state:{1} action:{2} project:{3}", new Object[] {
+ getPayload().getObjectAttributes().getIid(),
+ String.valueOf(state),
+ getPayload().getObjectAttributes().getAction(),
+ getPayload().getProject().getName()
+ });
+ if (state != null) {
+ switch (state) {
+ case "opened":
+ case "reopened":
+ case "closed":
+ return "Merge request !"
+ + getPayload().getObjectAttributes().getIid()
+ + " state:" + state
+ + " action:" + getPayload().getObjectAttributes().getAction()
+ + " in project " + getPayload().getProject().getName()
+ + " changes:" + getPayload().getChanges().toString();
+ }
}
+ return "Merge request !" + getPayload().getObjectAttributes().getIid() + " event in project "
+ + getPayload().getProject().getName();
+ }
- @Override
- public boolean isMatch(@NonNull GitLabSCMSource source) {
- return getPayload().getObjectAttributes().getTargetProjectId()
- .equals(source.getProjectId());
- }
+ @Override
+ public boolean isMatch(@NonNull GitLabSCMNavigator navigator) {
+ return navigator
+ .getNavigatorProjects()
+ .contains(getPayload().getProject().getPathWithNamespace());
+ }
- @NonNull
- @Override
- public String getSourceName() {
- return getPayload().getProject().getPathWithNamespace();
- }
+ @Override
+ public boolean isMatch(@NonNull GitLabSCMSource source) {
+ return getPayload().getObjectAttributes().getTargetProjectId().equals(source.getProjectId());
+ }
- @Override
- public String descriptionFor(@NonNull SCMSource source) {
- String state = getPayload().getObjectAttributes().getState();
- LOGGER.log(Level.FINE, "descriptionFor() event:{0} state:{1} action:{2}",
- new Object[] {
- getPayload().getObjectAttributes().getIid(),
- String.valueOf(state),
- getPayload().getObjectAttributes().getAction()
- });
- if (state != null) {
- switch (state) {
- case "opened":
- case "reopened":
- case "closed":
- return "Merge request !" + getPayload().getObjectAttributes().getIid()
- + " state:" + state
- + " action:" + getPayload().getObjectAttributes().getAction()
- + " changes:" + getPayload().getChanges().toString();
- }
- }
- return "Merge request !" + getPayload().getObjectAttributes().getIid() + " event";
- }
+ @NonNull
+ @Override
+ public String getSourceName() {
+ return getPayload().getProject().getPathWithNamespace();
+ }
- @Override
- public String description() {
- String state = getPayload().getObjectAttributes().getState();
- LOGGER.log(Level.FINE, "description() event:{0} state:{1} action:{2} project:{3}",
- new Object[] {
- getPayload().getObjectAttributes().getIid(),
- String.valueOf(state),
- getPayload().getObjectAttributes().getAction(),
- getPayload().getProject().getPathWithNamespace()
- });
- if (state != null) {
- switch (state) {
- case "opened":
- case "reopened":
- case "closed":
- return "Merge request !" + getPayload().getObjectAttributes().getIid()
- + " state:" + state
- + " action:" + getPayload().getObjectAttributes().getAction()
- + " in project "
- + getPayload().getProject().getPathWithNamespace()
- + " changes:" + getPayload().getChanges().toString();
- }
- }
- return "Merge request !" + getPayload().getObjectAttributes().getIid() + " event";
+ @Override
+ public String descriptionFor(@NonNull SCMSource source) {
+ String state = getPayload().getObjectAttributes().getState();
+ LOGGER.log(Level.FINE, "descriptionFor() event:{0} state:{1} action:{2}", new Object[] {
+ getPayload().getObjectAttributes().getIid(),
+ String.valueOf(state),
+ getPayload().getObjectAttributes().getAction()
+ });
+ if (state != null) {
+ switch (state) {
+ case "opened":
+ case "reopened":
+ case "closed":
+ return "Merge request !"
+ + getPayload().getObjectAttributes().getIid()
+ + " state:" + state
+ + " action:" + getPayload().getObjectAttributes().getAction()
+ + " changes:" + getPayload().getChanges().toString();
+ }
}
+ return "Merge request !" + getPayload().getObjectAttributes().getIid() + " event";
+ }
- @NonNull
- @Override
- public Map headsFor(GitLabSCMSource source) {
- Map result = new HashMap<>();
- try (GitLabSCMSourceRequest request = new GitLabSCMSourceContext(null,
- SCMHeadObserver.none())
- .withTraits(source.getTraits())
- .newRequest(source, null)) {
- MergeRequestEvent.ObjectAttributes m = getPayload().getObjectAttributes();
- Map> strategies = request.getMRStrategies();
- boolean fork = !getPayload().getObjectAttributes().getSourceProjectId()
- .equals(getPayload().getObjectAttributes().getTargetProjectId());
- String originOwner = getPayload().getUser().getUsername();
- String originProjectPath = m.getSource().getPathWithNamespace();
- for (ChangeRequestCheckoutStrategy strategy : strategies.get(fork)) {
- MergeRequestSCMHead h = new MergeRequestSCMHead(
- "MR-" + m.getIid() + (strategies.get(fork).size() > 1
- ? "-" + strategy.name().toLowerCase(Locale.ENGLISH)
- : ""),
- m.getIid(),
- new BranchSCMHead(m.getTargetBranch()),
- strategy,
- fork ? new SCMHeadOrigin.Fork(originProjectPath)
- : SCMHeadOrigin.DEFAULT,
- originOwner,
- originProjectPath,
- m.getSourceBranch(),
- m.getTitle());
- result.put(h, m.getState().equals("closed")
- ? null
- : new MergeRequestSCMRevision(
- h,
- new BranchSCMRevision(
- h.getTarget(),
- "HEAD"),
- new BranchSCMRevision(
- new BranchSCMHead(h.getOriginName()),
- m.getLastCommit().getId())));
- }
- } catch (IOException e) {
- LOGGER.log(Level.SEVERE, "Exception caught: " + e, e);
- }
- return result;
+ @Override
+ public String description() {
+ String state = getPayload().getObjectAttributes().getState();
+ LOGGER.log(Level.FINE, "description() event:{0} state:{1} action:{2} project:{3}", new Object[] {
+ getPayload().getObjectAttributes().getIid(),
+ String.valueOf(state),
+ getPayload().getObjectAttributes().getAction(),
+ getPayload().getProject().getPathWithNamespace()
+ });
+ if (state != null) {
+ switch (state) {
+ case "opened":
+ case "reopened":
+ case "closed":
+ return "Merge request !"
+ + getPayload().getObjectAttributes().getIid()
+ + " state:" + state
+ + " action:" + getPayload().getObjectAttributes().getAction()
+ + " in project "
+ + getPayload().getProject().getPathWithNamespace()
+ + " changes:" + getPayload().getChanges().toString();
+ }
}
+ return "Merge request !" + getPayload().getObjectAttributes().getIid() + " event";
+ }
- @Override
- public GitLabWebHookCause getCause() {
- return new GitLabWebHookCause().fromMergeRequest(getPayload());
+ @NonNull
+ @Override
+ public Map headsFor(GitLabSCMSource source) {
+ Map result = new HashMap<>();
+ try (GitLabSCMSourceRequest request = new GitLabSCMSourceContext(null, SCMHeadObserver.none())
+ .withTraits(source.getTraits())
+ .newRequest(source, null)) {
+ MergeRequestEvent.ObjectAttributes m = getPayload().getObjectAttributes();
+ Map> strategies = request.getMRStrategies();
+ boolean fork = !getPayload()
+ .getObjectAttributes()
+ .getSourceProjectId()
+ .equals(getPayload().getObjectAttributes().getTargetProjectId());
+ String originOwner = getPayload().getUser().getUsername();
+ String originProjectPath = m.getSource().getPathWithNamespace();
+ for (ChangeRequestCheckoutStrategy strategy : strategies.get(fork)) {
+ MergeRequestSCMHead h = new MergeRequestSCMHead(
+ "MR-" + m.getIid()
+ + (strategies.get(fork).size() > 1
+ ? "-" + strategy.name().toLowerCase(Locale.ENGLISH)
+ : ""),
+ m.getIid(),
+ new BranchSCMHead(m.getTargetBranch()),
+ strategy,
+ fork ? new SCMHeadOrigin.Fork(originProjectPath) : SCMHeadOrigin.DEFAULT,
+ originOwner,
+ originProjectPath,
+ m.getSourceBranch(),
+ m.getTitle());
+ result.put(
+ h,
+ m.getState().equals("closed")
+ ? null
+ : new MergeRequestSCMRevision(
+ h,
+ new BranchSCMRevision(h.getTarget(), "HEAD"),
+ new BranchSCMRevision(
+ new BranchSCMHead(h.getOriginName()),
+ m.getLastCommit().getId())));
+ }
+ } catch (IOException e) {
+ LOGGER.log(Level.SEVERE, "Exception caught: " + e, e);
}
+ return result;
+ }
+ @Override
+ public GitLabWebHookCause getCause() {
+ return new GitLabWebHookCause().fromMergeRequest(getPayload());
+ }
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestTrigger.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestTrigger.java
index 99efee30..ede1200c 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestTrigger.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestTrigger.java
@@ -17,19 +17,15 @@ public GitLabMergeRequestTrigger(MergeRequestEvent mrEvent, String origin) {
@Override
public boolean isMatch(@NonNull GitLabSCMSource source) {
- final GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(
- null, SCMHeadObserver.none())
- .withTraits(source.getTraits());
+ final GitLabSCMSourceContext sourceContext =
+ new GitLabSCMSourceContext(null, SCMHeadObserver.none()).withTraits(source.getTraits());
boolean shouldBuild = this.shouldBuild(getPayload(), sourceContext);
- LOGGER.log(Level.FINE, "isMatch() result for MR-{0}: {1}",
- new Object[] {
- getPayload().getObjectAttributes().getIid(),
- String.valueOf(shouldBuild)
- });
-
- return getPayload().getObjectAttributes().getTargetProjectId()
- .equals(source.getProjectId()) && shouldBuild;
+ LOGGER.log(Level.FINE, "isMatch() result for MR-{0}: {1}", new Object[] {
+ getPayload().getObjectAttributes().getIid(), String.valueOf(shouldBuild)
+ });
+
+ return getPayload().getObjectAttributes().getTargetProjectId().equals(source.getProjectId()) && shouldBuild;
}
private boolean shouldBuild(MergeRequestEvent mrEvent, GitLabSCMSourceContext context) {
@@ -38,7 +34,9 @@ private boolean shouldBuild(MergeRequestEvent mrEvent, GitLabSCMSourceContext co
boolean shouldBuild = true;
if (attributes.getWorkInProgress() && context.alwaysIgnoreMRWorkInProgress()) {
- LOGGER.log(Level.FINE, "shouldBuild for MR-{0} set to false due to WorkInProgress=true.",
+ LOGGER.log(
+ Level.FINE,
+ "shouldBuild for MR-{0} set to false due to WorkInProgress=true.",
getPayload().getObjectAttributes().getIid());
return false;
}
@@ -71,16 +69,16 @@ private boolean shouldBuild(MergeRequestEvent mrEvent, GitLabSCMSourceContext co
}
if (!shouldBuild) {
- LOGGER.log(Level.FINE, "shouldBuild for MR-{0} set to false due to non-code related updates.",
+ LOGGER.log(
+ Level.FINE,
+ "shouldBuild for MR-{0} set to false due to non-code related updates.",
getPayload().getObjectAttributes().getIid());
}
- LOGGER.log(Level.FINEST,
+ LOGGER.log(
+ Level.FINEST,
"shouldBuild for MR-{0} will be set for action {1} based on pipeline configuration.",
- new Object[] {
- getPayload().getObjectAttributes().getIid(),
- action
- });
+ new Object[] {getPayload().getObjectAttributes().getIid(), action});
if (action.equals("open")) {
return context.alwaysBuildMROpen();
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabProjectSCMEvent.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabProjectSCMEvent.java
index 3d298d32..1238871a 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabProjectSCMEvent.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabProjectSCMEvent.java
@@ -21,8 +21,7 @@ private static Type typeOf(ProjectSystemHookEvent projectSystemHookEvent) {
case ProjectSystemHookEvent.PROJECT_UPDATE_EVENT:
return Type.UPDATED;
default:
- throw new IllegalArgumentException(
- "cannot handle system-hook " + projectSystemHookEvent);
+ throw new IllegalArgumentException("cannot handle system-hook " + projectSystemHookEvent);
}
}
@@ -39,8 +38,8 @@ public String descriptionFor(@NonNull SCMNavigator navigator) {
*/
@Override
public String description() {
- return "Project event to branch " + getPayload().getPath() + " in namespace " +
- getPayload().getPathWithNamespace();
+ return "Project event to branch " + getPayload().getPath() + " in namespace "
+ + getPayload().getPathWithNamespace();
}
/**
@@ -66,12 +65,12 @@ private boolean isMatch(@NonNull GitLabSCMNavigator navigator) {
switch (getType()) {
case CREATED:
String projectPathWithNamespace = getPayload().getPathWithNamespace();
- String projectOwner = GitLabSCMNavigator
- .getProjectOwnerFromNamespace(projectPathWithNamespace);
+ String projectOwner = GitLabSCMNavigator.getProjectOwnerFromNamespace(projectPathWithNamespace);
if (navigator.isGroup()) {
// checks when project owner is a Group
if (navigator.isWantSubGroupProjects()) {
- // can be a subgroup so needs to at least start with the project owner when subgroup projects are required
+ // can be a subgroup so needs to at least start with the project owner when subgroup projects
+ // are required
return projectOwner.startsWith(navigator.getProjectOwner());
} else {
// when subgroup projects are not required, project owner should match project owner
@@ -83,11 +82,9 @@ private boolean isMatch(@NonNull GitLabSCMNavigator navigator) {
return projectOwner.equals(navigator.getProjectOwner());
}
case UPDATED:
- return navigator.getNavigatorProjects()
- .contains(getPayload().getPathWithNamespace());
+ return navigator.getNavigatorProjects().contains(getPayload().getPathWithNamespace());
case REMOVED:
- return navigator.getNavigatorProjects()
- .contains(getPayload().getPathWithNamespace());
+ return navigator.getNavigatorProjects().contains(getPayload().getPathWithNamespace());
default:
return false;
}
@@ -95,8 +92,7 @@ private boolean isMatch(@NonNull GitLabSCMNavigator navigator) {
@Override
public boolean isMatch(@NonNull SCMSource source) {
- return source instanceof GitLabSCMSource && getPayload().getProjectId()
- .equals(((GitLabSCMSource) source).getProjectId());
+ return source instanceof GitLabSCMSource
+ && getPayload().getProjectId().equals(((GitLabSCMSource) source).getProjectId());
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabPushSCMEvent.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabPushSCMEvent.java
index 8e994546..afa47482 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabPushSCMEvent.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabPushSCMEvent.java
@@ -51,14 +51,15 @@ public String descriptionFor(SCMSource source) {
public String description() {
String ref = getPayload().getRef();
ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref;
- return "Push event to branch " + ref + " in project " +
- getPayload().getProject().getPathWithNamespace();
+ return "Push event to branch " + ref + " in project "
+ + getPayload().getProject().getPathWithNamespace();
}
@Override
public boolean isMatch(@NonNull GitLabSCMNavigator navigator) {
- return navigator.getNavigatorProjects()
- .contains(getPayload().getProject().getPathWithNamespace());
+ return navigator
+ .getNavigatorProjects()
+ .contains(getPayload().getProject().getPathWithNamespace());
}
@Override
@@ -72,14 +73,15 @@ public Map headsFor(GitLabSCMSource source) {
String ref = getPayload().getRef();
ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref;
BranchSCMHead h = new BranchSCMHead(ref);
- return Collections.singletonMap(h,
- StringUtils.isNotBlank(getPayload().getAfter())
- ? new BranchSCMRevision(h, getPayload().getAfter()) : null);
+ return Collections.singletonMap(
+ h,
+ StringUtils.isNotBlank(getPayload().getAfter())
+ ? new BranchSCMRevision(h, getPayload().getAfter())
+ : null);
}
@Override
public GitLabWebHookCause getCause() {
return new GitLabWebHookCause().fromPush(getPayload());
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMBuilder.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMBuilder.java
index 4bdf28c9..dcf17d31 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMBuilder.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMBuilder.java
@@ -1,5 +1,10 @@
package io.jenkins.plugins.gitlabbranchsource;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrlFromName;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.projectUriTemplate;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.splitPath;
+import static org.apache.commons.lang.StringUtils.defaultIfBlank;
+
import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey;
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
@@ -27,11 +32,6 @@
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.RefSpec;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrlFromName;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.projectUriTemplate;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.splitPath;
-import static org.apache.commons.lang.StringUtils.defaultIfBlank;
-
/**
* Builds a {@link GitSCM} for {@link GitLabSCMSource}.
*/
@@ -68,17 +68,11 @@ public class GitLabSCMBuilder extends GitSCMBuilder {
* @param head the {@link SCMHead}
* @param revision the (optional) {@link SCMRevision}
*/
- public GitLabSCMBuilder(@NonNull GitLabSCMSource source, @NonNull SCMHead head,
- @CheckForNull SCMRevision revision) {
- super(
- head,
- revision,
- source.getHttpRemote(),
- source.getCredentialsId()
- );
+ public GitLabSCMBuilder(
+ @NonNull GitLabSCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision revision) {
+ super(head, revision, source.getHttpRemote(), source.getCredentialsId());
this.context = source.getOwner();
- serverUrl = defaultIfBlank(getServerUrlFromName(source.getServerName()),
- GitLabServer.GITLAB_SERVER_URL);
+ serverUrl = defaultIfBlank(getServerUrlFromName(source.getServerName()), GitLabServer.GITLAB_SERVER_URL);
projectPath = source.getProjectPath();
sshRemote = source.getSshRemote();
httpRemote = source.getHttpRemote();
@@ -87,16 +81,14 @@ public GitLabSCMBuilder(@NonNull GitLabSCMSource source, @NonNull SCMHead head,
String projectUrl;
if (head instanceof MergeRequestSCMHead) {
MergeRequestSCMHead h = (MergeRequestSCMHead) head;
- withRefSpec("+refs/merge-requests/" + h.getId() + "/head:refs/remotes/@{remote}/" + head
- .getName());
+ withRefSpec("+refs/merge-requests/" + h.getId() + "/head:refs/remotes/@{remote}/" + head.getName());
projectUrl = projectUrl(h.getOriginProjectPath());
} else if (head instanceof GitLabTagSCMHead) {
withRefSpec("+refs/tags/" + head.getName() + ":refs/tags/" + head.getName());
projectUrl = projectUrl(projectPath);
} else {
- withRefSpec(
- "+refs/heads/" + head.getName() + ":refs/remotes/@{remote}/" + head.getName());
+ withRefSpec("+refs/heads/" + head.getName() + ":refs/remotes/@{remote}/" + head.getName());
projectUrl = projectUrl(projectPath);
}
withBrowser(new GitLabBrowser(projectUrl));
@@ -113,12 +105,13 @@ public GitLabSCMBuilder(@NonNull GitLabSCMSource source, @NonNull SCMHead head,
* @param projectPath the full path to the project (with namespace).
* @return a {@link UriTemplate}
*/
- public static UriTemplate checkoutUriTemplate(@CheckForNull Item context,
- @NonNull String serverUrl,
- @CheckForNull String httpRemote,
- @CheckForNull String sshRemote,
- @CheckForNull String credentialsId,
- @NonNull String projectPath) {
+ public static UriTemplate checkoutUriTemplate(
+ @CheckForNull Item context,
+ @NonNull String serverUrl,
+ @CheckForNull String httpRemote,
+ @CheckForNull String sshRemote,
+ @CheckForNull String credentialsId,
+ @NonNull String projectPath) {
if (credentialsId != null && sshRemote != null) {
URIRequirementBuilder builder = URIRequirementBuilder.create();
@@ -127,37 +120,32 @@ public static UriTemplate checkoutUriTemplate(@CheckForNull Item context,
builder.withHostname(serverUri.getHost());
}
StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull(
- CredentialsProvider.lookupCredentials(
- StandardUsernameCredentials.class,
- context,
- context instanceof Queue.Task
- ? ((Queue.Task) context).getDefaultAuthentication()
- : ACL.SYSTEM,
- builder.build()
- ),
- CredentialsMatchers.allOf(
- CredentialsMatchers.withId(credentialsId),
- CredentialsMatchers.instanceOf(StandardUsernameCredentials.class)
- )
- );
+ CredentialsProvider.lookupCredentials(
+ StandardUsernameCredentials.class,
+ context,
+ context instanceof Queue.Task
+ ? ((Queue.Task) context).getDefaultAuthentication()
+ : ACL.SYSTEM,
+ builder.build()),
+ CredentialsMatchers.allOf(
+ CredentialsMatchers.withId(credentialsId),
+ CredentialsMatchers.instanceOf(StandardUsernameCredentials.class)));
if (credentials instanceof SSHUserPrivateKey) {
- return UriTemplate.buildFromTemplate(sshRemote)
- .build();
+ return UriTemplate.buildFromTemplate(sshRemote).build();
}
}
if (httpRemote != null) {
- return UriTemplate.buildFromTemplate(httpRemote)
- .build();
+ return UriTemplate.buildFromTemplate(httpRemote).build();
}
return UriTemplate.buildFromTemplate(serverUrl + '/' + projectPath)
- .literal(".git")
- .build();
+ .literal(".git")
+ .build();
}
private String projectUrl(String projectPath) {
return projectUriTemplate(serverUrl)
- .set("project", splitPath(projectPath))
- .expand();
+ .set("project", splitPath(projectPath))
+ .expand();
}
/**
@@ -168,8 +156,7 @@ private String projectUrl(String projectPath) {
*/
@NonNull
public final UriTemplate checkoutUriTemplate() {
- return checkoutUriTemplate(context, serverUrl, httpRemote, sshRemote, credentialsId(),
- projectPath);
+ return checkoutUriTemplate(context, serverUrl, httpRemote, sshRemote, credentialsId(), projectPath);
}
/**
@@ -218,8 +205,7 @@ public GitSCM build() {
String targetDst = Constants.R_REMOTES + remoteName() + "/" + name;
for (RefSpec b : asRefSpecs()) {
String dst = b.getDestination();
- assert dst.startsWith(Constants.R_REFS)
- : "All git references must start with refs/";
+ assert dst.startsWith(Constants.R_REFS) : "All git references must start with refs/";
if (targetSrc.equals(b.getSource())) {
if (targetDst.equals(dst)) {
match = true;
@@ -240,17 +226,14 @@ public GitSCM build() {
if (localNames.contains(localName)) {
// conflict with intended alternative name
localName =
- "remotes/" + remoteName() + "/merge-requests-" + head.getId()
- + "-upstream-" + name;
+ "remotes/" + remoteName() + "/merge-requests-" + head.getId() + "-upstream-" + name;
}
if (localNames.contains(localName)) {
// ok we're just going to mangle our way to something that works
while (localNames.contains(localName)) {
- localName =
- "remotes/" + remoteName() + "/merge-requests-" + head.getId()
+ localName = "remotes/" + remoteName() + "/merge-requests-" + head.getId()
+ "-upstream-" + name
- + "-" + Integer
- .toHexString(RANDOM.nextInt(Integer.MAX_VALUE));
+ + "-" + Integer.toHexString(RANDOM.nextInt(Integer.MAX_VALUE));
}
}
withRefSpec("+refs/heads/" + name + ":refs/" + localName);
@@ -258,11 +241,8 @@ public GitSCM build() {
withExtension(new MergeWithGitSCMExtension(
localName,
r instanceof MergeRequestSCMRevision
- ? ((BranchSCMRevision) ((MergeRequestSCMRevision) r).getTarget())
- .getHash()
- : null
- )
- );
+ ? ((BranchSCMRevision) ((MergeRequestSCMRevision) r).getTarget()).getHash()
+ : null));
}
if (r instanceof MergeRequestSCMRevision) {
withRevision(((MergeRequestSCMRevision) r).getOrigin());
@@ -274,5 +254,4 @@ public GitSCM build() {
withRevision(r);
}
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMCauseAction.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMCauseAction.java
index 605daa7f..e50e98b0 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMCauseAction.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMCauseAction.java
@@ -13,5 +13,4 @@ public String getDescription() {
GitLabWebHookCause cause = findCause(GitLabWebHookCause.class);
return (cause != null) ? cause.getShortDescription() : null;
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFile.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFile.java
index 94be1cd5..5193bbbe 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFile.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFile.java
@@ -89,8 +89,7 @@ protected Type type() throws IOException, InterruptedException {
return Type.DIRECTORY;
}
try {
- gitLabApi.getRepositoryFileApi()
- .getFile(projectPath, getPath(), ref);
+ gitLabApi.getRepositoryFileApi().getFile(projectPath, getPath(), ref);
return Type.REGULAR_FILE;
} catch (GitLabApiException e) {
if (e.getHttpStatus() != 404) {
@@ -136,5 +135,4 @@ private List fetchTree() throws IOException {
throw new IOException(String.format("%s not found at %s", getPath(), ref));
}
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFileSystem.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFileSystem.java
index ac0dc906..8fcc8608 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFileSystem.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMFileSystem.java
@@ -1,5 +1,7 @@
package io.jenkins.plugins.gitlabbranchsource;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.apiBuilder;
+
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
@@ -17,19 +19,14 @@
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.apiBuilder;
-
public class GitLabSCMFileSystem extends SCMFileSystem {
private final GitLabApi gitLabApi;
private final String projectPath;
private final String ref;
- protected GitLabSCMFileSystem(
- GitLabApi gitLabApi,
- String projectPath,
- String ref,
- @CheckForNull SCMRevision rev) throws IOException {
+ protected GitLabSCMFileSystem(GitLabApi gitLabApi, String projectPath, String ref, @CheckForNull SCMRevision rev)
+ throws IOException {
super(rev);
this.gitLabApi = gitLabApi;
this.projectPath = projectPath;
@@ -51,7 +48,11 @@ protected GitLabSCMFileSystem(
@Override
public long lastModified() throws IOException {
try {
- return gitLabApi.getCommitsApi().getCommit(projectPath, ref).getCommittedDate().getTime();
+ return gitLabApi
+ .getCommitsApi()
+ .getCommit(projectPath, ref)
+ .getCommittedDate()
+ .getTime();
} catch (GitLabApiException e) {
throw new IOException("Failed to retrieve last modified time", e);
}
@@ -87,24 +88,25 @@ protected boolean supportsDescriptor(SCMSourceDescriptor scmSourceDescriptor) {
}
@Override
- public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm,
- @CheckForNull SCMRevision rev) {
+ public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull SCMRevision rev) {
return null;
}
@Override
- public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head,
- @CheckForNull SCMRevision rev)
- throws IOException, InterruptedException {
+ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision rev)
+ throws IOException, InterruptedException {
GitLabSCMSource gitlabScmSource = (GitLabSCMSource) source;
GitLabApi gitLabApi = apiBuilder(source.getOwner(), gitlabScmSource.getServerName());
String projectPath = gitlabScmSource.getProjectPath();
return build(head, rev, gitLabApi, projectPath);
}
- public SCMFileSystem build(@NonNull SCMHead head, @CheckForNull SCMRevision rev,
- @NonNull GitLabApi gitLabApi, @NonNull String projectPath)
- throws IOException, InterruptedException {
+ public SCMFileSystem build(
+ @NonNull SCMHead head,
+ @CheckForNull SCMRevision rev,
+ @NonNull GitLabApi gitLabApi,
+ @NonNull String projectPath)
+ throws IOException, InterruptedException {
String ref;
if (head instanceof MergeRequestSCMHead) {
ref = ((MergeRequestSCMHead) head).getOriginName();
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator.java
index bfd6a414..0dd7ee7e 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator.java
@@ -1,5 +1,14 @@
package io.jenkins.plugins.gitlabbranchsource;
+import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
+import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.apiBuilder;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getProxyConfig;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrl;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrlFromName;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabIcons.ICON_GITLAB;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabIcons.iconFilePathPattern;
+
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
@@ -69,15 +78,6 @@
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
-import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
-import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.apiBuilder;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getProxyConfig;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrl;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrlFromName;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabIcons.ICON_GITLAB;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabIcons.iconFilePathPattern;
-
public class GitLabSCMNavigator extends SCMNavigator {
public static final Logger LOGGER = Logger.getLogger(GitLabSCMNavigator.class.getName());
@@ -113,6 +113,7 @@ public class GitLabSCMNavigator extends SCMNavigator {
* To store if navigator should include subgroup projects
*/
private boolean wantSubGroupProjects;
+
private transient GitLabOwner gitlabOwner; // TODO check if a better data structure can be used
@DataBoundConstructor
@@ -218,7 +219,6 @@ private GitLabOwner getGitlabOwner(GitLabApi gitLabApi) {
@Override
public void setTraits(@CheckForNull List>> traits) {
this.traits = traits != null ? new ArrayList<>(traits) : new ArrayList<>();
-
}
@NonNull
@@ -228,18 +228,15 @@ protected String id() {
}
@Override
- public void visitSources(@NonNull final SCMSourceObserver observer)
- throws IOException, InterruptedException {
- GitLabSCMNavigatorContext context = new GitLabSCMNavigatorContext()
- .withTraits(traits);
+ public void visitSources(@NonNull final SCMSourceObserver observer) throws IOException, InterruptedException {
+ GitLabSCMNavigatorContext context = new GitLabSCMNavigatorContext().withTraits(traits);
try (GitLabSCMNavigatorRequest request = context.newRequest(this, observer)) {
GitLabApi gitLabApi = apiBuilder(observer.getContext(), serverName);
getGitlabOwner(gitLabApi);
List projects;
if (gitlabOwner instanceof GitLabUser) {
// Even returns the group projects owned by the user
- projects = gitLabApi.getProjectApi()
- .getUserProjects(projectOwner, new ProjectFilter().withOwned(true));
+ projects = gitLabApi.getProjectApi().getUserProjects(projectOwner, new ProjectFilter().withOwned(true));
} else {
isGroup = true;
GroupProjectsFilter groupProjectsFilter = new GroupProjectsFilter();
@@ -256,8 +253,8 @@ public void visitSources(@NonNull final SCMSourceObserver observer)
if (webHookCredentials != null) {
GitLabServer server = GitLabServers.get().findServer(serverName);
String serverUrl = getServerUrl(server);
- webhookGitLabApi = new GitLabApi(serverUrl,
- webHookCredentials.getToken().getPlainText(), null, getProxyConfig(serverUrl));
+ webhookGitLabApi = new GitLabApi(
+ serverUrl, webHookCredentials.getToken().getPlainText(), null, getProxyConfig(serverUrl));
webHookUrl = GitLabHookCreator.getHookUrl(server, true);
}
for (Project p : projects) {
@@ -267,50 +264,60 @@ public void visitSources(@NonNull final SCMSourceObserver observer)
String projectName = getProjectName(gitLabApi, request.withProjectNamingStrategy(), p);
getNavigatorProjects().add(projectPathWithNamespace);
if (StringUtils.isEmpty(p.getDefaultBranch())) {
- observer.getListener().getLogger()
- .format("%nIgnoring project with empty repository %s%n",
+ observer.getListener()
+ .getLogger()
+ .format(
+ "%nIgnoring project with empty repository %s%n",
HyperlinkNote.encodeTo(p.getWebUrl(), p.getName()));
continue;
}
if (p.getArchived() && context.isExcludeArchivedRepositories()) {
- observer.getListener().getLogger()
- .format("%nIgnoring archived project %s%n",
+ observer.getListener()
+ .getLogger()
+ .format(
+ "%nIgnoring archived project %s%n",
HyperlinkNote.encodeTo(p.getWebUrl(), p.getName()));
continue;
}
- observer.getListener().getLogger().format("%nChecking project %s%n",
- HyperlinkNote.encodeTo(p.getWebUrl(), projectName));
+ observer.getListener()
+ .getLogger()
+ .format("%nChecking project %s%n", HyperlinkNote.encodeTo(p.getWebUrl(), projectName));
try {
GitLabServer server = GitLabServers.get().findServer(serverName);
if (webhookGitLabApi != null && webHookUrl != null) {
- observer.getListener().getLogger().format("Web hook %s%n", GitLabHookCreator
- .createWebHookWhenMissing(webhookGitLabApi, projectPathWithNamespace,
- webHookUrl, server.getSecretTokenAsPlainText()));
+ observer.getListener()
+ .getLogger()
+ .format(
+ "Web hook %s%n",
+ GitLabHookCreator.createWebHookWhenMissing(
+ webhookGitLabApi,
+ projectPathWithNamespace,
+ webHookUrl,
+ server.getSecretTokenAsPlainText()));
}
} catch (GitLabApiException e) {
- observer.getListener().getLogger()
- .format("Cannot set web hook: %s%n", e.getReason());
+ observer.getListener().getLogger().format("Cannot set web hook: %s%n", e.getReason());
}
- if (request.process(projectName,
+ if (request.process(
+ projectName,
name -> new GitLabSCMSourceBuilder(
- getId() + "::" + projectPathWithNamespace,
- serverName,
- credentialsId,
- projectOwner,
- projectPathWithNamespace,
- name).withTraits(traits).build(),
+ getId() + "::" + projectPathWithNamespace,
+ serverName,
+ credentialsId,
+ projectOwner,
+ projectPathWithNamespace,
+ name)
+ .withTraits(traits)
+ .build(),
null,
(Witness) (name, isMatch) -> {
if (isMatch) {
- observer.getListener().getLogger()
- .format("Proposing %s%n", name);
+ observer.getListener().getLogger().format("Proposing %s%n", name);
} else {
observer.getListener().getLogger().format("Ignoring %s%n", name);
}
})) {
- observer.getListener().getLogger()
- .format("%n%d projects were processed (query complete)%n",
- count);
+ observer.getListener().getLogger().format("%n%d projects were processed (query complete)%n", count);
return;
}
}
@@ -335,7 +342,8 @@ private String getProjectName(GitLabApi gitLabApi, int projectNamingStrategy, Pr
case 2:
// Project name
projectName = project.getNameWithNamespace()
- .replace(String.format("%s / ", getGitlabOwner(gitLabApi).getFullName()), "");
+ .replace(
+ String.format("%s / ", getGitlabOwner(gitLabApi).getFullName()), "");
break;
case 3:
// Contextual project path
@@ -357,10 +365,9 @@ private PersonalAccessToken getWebHookCredentials(SCMSourceOwner owner) {
if (server == null) {
return null;
}
- GitLabSCMNavigatorContext navigatorContext = new GitLabSCMNavigatorContext()
- .withTraits(traits);
- GitLabSCMSourceContext ctx = new GitLabSCMSourceContext(null, SCMHeadObserver.none())
- .withTraits(navigatorContext.traits());
+ GitLabSCMNavigatorContext navigatorContext = new GitLabSCMNavigatorContext().withTraits(traits);
+ GitLabSCMSourceContext ctx =
+ new GitLabSCMSourceContext(null, SCMHeadObserver.none()).withTraits(navigatorContext.traits());
GitLabHookRegistration webhookMode = ctx.webhookRegistration();
switch (webhookMode) {
case DISABLE:
@@ -388,9 +395,9 @@ private PersonalAccessToken getWebHookCredentials(SCMSourceOwner owner) {
@NonNull
@Override
- protected List retrieveActions(@NonNull SCMNavigatorOwner owner,
- SCMNavigatorEvent event,
- @NonNull TaskListener listener) throws IOException, InterruptedException {
+ protected List retrieveActions(
+ @NonNull SCMNavigatorOwner owner, SCMNavigatorEvent event, @NonNull TaskListener listener)
+ throws IOException, InterruptedException {
getGitlabOwner(owner);
String fullName = gitlabOwner.getFullName();
String webUrl = gitlabOwner.getWebUrl();
@@ -400,10 +407,7 @@ protected List retrieveActions(@NonNull SCMNavigatorOwner owner,
description = ((GitLabGroup) gitlabOwner).getDescription();
}
List result = new ArrayList<>();
- result.add(new ObjectMetadataAction(
- Util.fixEmpty(fullName),
- description,
- webUrl));
+ result.add(new ObjectMetadataAction(Util.fixEmpty(fullName), description, webUrl));
if (StringUtils.isNotBlank(avatarUrl)) {
result.add(new GitLabAvatar(avatarUrl));
}
@@ -411,19 +415,20 @@ protected List retrieveActions(@NonNull SCMNavigatorOwner owner,
if (StringUtils.isBlank(webUrl)) {
listener.getLogger().println("Web URL unspecified");
} else {
- listener.getLogger().printf("%s URL: %s%n", gitlabOwner.getWord(),
- HyperlinkNote
- .encodeTo(webUrl, StringUtils.defaultIfBlank(fullName, webUrl)));
+ listener.getLogger()
+ .printf(
+ "%s URL: %s%n",
+ gitlabOwner.getWord(),
+ HyperlinkNote.encodeTo(webUrl, StringUtils.defaultIfBlank(fullName, webUrl)));
}
return result;
}
@Override
public void afterSave(@NonNull SCMNavigatorOwner owner) {
- GitLabSCMNavigatorContext navigatorContext = new GitLabSCMNavigatorContext()
- .withTraits(traits);
- GitLabSCMSourceContext ctx = new GitLabSCMSourceContext(null, SCMHeadObserver.none())
- .withTraits(navigatorContext.traits());
+ GitLabSCMNavigatorContext navigatorContext = new GitLabSCMNavigatorContext().withTraits(traits);
+ GitLabSCMSourceContext ctx =
+ new GitLabSCMSourceContext(null, SCMHeadObserver.none()).withTraits(navigatorContext.traits());
GitLabHookRegistration systemhookMode = ctx.systemhookRegistration();
GitLabHookCreator.register(owner, this, systemhookMode);
}
@@ -445,7 +450,8 @@ public static class DescriptorImpl extends SCMNavigatorDescriptor implements Ico
@Inject
private GitLabSCMSource.DescriptorImpl delegate;
- public static FormValidation doCheckProjectOwner(@AncestorInPath SCMSourceOwner context,
+ public static FormValidation doCheckProjectOwner(
+ @AncestorInPath SCMSourceOwner context,
@QueryParameter String projectOwner,
@QueryParameter String serverName) {
if (projectOwner.equals("")) {
@@ -495,8 +501,8 @@ public SCMNavigator newInstance(String name) {
return navigator;
}
- public ListBoxModel doFillServerNameItems(@AncestorInPath SCMSourceOwner context,
- @QueryParameter String serverName) {
+ public ListBoxModel doFillServerNameItems(
+ @AncestorInPath SCMSourceOwner context, @QueryParameter String serverName) {
if (context == null) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
// must have admin if you want the list without a context
@@ -515,7 +521,8 @@ public ListBoxModel doFillServerNameItems(@AncestorInPath SCMSourceOwner context
return GitLabServers.get().getServerItems();
}
- public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
+ public ListBoxModel doFillCredentialsIdItems(
+ @AncestorInPath SCMSourceOwner context,
@QueryParameter String serverName,
@QueryParameter String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
@@ -536,9 +543,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner cont
}
result.includeEmptyValue();
result.includeMatchingAs(
- context instanceof Queue.Task
- ? ((Queue.Task) context).getDefaultAuthentication()
- : ACL.SYSTEM,
+ context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM,
context,
StandardUsernameCredentials.class,
fromUri(getServerUrlFromName(serverName)).build(),
@@ -548,18 +553,16 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner cont
@SuppressWarnings("unused") // jelly
public List>> getTraitsDescriptorLists() {
- GitLabSCMSource.DescriptorImpl sourceDescriptor = Jenkins.get()
- .getDescriptorByType(GitLabSCMSource.DescriptorImpl.class);
+ GitLabSCMSource.DescriptorImpl sourceDescriptor =
+ Jenkins.get().getDescriptorByType(GitLabSCMSource.DescriptorImpl.class);
List> all = new ArrayList<>();
- all.addAll(SCMNavigatorTrait
- ._for(this, GitLabSCMNavigatorContext.class, GitLabSCMSourceBuilder.class));
+ all.addAll(SCMNavigatorTrait._for(this, GitLabSCMNavigatorContext.class, GitLabSCMSourceBuilder.class));
all.addAll(SCMSourceTrait._for(sourceDescriptor, GitLabSCMSourceContext.class, null));
all.addAll(SCMSourceTrait._for(sourceDescriptor, null, GitLabSCMBuilder.class));
Set> dedup = new HashSet<>();
- for (Iterator> iterator = all.iterator(); iterator.hasNext();) {
+ for (Iterator> iterator = all.iterator(); iterator.hasNext(); ) {
SCMTraitDescriptor> d = iterator.next();
- if (dedup.contains(d)
- || d instanceof GitBrowserSCMSourceTrait.DescriptorImpl) {
+ if (dedup.contains(d) || d instanceof GitBrowserSCMSourceTrait.DescriptorImpl) {
// remove any we have seen already and ban the browser configuration as it will
// always be github
iterator.remove();
@@ -568,18 +571,25 @@ public List>> getTraitsDescriptor
}
}
List>> result = new ArrayList<>();
- NamedArrayList
- .select(all, "Projects", new NamedArrayList.Predicate>() {
+ NamedArrayList.select(
+ all,
+ "Projects",
+ new NamedArrayList.Predicate>() {
@Override
public boolean test(SCMTraitDescriptor> scmTraitDescriptor) {
return scmTraitDescriptor instanceof SCMNavigatorTraitDescriptor;
}
},
- true, result);
- NamedArrayList.select(all, "Within project", NamedArrayList
- .anyOf(NamedArrayList.withAnnotation(Discovery.class),
+ true,
+ result);
+ NamedArrayList.select(
+ all,
+ "Within project",
+ NamedArrayList.anyOf(
+ NamedArrayList.withAnnotation(Discovery.class),
NamedArrayList.withAnnotation(Selection.class)),
- true, result);
+ true,
+ result);
NamedArrayList.select(all, "Additional", null, true, result);
return result;
}
@@ -591,5 +601,4 @@ public List>> getTraitsDefaults() {
return new ArrayList<>(delegate.getTraitsDefaults());
}
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorContext.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorContext.java
index 8d8a86fc..8197b82c 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorContext.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorContext.java
@@ -5,8 +5,8 @@
import jenkins.scm.api.SCMSourceObserver;
import jenkins.scm.api.trait.SCMNavigatorContext;
-public class GitLabSCMNavigatorContext extends
- SCMNavigatorContext {
+public class GitLabSCMNavigatorContext
+ extends SCMNavigatorContext {
private boolean wantSubgroupProjects;
@@ -17,8 +17,7 @@ public class GitLabSCMNavigatorContext extends
@NonNull
@Override
- public GitLabSCMNavigatorRequest newRequest(@NonNull SCMNavigator navigator,
- @NonNull SCMSourceObserver observer) {
+ public GitLabSCMNavigatorRequest newRequest(@NonNull SCMNavigator navigator, @NonNull SCMSourceObserver observer) {
return new GitLabSCMNavigatorRequest(navigator, this, observer);
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorRequest.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorRequest.java
index 77385299..876c9f3a 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorRequest.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorRequest.java
@@ -11,9 +11,10 @@ public class GitLabSCMNavigatorRequest extends SCMNavigatorRequest {
private int projectNamingStrategy;
- protected GitLabSCMNavigatorRequest(@NonNull SCMNavigator source,
- @NonNull GitLabSCMNavigatorContext context,
- @NonNull SCMSourceObserver observer) {
+ protected GitLabSCMNavigatorRequest(
+ @NonNull SCMNavigator source,
+ @NonNull GitLabSCMNavigatorContext context,
+ @NonNull SCMSourceObserver observer) {
super(source, context, observer);
wantSubgroupProjects = context.wantSubgroupProjects();
projectNamingStrategy = context.withProjectNamingStrategy();
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java
index ba295591..11b38bca 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java
@@ -1,5 +1,16 @@
package io.jenkins.plugins.gitlabbranchsource;
+import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
+import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.apiBuilder;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.branchUriTemplate;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.commitUriTemplate;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrlFromName;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.mergeRequestUriTemplate;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.splitPath;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.tagUriTemplate;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabIcons.ICON_GITLAB;
+
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
@@ -91,17 +102,6 @@
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
-import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
-import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.apiBuilder;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.branchUriTemplate;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.commitUriTemplate;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getServerUrlFromName;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.mergeRequestUriTemplate;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.splitPath;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.tagUriTemplate;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabIcons.ICON_GITLAB;
-
public class GitLabSCMSource extends AbstractGitSCMSource {
public static final Logger LOGGER = Logger.getLogger(GitLabSCMSource.class.getName());
@@ -120,12 +120,14 @@ public class GitLabSCMSource extends AbstractGitSCMSource {
* The cache of {@link ObjectMetadataAction} instances for each open MR.
*/
@NonNull
- private transient /* effectively final */ Map mergeRequestMetadataCache = new ConcurrentHashMap<>();
+ private transient /* effectively final */ Map mergeRequestMetadataCache =
+ new ConcurrentHashMap<>();
/**
* The cache of {@link ObjectMetadataAction} instances for each open MR.
*/
@NonNull
- private transient /* effectively final */ Map mergeRequestContributorCache = new ConcurrentHashMap<>();
+ private transient /* effectively final */ Map mergeRequestContributorCache =
+ new ConcurrentHashMap<>();
@DataBoundConstructor
public GitLabSCMSource(String serverName, String projectOwner, String projectPath) {
@@ -187,8 +189,14 @@ public void setCredentialsId(String credentialsId) {
@Override
public String getRemote() {
- return GitLabSCMBuilder.checkoutUriTemplate(getOwner(), getServerUrlFromName(serverName), getHttpRemote(),
- getSshRemote(), getCredentialsId(), projectPath).expand();
+ return GitLabSCMBuilder.checkoutUriTemplate(
+ getOwner(),
+ getServerUrlFromName(serverName),
+ getHttpRemote(),
+ getSshRemote(),
+ getCredentialsId(),
+ projectPath)
+ .expand();
}
protected Project getGitlabProject() {
@@ -255,39 +263,48 @@ protected SCMRevision retrieve(@NonNull SCMHead head, @NonNull TaskListener list
getGitlabProject(gitLabApi);
if (head instanceof BranchSCMHead) {
listener.getLogger().format("Querying the current revision of branch %s...%n", head.getName());
- String revision = gitLabApi.getRepositoryApi().getBranch(gitlabProject, head.getName()).getCommit()
+ String revision = gitLabApi
+ .getRepositoryApi()
+ .getBranch(gitlabProject, head.getName())
+ .getCommit()
.getId();
listener.getLogger().format("Current revision of branch %s is %s%n", head.getName(), revision);
return new BranchSCMRevision((BranchSCMHead) head, revision);
} else if (head instanceof MergeRequestSCMHead) {
MergeRequestSCMHead h = (MergeRequestSCMHead) head;
listener.getLogger().format("Querying the current revision of merge request #%s...%n", h.getId());
- MergeRequest mr = gitLabApi.getMergeRequestApi().getMergeRequest(gitlabProject,
- Long.parseLong(h.getId()));
- String targetSha = gitLabApi.getRepositoryApi().getBranch(mr.getTargetProjectId(), mr.getTargetBranch())
- .getCommit().getId();
+ MergeRequest mr =
+ gitLabApi.getMergeRequestApi().getMergeRequest(gitlabProject, Long.parseLong(h.getId()));
+ String targetSha = gitLabApi
+ .getRepositoryApi()
+ .getBranch(mr.getTargetProjectId(), mr.getTargetBranch())
+ .getCommit()
+ .getId();
if (mr.getState().equals(Constants.MergeRequestState.OPENED.toString())) {
- listener.getLogger().format("Current revision of merge request #%s is %s%n",
- h.getId(), mr.getSha());
+ listener.getLogger()
+ .format("Current revision of merge request #%s is %s%n", h.getId(), mr.getSha());
return new MergeRequestSCMRevision(
h,
- new BranchSCMRevision(
- h.getTarget(),
- targetSha),
- new BranchSCMRevision(
- new BranchSCMHead(h.getOriginName()),
- mr.getSha()));
+ new BranchSCMRevision(h.getTarget(), targetSha),
+ new BranchSCMRevision(new BranchSCMHead(h.getOriginName()), mr.getSha()));
} else {
listener.getLogger().format("Merge request #%s is CLOSED%n", h.getId());
return null;
}
} else if (head instanceof GitLabTagSCMHead) {
listener.getLogger().format("Querying the current revision of tag %s...%n", head.getName());
- String revision = gitLabApi.getTagsApi().getTag(gitlabProject, head.getName()).getCommit().getId();
+ String revision = gitLabApi
+ .getTagsApi()
+ .getTag(gitlabProject, head.getName())
+ .getCommit()
+ .getId();
listener.getLogger().format("Current revision of tag %s is %s%n", head.getName(), revision);
return new GitTagSCMRevision((GitLabTagSCMHead) head, revision);
} else {
- listener.getLogger().format("Unknown head: %s of type %s%n", head.getName(), head.getClass().getName());
+ listener.getLogger()
+ .format(
+ "Unknown head: %s of type %s%n",
+ head.getName(), head.getClass().getName());
return null;
}
} catch (GitLabApiException e) {
@@ -297,9 +314,12 @@ protected SCMRevision retrieve(@NonNull SCMHead head, @NonNull TaskListener list
}
@Override
- protected void retrieve(SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer,
+ protected void retrieve(
+ SCMSourceCriteria criteria,
+ @NonNull SCMHeadObserver observer,
SCMHeadEvent> event,
- @NonNull TaskListener listener) throws IOException, InterruptedException {
+ @NonNull TaskListener listener)
+ throws IOException, InterruptedException {
try {
GitLabApi gitLabApi = apiBuilder(this.getOwner(), serverName);
getGitlabProject(gitLabApi);
@@ -307,9 +327,7 @@ protected void retrieve(SCMSourceCriteria criteria, @NonNull SCMHeadObserver obs
sshRemote = gitlabProject.getSshUrlToRepo();
httpRemote = gitlabProject.getHttpUrlToRepo();
GitLabSCMSourceContext ctx = new GitLabSCMSourceContext(criteria, observer);
- try (GitLabSCMSourceRequest request = ctx
- .withTraits(getTraits())
- .newRequest(this, listener)) {
+ try (GitLabSCMSourceRequest request = ctx.withTraits(getTraits()).newRequest(this, listener)) {
request.setGitLabApi(gitLabApi);
request.setProject(gitlabProject);
request.setMembers(getMembers());
@@ -321,26 +339,30 @@ protected void retrieve(SCMSourceCriteria criteria, @NonNull SCMHeadObserver obs
// If `forkedFromProject` is null it doesn't mean anything
if (gitlabProject.getForkedFromProject() == null) {
listener.getLogger()
- .format(
- "%nUnable to detect if it is a mirror or not still fetching MRs anyway...%n");
- List mrs = gitLabApi.getMergeRequestApi()
+ .format("%nUnable to detect if it is a mirror or not still fetching MRs anyway...%n");
+ List mrs = gitLabApi
+ .getMergeRequestApi()
.getMergeRequests(gitlabProject, Constants.MergeRequestState.OPENED);
- mrs = mrs.stream().filter(mr -> mr.getSourceProjectId() != null)
+ mrs = mrs.stream()
+ .filter(mr -> mr.getSourceProjectId() != null)
.collect(Collectors.toList());
request.setMergeRequests(mrs);
} else if (ctx.buildMRForksNotMirror()) {
listener.getLogger()
- .format(
- "%nCollecting MRs for fork except those that target its upstream...%n");
- List mrs = gitLabApi.getMergeRequestApi()
+ .format("%nCollecting MRs for fork except those that target its upstream...%n");
+ List mrs = gitLabApi
+ .getMergeRequestApi()
.getMergeRequests(gitlabProject, Constants.MergeRequestState.OPENED);
- mrs = mrs.stream().filter(mr -> mr.getSourceProjectId() != null
- && !mr.getTargetProjectId().equals(gitlabProject.getForkedFromProject().getId()))
+ mrs = mrs.stream()
+ .filter(mr -> mr.getSourceProjectId() != null
+ && !mr.getTargetProjectId()
+ .equals(gitlabProject
+ .getForkedFromProject()
+ .getId()))
.collect(Collectors.toList());
request.setMergeRequests(mrs);
} else {
- listener.getLogger()
- .format("%nIgnoring merge requests as project is a mirror...%n");
+ listener.getLogger().format("%nIgnoring merge requests as project is a mirror...%n");
}
}
if (request.isFetchTags()) {
@@ -354,20 +376,23 @@ protected void retrieve(SCMSourceCriteria criteria, @NonNull SCMHeadObserver obs
count++;
String branchName = branch.getName();
String sha = branch.getCommit().getId();
- listener.getLogger().format("%nChecking branch %s%n",
- HyperlinkNote.encodeTo(
- branchUriTemplate(gitlabProject.getWebUrl())
- .set("branch", splitPath(branchName))
- .expand(),
- branchName));
- if (request.process(new BranchSCMHead(branchName),
- (SCMSourceRequest.RevisionLambda) head -> new BranchSCMRevision(
- head, sha),
+ listener.getLogger()
+ .format(
+ "%nChecking branch %s%n",
+ HyperlinkNote.encodeTo(
+ branchUriTemplate(gitlabProject.getWebUrl())
+ .set("branch", splitPath(branchName))
+ .expand(),
+ branchName));
+ if (request.process(
+ new BranchSCMHead(branchName),
+ (SCMSourceRequest.RevisionLambda)
+ head -> new BranchSCMRevision(head, sha),
new SCMSourceRequest.ProbeLambda() {
@NonNull
@Override
- public SCMSourceCriteria.Probe create(@NonNull BranchSCMHead head,
- @Nullable BranchSCMRevision revision)
+ public SCMSourceCriteria.Probe create(
+ @NonNull BranchSCMHead head, @Nullable BranchSCMRevision revision)
throws IOException {
return createProbe(head, revision);
}
@@ -379,8 +404,7 @@ public SCMSourceCriteria.Probe create(@NonNull BranchSCMHead head,
listener.getLogger().format("Does not meet criteria%n");
}
})) {
- listener.getLogger()
- .format("%n%d branches were processed (query completed)%n", count);
+ listener.getLogger().format("%n%d branches were processed (query completed)%n", count);
return;
}
}
@@ -391,72 +415,85 @@ public SCMSourceCriteria.Probe create(@NonNull BranchSCMHead head,
listener.getLogger().format("%nChecking merge requests..%n");
HashMap forkMrSources = new HashMap<>();
for (MergeRequest mr : request.getMergeRequests()) {
- mergeRequestContributorCache.put(mr.getIid(),
+ mergeRequestContributorCache.put(
+ mr.getIid(),
new ContributorMetadataAction(
mr.getAuthor().getUsername(),
mr.getAuthor().getName(),
mr.getAuthor().getEmail()));
- mergeRequestMetadataCache.put(mr.getIid(),
- new ObjectMetadataAction(
- mr.getTitle(),
- mr.getDescription(),
- mr.getWebUrl()));
+ mergeRequestMetadataCache.put(
+ mr.getIid(),
+ new ObjectMetadataAction(mr.getTitle(), mr.getDescription(), mr.getWebUrl()));
count++;
- listener.getLogger().format("%nChecking merge request %s%n",
- HyperlinkNote.encodeTo(
- mergeRequestUriTemplate(gitlabProject.getWebUrl())
- .set("iid", mr.getIid())
- .expand(),
- "!" + mr.getIid()));
- Map> strategies = request
- .getMRStrategies();
+ listener.getLogger()
+ .format(
+ "%nChecking merge request %s%n",
+ HyperlinkNote.encodeTo(
+ mergeRequestUriTemplate(gitlabProject.getWebUrl())
+ .set("iid", mr.getIid())
+ .expand(),
+ "!" + mr.getIid()));
+ Map> strategies = request.getMRStrategies();
boolean fork = !mr.getSourceProjectId().equals(mr.getTargetProjectId());
String originOwner = mr.getAuthor().getUsername();
String originProjectPath = projectPath;
if (fork && !forkMrSources.containsKey(mr.getSourceProjectId())) {
// This is a hack to get the path with namespace of source project for forked
// mrs
- originProjectPath = gitLabApi.getProjectApi()
- .getProject(mr.getSourceProjectId()).getPathWithNamespace();
+ originProjectPath = gitLabApi
+ .getProjectApi()
+ .getProject(mr.getSourceProjectId())
+ .getPathWithNamespace();
forkMrSources.put(mr.getSourceProjectId(), originProjectPath);
} else if (fork) {
originProjectPath = forkMrSources.get(mr.getSourceProjectId());
}
String targetSha;
try {
- targetSha = gitLabApi.getRepositoryApi()
- .getBranch(mr.getTargetProjectId(), mr.getTargetBranch()).getCommit().getId();
+ targetSha = gitLabApi
+ .getRepositoryApi()
+ .getBranch(mr.getTargetProjectId(), mr.getTargetBranch())
+ .getCommit()
+ .getId();
} catch (Exception e) {
- listener.getLogger().format("Failed getting TargetBranch from Merge Request: " + mr.getIid()
- + " (" + mr.getTitle() + ")%n%s", e);
+ listener.getLogger()
+ .format(
+ "Failed getting TargetBranch from Merge Request: " + mr.getIid() + " ("
+ + mr.getTitle() + ")%n%s",
+ e);
continue;
}
- LOGGER.log(Level.FINE,
- String.format("%s -> %s", originOwner, (request.isMember(originOwner) ? "Trusted"
- : "Untrusted")));
+ LOGGER.log(
+ Level.FINE,
+ String.format(
+ "%s -> %s",
+ originOwner, (request.isMember(originOwner) ? "Trusted" : "Untrusted")));
for (ChangeRequestCheckoutStrategy strategy : strategies.get(fork)) {
- if (request.process(new MergeRequestSCMHead(
- "MR-" + mr.getIid() + (strategies.get(fork).size() > 1 ? "-" + strategy.name()
- .toLowerCase(Locale.ENGLISH) : ""),
- mr.getIid(),
- new BranchSCMHead(mr.getTargetBranch()),
- strategy,
- fork
- ? new SCMHeadOrigin.Fork(originProjectPath)
- : SCMHeadOrigin.DEFAULT,
- originOwner,
- originProjectPath,
- mr.getSourceBranch(),
- mr.getTitle()),
- (SCMSourceRequest.RevisionLambda) head -> new MergeRequestSCMRevision(
- head,
- new BranchSCMRevision(
- head.getTarget(),
- targetSha // Latest revision of target branch
- ),
- new BranchSCMRevision(
- new BranchSCMHead(head.getOriginName()),
- mr.getSha())),
+ if (request.process(
+ new MergeRequestSCMHead(
+ "MR-" + mr.getIid()
+ + (strategies.get(fork).size() > 1
+ ? "-"
+ + strategy.name()
+ .toLowerCase(Locale.ENGLISH)
+ : ""),
+ mr.getIid(),
+ new BranchSCMHead(mr.getTargetBranch()),
+ strategy,
+ fork ? new SCMHeadOrigin.Fork(originProjectPath) : SCMHeadOrigin.DEFAULT,
+ originOwner,
+ originProjectPath,
+ mr.getSourceBranch(),
+ mr.getTitle()),
+ (SCMSourceRequest.RevisionLambda)
+ head -> new MergeRequestSCMRevision(
+ head,
+ new BranchSCMRevision(
+ head.getTarget(),
+ targetSha // Latest revision of target branch
+ ),
+ new BranchSCMRevision(
+ new BranchSCMHead(head.getOriginName()), mr.getSha())),
new SCMSourceRequest.ProbeLambda() {
@NonNull
@Override
@@ -466,11 +503,9 @@ public SCMSourceCriteria.Probe create(
throws IOException, InterruptedException {
boolean isTrusted = request.isTrusted(head);
if (!isTrusted) {
- listener.getLogger()
- .format("(not from a trusted source)%n");
+ listener.getLogger().format("(not from a trusted source)%n");
}
- return createProbe(isTrusted ? head : head.getTarget(),
- revision);
+ return createProbe(isTrusted ? head : head.getTarget(), revision);
}
},
(SCMSourceRequest.Witness) (head, revision, isMatch) -> {
@@ -481,9 +516,7 @@ public SCMSourceCriteria.Probe create(
}
})) {
listener.getLogger()
- .format(
- "%n%d merge requests were processed (query completed)%n",
- count);
+ .format("%n%d merge requests were processed (query completed)%n", count);
return;
}
}
@@ -499,37 +532,39 @@ public SCMSourceCriteria.Probe create(
String tagName = tag.getName();
Long tagDate = tag.getCommit().getCommittedDate().getTime();
String sha = tag.getCommit().getId();
- listener.getLogger().format("%nChecking tag %s%n",
- HyperlinkNote.encodeTo(
- tagUriTemplate(gitlabProject.getWebUrl())
- .set("tag", splitPath(tag.getName()))
- .expand(),
- tag.getName()));
+ listener.getLogger()
+ .format(
+ "%nChecking tag %s%n",
+ HyperlinkNote.encodeTo(
+ tagUriTemplate(gitlabProject.getWebUrl())
+ .set("tag", splitPath(tag.getName()))
+ .expand(),
+ tag.getName()));
GitLabTagSCMHead head = new GitLabTagSCMHead(tagName, tagDate);
- if (request.process(head, new GitTagSCMRevision(head, sha),
+ if (request.process(
+ head,
+ new GitTagSCMRevision(head, sha),
new SCMSourceRequest.ProbeLambda() {
@NonNull
@Override
public SCMSourceCriteria.Probe create(
- @NonNull GitLabTagSCMHead head,
- @Nullable GitTagSCMRevision revision)
+ @NonNull GitLabTagSCMHead head, @Nullable GitTagSCMRevision revision)
throws IOException {
return createProbe(head, revision);
}
- }, (SCMSourceRequest.Witness) (head1, revision, isMatch) -> {
+ },
+ (SCMSourceRequest.Witness) (head1, revision, isMatch) -> {
if (isMatch) {
listener.getLogger().format("Met criteria%n");
} else {
listener.getLogger().format("Does not meet criteria%n");
}
})) {
- listener.getLogger()
- .format("%n%d tags were processed (query completed)%n", count);
+ listener.getLogger().format("%n%d tags were processed (query completed)%n", count);
return;
}
}
- listener.getLogger()
- .format("%n%d tags were processed (query completed)%n", count);
+ listener.getLogger().format("%n%d tags were processed (query completed)%n", count);
}
}
} catch (GitLabApiException e) {
@@ -585,8 +620,10 @@ protected List retrieveActions(@NonNull SCMHead head, SCMHeadEvent event
getGitlabProject();
List result = new ArrayList<>();
if (head instanceof BranchSCMHead) {
- String branchUrl = branchUriTemplate(serverName).set("project", splitPath(projectPath))
- .set("branch", head.getName()).expand();
+ String branchUrl = branchUriTemplate(serverName)
+ .set("project", splitPath(projectPath))
+ .set("branch", head.getName())
+ .expand();
result.add(new ObjectMetadataAction(null, null, branchUrl));
result.add(GitLabLink.toBranch(branchUrl));
if (head.getName().equals(gitlabProject.getDefaultBranch())) {
@@ -594,7 +631,9 @@ protected List retrieveActions(@NonNull SCMHead head, SCMHeadEvent event
}
} else if (head instanceof MergeRequestSCMHead) {
long iid = Long.parseLong(((MergeRequestSCMHead) head).getId());
- String mergeUrl = mergeRequestUriTemplate(serverName).set("project", splitPath(projectPath)).set("iid", iid)
+ String mergeUrl = mergeRequestUriTemplate(serverName)
+ .set("project", splitPath(projectPath))
+ .set("iid", iid)
.expand();
ObjectMetadataAction metadataAction = mergeRequestMetadataCache.get(iid);
if (metadataAction == null) {
@@ -608,7 +647,9 @@ protected List retrieveActions(@NonNull SCMHead head, SCMHeadEvent event
}
result.add(GitLabLink.toMergeRequest(mergeUrl));
} else if (head instanceof GitLabTagSCMHead) {
- String tagUrl = tagUriTemplate(serverName).set("project", splitPath(projectPath)).set("tag", head.getName())
+ String tagUrl = tagUriTemplate(serverName)
+ .set("project", splitPath(projectPath))
+ .set("tag", head.getName())
.expand();
result.add(new ObjectMetadataAction(null, null, tagUrl));
result.add(GitLabLink.toTag(tagUrl));
@@ -628,7 +669,8 @@ public SCMRevision getTrustedRevision(@NonNull SCMRevision revision, @NonNull Ta
if (revision instanceof MergeRequestSCMRevision) {
MergeRequestSCMHead head = (MergeRequestSCMHead) revision.getHead();
try (GitLabSCMSourceRequest request = new GitLabSCMSourceContext(null, SCMHeadObserver.none())
- .withTraits(traits).newRequest(this, listener)) {
+ .withTraits(traits)
+ .newRequest(this, listener)) {
request.setMembers(getMembers());
boolean isTrusted = request.isTrusted(head);
LOGGER.log(Level.FINEST, String.format("Trusted Revision: %s -> %s", head.getOriginOwner(), isTrusted));
@@ -639,8 +681,10 @@ public SCMRevision getTrustedRevision(@NonNull SCMRevision revision, @NonNull Ta
LOGGER.log(Level.SEVERE, "Exception caught: " + e, e);
}
MergeRequestSCMRevision rev = (MergeRequestSCMRevision) revision;
- listener.getLogger().format("Loading trusted files from target branch %s at %s rather than %s%n",
- head.getTarget().getName(), rev.getBaseHash(), rev.getHeadHash());
+ listener.getLogger()
+ .format(
+ "Loading trusted files from target branch %s at %s rather than %s%n",
+ head.getTarget().getName(), rev.getBaseHash(), rev.getHeadHash());
return new SCMRevisionImpl(head.getTarget(), rev.getBaseHash());
}
return revision;
@@ -648,12 +692,15 @@ public SCMRevision getTrustedRevision(@NonNull SCMRevision revision, @NonNull Ta
@NonNull
@Override
- protected List retrieveActions(@NonNull SCMRevision revision, SCMHeadEvent event,
- @NonNull TaskListener listener) throws IOException, InterruptedException {
+ protected List retrieveActions(
+ @NonNull SCMRevision revision, SCMHeadEvent event, @NonNull TaskListener listener)
+ throws IOException, InterruptedException {
List actions = new ArrayList<>();
if (revision instanceof SCMRevisionImpl) {
String hash = ((SCMRevisionImpl) revision).getHash();
- String commitUrl = commitUriTemplate(serverName).set("project", splitPath(projectPath)).set("hash", hash)
+ String commitUrl = commitUriTemplate(serverName)
+ .set("project", splitPath(projectPath))
+ .set("hash", hash)
.expand();
actions.add(GitLabLink.toCommit(commitUrl));
}
@@ -669,8 +716,8 @@ protected List retrieveActions(@NonNull SCMRevision revision, SCMHeadEve
@Override
protected SCMProbe createProbe(@NonNull final SCMHead head, SCMRevision revision) throws IOException {
try {
- GitLabSCMFileSystem.BuilderImpl builder = ExtensionList.lookup(SCMFileSystem.Builder.class)
- .get(GitLabSCMFileSystem.BuilderImpl.class);
+ GitLabSCMFileSystem.BuilderImpl builder =
+ ExtensionList.lookup(SCMFileSystem.Builder.class).get(GitLabSCMFileSystem.BuilderImpl.class);
if (builder == null) {
throw new AssertionError();
}
@@ -724,7 +771,8 @@ public void afterSave() {
// the jenkins instance.
if (server != null && server.isManageWebHooks()) {
GitLabSCMSourceContext ctx = new GitLabSCMSourceContext(null, SCMHeadObserver.none())
- .withTraits(new GitLabSCMNavigatorContext().withTraits(traits).traits());
+ .withTraits(
+ new GitLabSCMNavigatorContext().withTraits(traits).traits());
GitLabHookRegistration webhookMode = ctx.webhookRegistration();
GitLabHookRegistration systemhookMode = ctx.systemhookRegistration();
GitLabHookCreator.register(this, webhookMode, systemhookMode);
@@ -732,8 +780,12 @@ public void afterSave() {
}
public PersonalAccessToken credentials() {
- return CredentialsMatchers.firstOrNull(lookupCredentials(PersonalAccessToken.class, getOwner(),
- Jenkins.getAuthentication(), fromUri(getServerUrlFromName(serverName)).build()),
+ return CredentialsMatchers.firstOrNull(
+ lookupCredentials(
+ PersonalAccessToken.class,
+ getOwner(),
+ Jenkins.getAuthentication(),
+ fromUri(getServerUrlFromName(serverName)).build()),
GitLabServer.CREDENTIALS_MATCHER);
}
@@ -760,8 +812,8 @@ public String getSelectedServer(@QueryParameter String serverName) {
return serverName;
}
- public ListBoxModel doFillServerNameItems(@AncestorInPath SCMSourceOwner context,
- @QueryParameter String serverName) {
+ public ListBoxModel doFillServerNameItems(
+ @AncestorInPath SCMSourceOwner context, @QueryParameter String serverName) {
if (context == null) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
// must have admin if you want the list without a context
@@ -780,8 +832,10 @@ public ListBoxModel doFillServerNameItems(@AncestorInPath SCMSourceOwner context
return GitLabServers.get().getServerItems();
}
- public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
- @QueryParameter String serverName, @QueryParameter String credentialsId) {
+ public ListBoxModel doFillCredentialsIdItems(
+ @AncestorInPath SCMSourceOwner context,
+ @QueryParameter String serverName,
+ @QueryParameter String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
if (context == null) {
// must have admin if you want the list without a context
@@ -801,12 +855,16 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner cont
result.includeEmptyValue();
result.includeMatchingAs(
context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM,
- context, StandardUsernameCredentials.class, fromUri(getServerUrlFromName(serverName)).build(),
+ context,
+ StandardUsernameCredentials.class,
+ fromUri(getServerUrlFromName(serverName)).build(),
GitClient.CREDENTIALS_MATCHER);
return result;
}
- public long getProjectId(@AncestorInPath SCMSourceOwner context, @QueryParameter String projectPath,
+ public long getProjectId(
+ @AncestorInPath SCMSourceOwner context,
+ @QueryParameter String projectPath,
@QueryParameter String serverName) {
List gitLabServers = GitLabServers.get().getServers();
if (gitLabServers.size() == 0) {
@@ -828,8 +886,10 @@ public long getProjectId(@AncestorInPath SCMSourceOwner context, @QueryParameter
return -1;
}
- public ListBoxModel doFillProjectPathItems(@AncestorInPath SCMSourceOwner context,
- @QueryParameter String serverName, @QueryParameter String projectOwner) {
+ public ListBoxModel doFillProjectPathItems(
+ @AncestorInPath SCMSourceOwner context,
+ @QueryParameter String serverName,
+ @QueryParameter String projectOwner) {
List gitLabServers = GitLabServers.get().getServers();
if (gitLabServers.size() == 0) {
return new StandardListBoxModel().includeEmptyValue();
@@ -847,8 +907,9 @@ public ListBoxModel doFillProjectPathItems(@AncestorInPath SCMSourceOwner contex
return new StandardListBoxModel().includeEmptyValue();
}
try {
- for (Project p : gitLabApi.getProjectApi().getUserProjects(projectOwner,
- new ProjectFilter().withOwned(true))) {
+ for (Project p : gitLabApi
+ .getProjectApi()
+ .getUserProjects(projectOwner, new ProjectFilter().withOwned(true))) {
result.add(p.getPathWithNamespace());
}
} catch (GitLabApiException e) {
@@ -868,7 +929,7 @@ public List>> getTraitsDescriptor
all.addAll(SCMSourceTrait._for(this, GitLabSCMSourceContext.class, null));
all.addAll(SCMSourceTrait._for(this, null, GitLabSCMBuilder.class));
Set> dedup = new HashSet<>();
- for (Iterator> iterator = all.iterator(); iterator.hasNext();) {
+ for (Iterator> iterator = all.iterator(); iterator.hasNext(); ) {
SCMTraitDescriptor> d = iterator.next();
if (dedup.contains(d) || d instanceof GitBrowserSCMSourceTrait.DescriptorImpl) {
// remove any we have seen already and ban the browser configuration as it will
@@ -879,16 +940,25 @@ public List>> getTraitsDescriptor
}
}
List>> result = new ArrayList<>();
- NamedArrayList.select(all, "Projects", new NamedArrayList.Predicate>() {
- @Override
- public boolean test(SCMTraitDescriptor> scmTraitDescriptor) {
- return scmTraitDescriptor instanceof SCMNavigatorTraitDescriptor;
- }
- }, true, result);
- NamedArrayList.select(all, "Within project",
- NamedArrayList.anyOf(NamedArrayList.withAnnotation(Discovery.class),
+ NamedArrayList.select(
+ all,
+ "Projects",
+ new NamedArrayList.Predicate>() {
+ @Override
+ public boolean test(SCMTraitDescriptor> scmTraitDescriptor) {
+ return scmTraitDescriptor instanceof SCMNavigatorTraitDescriptor;
+ }
+ },
+ true,
+ result);
+ NamedArrayList.select(
+ all,
+ "Within project",
+ NamedArrayList.anyOf(
+ NamedArrayList.withAnnotation(Discovery.class),
NamedArrayList.withAnnotation(Selection.class)),
- true, result);
+ true,
+ result);
NamedArrayList.select(all, "Additional", null, true, result);
return result;
}
@@ -898,8 +968,10 @@ public List getTraitsDefaults() {
return Arrays.asList( // TODO finalize
new BranchDiscoveryTrait(true, false),
new OriginMergeRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.MERGE)),
- new ForkMergeRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.MERGE),
- new ForkMergeRequestDiscoveryTrait.TrustPermission(), false),
+ new ForkMergeRequestDiscoveryTrait(
+ EnumSet.of(ChangeRequestCheckoutStrategy.MERGE),
+ new ForkMergeRequestDiscoveryTrait.TrustPermission(),
+ false),
new WebhookListenerBuildConditionsTrait());
}
@@ -907,13 +979,16 @@ public List getTraitsDefaults() {
@Override
protected SCMHeadCategory[] createCategories() {
return new SCMHeadCategory[] {
- new UncategorizedSCMHeadCategory(Messages._GitLabSCMSource_UncategorizedCategory()),
- new ChangeRequestSCMHeadCategory(Messages._GitLabSCMSource_ChangeRequestCategory()),
- new TagSCMHeadCategory(Messages._GitLabSCMSource_TagCategory()) };
+ new UncategorizedSCMHeadCategory(Messages._GitLabSCMSource_UncategorizedCategory()),
+ new ChangeRequestSCMHeadCategory(Messages._GitLabSCMSource_ChangeRequestCategory()),
+ new TagSCMHeadCategory(Messages._GitLabSCMSource_TagCategory())
+ };
}
}
- @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "Known to be null during deserialization")
+ @SuppressFBWarnings(
+ value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
+ justification = "Known to be null during deserialization")
private Object readResolve() {
if (mergeRequestMetadataCache == null) {
mergeRequestMetadataCache = new ConcurrentHashMap<>();
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceBuilder.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceBuilder.java
index 2410699c..6878152f 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceBuilder.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceBuilder.java
@@ -4,25 +4,33 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import jenkins.scm.api.trait.SCMSourceBuilder;
-public class GitLabSCMSourceBuilder extends
- SCMSourceBuilder {
+public class GitLabSCMSourceBuilder extends SCMSourceBuilder {
@CheckForNull
private final String id;
+
@CheckForNull
private final String serverName;
+
@CheckForNull
private final String credentialsId;
+
@NonNull
private final String projectOwner;
+
@NonNull
private final String projectPath;
+
@NonNull
private final String projectName;
- public GitLabSCMSourceBuilder(@CheckForNull String id, @CheckForNull String serverName,
- @CheckForNull String credentialsId, @NonNull String projectOwner,
- @NonNull String projectPath, @NonNull String projectName) {
+ public GitLabSCMSourceBuilder(
+ @CheckForNull String id,
+ @CheckForNull String serverName,
+ @CheckForNull String credentialsId,
+ @NonNull String projectOwner,
+ @NonNull String projectPath,
+ @NonNull String projectName) {
super(GitLabSCMSource.class, projectName);
this.id = id;
this.serverName = serverName;
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java
index 38824a50..9e92aa9d 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java
@@ -12,8 +12,7 @@
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import jenkins.scm.api.trait.SCMSourceContext;
-public class GitLabSCMSourceContext
- extends SCMSourceContext {
+public class GitLabSCMSourceContext extends SCMSourceContext {
private boolean wantBranches;
private boolean wantTags;
@@ -21,13 +20,14 @@ public class GitLabSCMSourceContext
private boolean wantForkMRs;
@NonNull
- private Set originMRStrategies = EnumSet
- .noneOf(ChangeRequestCheckoutStrategy.class);
+ private Set originMRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
+
@NonNull
- private Set forkMRStrategies = EnumSet
- .noneOf(ChangeRequestCheckoutStrategy.class);
+ private Set forkMRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
+
@NonNull
private GitLabHookRegistration webhookRegistration = GitLabHookRegistration.SYSTEM;
+
@NonNull
private GitLabHookRegistration systemhookRegistration = GitLabHookRegistration.SYSTEM;
@@ -69,8 +69,7 @@ public class GitLabSCMSourceContext
private boolean alwaysIgnoreMRWorkInProgress = false;
- public GitLabSCMSourceContext(@CheckForNull SCMSourceCriteria criteria,
- @NonNull SCMHeadObserver observer) {
+ public GitLabSCMSourceContext(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer) {
super(criteria, observer);
}
@@ -215,15 +214,13 @@ public GitLabSCMSourceContext wantForkMRs(boolean include) {
}
@NonNull
- public GitLabSCMSourceContext withOriginMRStrategies(
- Set strategies) {
+ public GitLabSCMSourceContext withOriginMRStrategies(Set strategies) {
originMRStrategies.addAll(strategies);
return this;
}
@NonNull
- public GitLabSCMSourceContext withForkMRStrategies(
- Set strategies) {
+ public GitLabSCMSourceContext withForkMRStrategies(Set strategies) {
forkMRStrategies.addAll(strategies);
return this;
}
@@ -304,8 +301,7 @@ public final GitLabSCMSourceContext withBuildStatusNameOverwrite(final Boolean b
@NonNull
@Override
- public GitLabSCMSourceRequest newRequest(@NonNull SCMSource source,
- @CheckForNull TaskListener listener) {
+ public GitLabSCMSourceRequest newRequest(@NonNull SCMSource source, @CheckForNull TaskListener listener) {
return new GitLabSCMSourceRequest(source, this, listener);
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceRequest.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceRequest.java
index d656f196..0cf3c658 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceRequest.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceRequest.java
@@ -115,8 +115,7 @@ public class GitLabSCMSourceRequest extends SCMSourceRequest {
* @param context the context.
* @param listener the listener.
*/
- GitLabSCMSourceRequest(SCMSource source, GitLabSCMSourceContext context,
- TaskListener listener) {
+ GitLabSCMSourceRequest(SCMSource source, GitLabSCMSourceContext context, TaskListener listener) {
super(source, context, listener);
fetchBranches = context.wantBranches();
fetchTags = context.wantTags();
@@ -238,11 +237,9 @@ public final Set getForkMRStrategies() {
@NonNull
public final Set getMRStrategies(boolean fork) {
if (fork) {
- return fetchForkMRs ? getForkMRStrategies()
- : Collections.emptySet();
+ return fetchForkMRs ? getForkMRStrategies() : Collections.emptySet();
}
- return fetchOriginMRs ? getOriginMRStrategies()
- : Collections.emptySet();
+ return fetchOriginMRs ? getOriginMRStrategies() : Collections.emptySet();
}
/**
@@ -257,7 +254,7 @@ public final Set getMRStrategies(boolean fork) {
*/
public final Map> getMRStrategies() {
Map> result = new HashMap<>();
- for (Boolean fork : new Boolean[] { Boolean.TRUE, Boolean.FALSE }) {
+ for (Boolean fork : new Boolean[] {Boolean.TRUE, Boolean.FALSE}) {
result.put(fork, getMRStrategies(fork));
}
return result;
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSkipNotificationsTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSkipNotificationsTrait.java
index 49c46554..243a5357 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSkipNotificationsTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSkipNotificationsTrait.java
@@ -16,7 +16,7 @@ public class GitLabSkipNotificationsTrait extends SCMSourceTrait {
*/
@DataBoundConstructor
public GitLabSkipNotificationsTrait() {
- //empty
+ // empty
}
@Override
@@ -49,7 +49,5 @@ public Class extends SCMSourceContext> getContextClass() {
public Class extends SCMSource> getSourceClass() {
return GitLabSCMSource.class;
}
-
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookAction.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookAction.java
index b8a844ee..f68046d3 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookAction.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookAction.java
@@ -43,7 +43,7 @@ public String getUrlName() {
@Override
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain)
- throws IOException, ServletException {
+ throws IOException, ServletException {
String pathInfo = req.getPathInfo();
if (pathInfo != null && pathInfo.startsWith("/" + getUrlName() + "/post")) {
chain.doFilter(req, resp);
@@ -54,26 +54,24 @@ public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterC
public HttpResponse doPost(StaplerRequest request) throws GitLabApiException {
if (!request.getMethod().equals("POST")) {
- return HttpResponses
- .error(HttpServletResponse.SC_BAD_REQUEST,
- "Only POST requests are supported, this was a " + request.getMethod()
- + " request");
+ return HttpResponses.error(
+ HttpServletResponse.SC_BAD_REQUEST,
+ "Only POST requests are supported, this was a " + request.getMethod() + " request");
}
if (!"application/json".equals(request.getContentType())) {
- return HttpResponses
- .error(HttpServletResponse.SC_BAD_REQUEST,
- "Only application/json content is supported, this was " + request
- .getContentType());
+ return HttpResponses.error(
+ HttpServletResponse.SC_BAD_REQUEST,
+ "Only application/json content is supported, this was " + request.getContentType());
}
String type = request.getHeader("X-Gitlab-Event");
if (StringUtils.isBlank(type)) {
- return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST,
- "Expecting a GitLab event, missing expected X-Gitlab-Event header");
+ return HttpResponses.error(
+ HttpServletResponse.SC_BAD_REQUEST,
+ "Expecting a GitLab event, missing expected X-Gitlab-Event header");
}
String secretToken = request.getHeader("X-Gitlab-Token");
- if(!isValidToken(secretToken)) {
- return HttpResponses.error(HttpServletResponse.SC_UNAUTHORIZED,
- "Expecting a valid secret token");
+ if (!isValidToken(secretToken)) {
+ return HttpResponses.error(HttpServletResponse.SC_UNAUTHORIZED, "Expecting a valid secret token");
}
String origin = SCMEvent.originOf(request);
SystemHookManager systemHookManager = new SystemHookManager();
@@ -85,8 +83,8 @@ public HttpResponse doPost(StaplerRequest request) throws GitLabApiException {
private boolean isValidToken(String secretToken) {
try {
List servers = GitLabServers.get().getServers();
- for(GitLabServer server: servers) {
- if(server.getSecretTokenAsPlainText().equals(secretToken)) {
+ for (GitLabServer server : servers) {
+ if (server.getSecretTokenAsPlainText().equals(secretToken)) {
return true;
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookListener.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookListener.java
index ff9e0326..0f6bd2bd 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookListener.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSystemHookListener.java
@@ -26,12 +26,15 @@ public void onProjectEvent(ProjectSystemHookEvent projectSystemHookEvent) {
case ProjectSystemHookEvent.PROJECT_CREATE_EVENT:
case ProjectSystemHookEvent.PROJECT_DESTROY_EVENT:
case ProjectSystemHookEvent.PROJECT_UPDATE_EVENT:
- GitLabProjectSCMEvent trigger = new GitLabProjectSCMEvent(projectSystemHookEvent,
- origin);
+ GitLabProjectSCMEvent trigger = new GitLabProjectSCMEvent(projectSystemHookEvent, origin);
SCMSourceEvent.fireLater(trigger, 5, TimeUnit.SECONDS);
break;
default:
- LOGGER.log(Level.INFO, String.format("unsupported System hook event: %s", projectSystemHookEvent.getEventName().toString()));
+ LOGGER.log(
+ Level.INFO,
+ String.format(
+ "unsupported System hook event: %s",
+ projectSystemHookEvent.getEventName().toString()));
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabTagPushSCMEvent.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabTagPushSCMEvent.java
index 29d9edf4..f6265d7b 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabTagPushSCMEvent.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabTagPushSCMEvent.java
@@ -1,5 +1,7 @@
package io.jenkins.plugins.gitlabbranchsource;
+import static jenkins.scm.api.SCMEvent.Type.CREATED;
+
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Collections;
import java.util.Map;
@@ -11,8 +13,6 @@
import org.eclipse.jgit.lib.Constants;
import org.gitlab4j.api.webhook.TagPushEvent;
-import static jenkins.scm.api.SCMEvent.Type.CREATED;
-
public class GitLabTagPushSCMEvent extends AbstractGitLabSCMHeadEvent {
public GitLabTagPushSCMEvent(TagPushEvent tagPushEvent, String origin) {
@@ -43,14 +43,15 @@ public String getSourceName() {
public String descriptionFor(SCMSource source) {
String ref = getPayload().getRef();
ref = ref.startsWith(Constants.R_TAGS) ? ref.substring(Constants.R_TAGS.length()) : ref;
- return "Tag push event of tag " + ref + " in project " + getPayload().getProject()
- .getPathWithNamespace();
+ return "Tag push event of tag " + ref + " in project "
+ + getPayload().getProject().getPathWithNamespace();
}
@Override
public boolean isMatch(@NonNull GitLabSCMNavigator navigator) {
- return navigator.getNavigatorProjects()
- .contains(getPayload().getProject().getPathWithNamespace());
+ return navigator
+ .getNavigatorProjects()
+ .contains(getPayload().getProject().getPathWithNamespace());
}
@Override
@@ -69,14 +70,12 @@ public Map headsFor(GitLabSCMSource source) {
}
GitLabTagSCMHead h = new GitLabTagSCMHead(ref, time);
String hash = getPayload().getCheckoutSha();
- return Collections.singletonMap(h,
- (getType() == CREATED)
- ? new GitTagSCMRevision(h, hash) : null);
+ return Collections.singletonMap(
+ h, (getType() == CREATED) ? new GitTagSCMRevision(h, hash) : null);
}
@Override
public GitLabWebHookCause getCause() {
return new GitLabWebHookCause().fromTag(getPayload());
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookAction.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookAction.java
index 45529ba8..d5dbc479 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookAction.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookAction.java
@@ -43,7 +43,7 @@ public String getUrlName() {
@Override
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain)
- throws IOException, ServletException {
+ throws IOException, ServletException {
String pathInfo = req.getPathInfo();
if (pathInfo != null && pathInfo.startsWith("/" + getUrlName() + "/post")) {
chain.doFilter(req, resp);
@@ -54,26 +54,24 @@ public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterC
public HttpResponse doPost(StaplerRequest request) throws IOException, GitLabApiException {
if (!request.getMethod().equals("POST")) {
- return HttpResponses
- .error(HttpServletResponse.SC_BAD_REQUEST,
- "Only POST requests are supported, this was a " + request.getMethod()
- + " request");
+ return HttpResponses.error(
+ HttpServletResponse.SC_BAD_REQUEST,
+ "Only POST requests are supported, this was a " + request.getMethod() + " request");
}
if (!"application/json".equals(request.getContentType())) {
- return HttpResponses
- .error(HttpServletResponse.SC_BAD_REQUEST,
- "Only application/json content is supported, this was " + request
- .getContentType());
+ return HttpResponses.error(
+ HttpServletResponse.SC_BAD_REQUEST,
+ "Only application/json content is supported, this was " + request.getContentType());
}
String type = request.getHeader("X-Gitlab-Event");
if (StringUtils.isBlank(type)) {
- return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST,
- "Expecting a GitLab event, missing expected X-Gitlab-Event header");
+ return HttpResponses.error(
+ HttpServletResponse.SC_BAD_REQUEST,
+ "Expecting a GitLab event, missing expected X-Gitlab-Event header");
}
String secretToken = request.getHeader("X-Gitlab-Token");
- if(!isValidToken(secretToken)) {
- return HttpResponses.error(HttpServletResponse.SC_UNAUTHORIZED,
- "Expecting a valid secret token");
+ if (!isValidToken(secretToken)) {
+ return HttpResponses.error(HttpServletResponse.SC_UNAUTHORIZED, "Expecting a valid secret token");
}
String origin = SCMEvent.originOf(request);
WebHookManager webHookManager = new WebHookManager();
@@ -85,8 +83,9 @@ public HttpResponse doPost(StaplerRequest request) throws IOException, GitLabApi
private boolean isValidToken(String secretToken) {
try {
List servers = GitLabServers.get().getServers();
- for(GitLabServer server: servers) {
- if(server.getSecretTokenAsPlainText().equals(secretToken) || (server.getSecretTokenAsPlainText().isEmpty() && secretToken == null)) {
+ for (GitLabServer server : servers) {
+ if (server.getSecretTokenAsPlainText().equals(secretToken)
+ || (server.getSecretTokenAsPlainText().isEmpty() && secretToken == null)) {
return true;
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookCause.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookCause.java
index 4e9db0ad..d2da69bf 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookCause.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookCause.java
@@ -38,11 +38,10 @@ public GitLabWebHookCause fromMergeRequest(MergeRequestEvent mergeRequestEvent)
String id = String.valueOf(objectAttributes.getIid());
String sourceNameSpace = objectAttributes.getSource().getNamespace();
String targetNameSpace = objectAttributes.getTarget().getNamespace();
- String nameSpace =
- StringUtils.equals(sourceNameSpace, targetNameSpace) ? "" : sourceNameSpace + "/";
+ String nameSpace = StringUtils.equals(sourceNameSpace, targetNameSpace) ? "" : sourceNameSpace + "/";
String source = String.format("%s%s", nameSpace, objectAttributes.getSourceBranch());
description = Messages.GitLabWebHookCause_ShortDescription_MergeRequestHook(
- id, source, objectAttributes.getTargetBranch());
+ id, source, objectAttributes.getTargetBranch());
this.gitLabMergeRequestCauseData = new GitLabMergeRequestCauseData(mergeRequestEvent);
return this;
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookListener.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookListener.java
index ebcad673..d325b68e 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookListener.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookListener.java
@@ -69,9 +69,7 @@ private void fireTrigger(final SCMHeadEvent> trigger, final String projectUrl)
private boolean findImmediateHookTrigger(@Nullable final GitLabServer projectServer) {
if (projectServer == null) {
- LOGGER.log(
- Level.WARNING,
- "Falling back to no immediate trigger");
+ LOGGER.log(Level.WARNING, "Falling back to no immediate trigger");
return false;
}
@@ -80,9 +78,7 @@ private boolean findImmediateHookTrigger(@Nullable final GitLabServer projectSer
private long findTriggerDelay(@Nullable final GitLabServer projectServer) {
if (projectServer == null) {
- LOGGER.log(
- Level.WARNING,
- "Falling back to default trigger delay equal GitLab caching timeout");
+ LOGGER.log(Level.WARNING, "Falling back to default trigger delay equal GitLab caching timeout");
return GITLAB_CACHING_TIMEOUT;
}
@@ -100,8 +96,7 @@ private GitLabServer findProjectServer(final String projectUrl) {
return server;
}
}
- LOGGER.log(Level.WARNING,
- String.format("No GitLab server for project URL: %s", projectUrl));
+ LOGGER.log(Level.WARNING, String.format("No GitLab server for project URL: %s", projectUrl));
return null;
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/HookRegistrationTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/HookRegistrationTrait.java
index 366f3d11..7f93fcc8 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/HookRegistrationTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/HookRegistrationTrait.java
@@ -38,8 +38,7 @@ public class HookRegistrationTrait extends SCMSourceTrait {
*/
@DataBoundConstructor
public HookRegistrationTrait(@NonNull String webHookMode, @NonNull String systemHookMode) {
- this(GitLabHookRegistration.valueOf(webHookMode),
- GitLabHookRegistration.valueOf(systemHookMode));
+ this(GitLabHookRegistration.valueOf(webHookMode), GitLabHookRegistration.valueOf(systemHookMode));
}
/**
@@ -48,8 +47,8 @@ public HookRegistrationTrait(@NonNull String webHookMode, @NonNull String system
* @param webHookMode the web hook mode of registration to apply.
* @param systemHookMode the system hook mode of registration to apply.
*/
- public HookRegistrationTrait(@NonNull GitLabHookRegistration webHookMode,
- @NonNull GitLabHookRegistration systemHookMode) {
+ public HookRegistrationTrait(
+ @NonNull GitLabHookRegistration webHookMode, @NonNull GitLabHookRegistration systemHookMode) {
this.webHookMode = webHookMode;
this.systemHookMode = systemHookMode;
}
@@ -74,7 +73,6 @@ public final GitLabHookRegistration getSystemHookMode() {
return systemHookMode;
}
-
/**
* {@inheritDoc}
*/
@@ -141,14 +139,10 @@ public ListBoxModel doFillSystemHookModeItems() {
private ListBoxModel getOptions(boolean isWebHook) {
ListBoxModel result = new ListBoxModel();
String pronoun = isWebHook ? "Web Hook" : "System Hook";
- result.add(Messages.HookRegistrationTrait_disable(pronoun),
- GitLabHookRegistration.DISABLE.toString());
- result.add(Messages.HookRegistrationTrait_useSystem(pronoun),
- GitLabHookRegistration.SYSTEM.toString());
- result.add(Messages.HookRegistrationTrait_useItem(pronoun),
- GitLabHookRegistration.ITEM.toString());
+ result.add(Messages.HookRegistrationTrait_disable(pronoun), GitLabHookRegistration.DISABLE.toString());
+ result.add(Messages.HookRegistrationTrait_useSystem(pronoun), GitLabHookRegistration.SYSTEM.toString());
+ result.add(Messages.HookRegistrationTrait_useItem(pronoun), GitLabHookRegistration.ITEM.toString());
return result;
}
-
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/LogCommentTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/LogCommentTrait.java
index ad9cac0d..2d1d9df4 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/LogCommentTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/LogCommentTrait.java
@@ -92,7 +92,5 @@ public Class extends SCMSourceContext> getContextClass() {
public Class extends SCMSource> getSourceClass() {
return GitLabSCMSource.class;
}
-
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMHead.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMHead.java
index 316a97cb..23265562 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMHead.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMHead.java
@@ -30,9 +30,16 @@ public class MergeRequestSCMHead extends SCMHead implements ChangeRequestSCMHead
* @param originName the name of the branch in the origin project
* @param title the title of the merge request
*/
- public MergeRequestSCMHead(@NonNull String name, long id, BranchSCMHead target,
- ChangeRequestCheckoutStrategy strategy, SCMHeadOrigin origin, String originOwner,
- String originProjectPath, String originName, String title) {
+ public MergeRequestSCMHead(
+ @NonNull String name,
+ long id,
+ BranchSCMHead target,
+ ChangeRequestCheckoutStrategy strategy,
+ SCMHeadOrigin origin,
+ String originOwner,
+ String originProjectPath,
+ String originName,
+ String title) {
super(name);
this.id = id;
this.target = target;
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMRevision.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMRevision.java
index cfbabbb6..abd17d4b 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMRevision.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeRequestSCMRevision.java
@@ -7,10 +7,8 @@
public class MergeRequestSCMRevision extends ChangeRequestSCMRevision {
- private final @NonNull
- String baseHash;
- private final @NonNull
- String headHash;
+ private final @NonNull String baseHash;
+ private final @NonNull String headHash;
private BranchSCMRevision origin;
/**
@@ -22,9 +20,7 @@ public class MergeRequestSCMRevision extends ChangeRequestSCMRevision revision) {
return (revision instanceof MergeRequestSCMRevision)
- && origin.equals(((MergeRequestSCMRevision) revision).getOrigin());
+ && origin.equals(((MergeRequestSCMRevision) revision).getOrigin());
}
@Override
@@ -60,7 +56,6 @@ protected int _hashCode() {
@Override
public String toString() {
- return (isMerge() ? ((BranchSCMRevision) getTarget()).getHash() + "+" : "") + origin
- .getHash();
+ return (isMerge() ? ((BranchSCMRevision) getTarget()).getHash() + "+" : "") + origin.getHash();
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeWithGitSCMExtension.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeWithGitSCMExtension.java
index 74f7d85d..ea18596a 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeWithGitSCMExtension.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/MergeWithGitSCMExtension.java
@@ -24,5 +24,4 @@ public class MergeWithGitSCMExtension extends jenkins.plugins.git.MergeWithGitSC
private Object readResolve() throws ObjectStreamException {
return new jenkins.plugins.git.MergeWithGitSCMExtension(getBaseName(), getBaseHash());
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/OriginMergeRequestDiscoveryTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/OriginMergeRequestDiscoveryTrait.java
index d8f74fca..6c3bcca0 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/OriginMergeRequestDiscoveryTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/OriginMergeRequestDiscoveryTrait.java
@@ -52,7 +52,7 @@ public OriginMergeRequestDiscoveryTrait(int strategyId) {
*/
public OriginMergeRequestDiscoveryTrait(Set strategies) {
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
- + (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0));
+ + (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0));
}
/**
@@ -77,8 +77,7 @@ public Set getStrategies() {
case 2:
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD);
case 3:
- return EnumSet
- .of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
+ return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
default:
return EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
}
@@ -157,14 +156,13 @@ public ListBoxModel doFillStrategyIdItems() {
* A {@link SCMHeadAuthority} that trusts origin merge requests
*/
public static class OriginChangeRequestSCMHeadAuthority
- extends SCMHeadAuthority {
+ extends SCMHeadAuthority {
/**
* {@inheritDoc}
*/
@Override
- protected boolean checkTrusted(@NonNull SCMSourceRequest request,
- @NonNull ChangeRequestSCMHead2 head) {
+ protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull ChangeRequestSCMHead2 head) {
return SCMHeadOrigin.DEFAULT.equals(head.getOrigin());
}
@@ -178,8 +176,7 @@ public static class DescriptorImpl extends SCMHeadAuthorityDescriptor {
* {@inheritDoc}
*/
@Override
- public boolean isApplicableToOrigin(
- @NonNull Class extends SCMHeadOrigin> originClass) {
+ public boolean isApplicableToOrigin(@NonNull Class extends SCMHeadOrigin> originClass) {
return SCMHeadOrigin.Default.class.isAssignableFrom(originClass);
}
@@ -191,9 +188,6 @@ public boolean isApplicableToOrigin(
public String getDisplayName() {
return Messages.OriginMergeRequestDiscoveryTrait_authorityDisplayName();
}
-
-
}
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait.java
index fb530cc6..e7e013ff 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait.java
@@ -80,9 +80,10 @@ public Class extends SCM> getScmClass() {
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler form binding
- public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
- @QueryParameter String serverUrl,
- @QueryParameter String credentialsId) {
+ public ListBoxModel doFillCredentialsIdItems(
+ @CheckForNull @AncestorInPath Item context,
+ @QueryParameter String serverUrl,
+ @QueryParameter String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
if (context == null) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
@@ -92,7 +93,7 @@ public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item
}
} else {
if (!context.hasPermission(Item.EXTENDED_READ)
- && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
+ && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
// must be able to read the configuration or use the item credentials if you want the list
result.includeCurrentValue(credentialsId);
return result;
@@ -100,14 +101,11 @@ public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item
}
result.includeEmptyValue();
result.includeMatchingAs(
- context instanceof Queue.Task
- ? ((Queue.Task) context).getDefaultAuthentication()
- : ACL.SYSTEM,
- context,
- StandardUsernameCredentials.class,
- URIRequirementBuilder.fromUri(serverUrl).build(),
- CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
- );
+ context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM,
+ context,
+ StandardUsernameCredentials.class,
+ URIRequirementBuilder.fromUri(serverUrl).build(),
+ CredentialsMatchers.instanceOf(SSHUserPrivateKey.class));
return result;
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/TagDiscoveryTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/TagDiscoveryTrait.java
index cc784092..412954b6 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/TagDiscoveryTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/TagDiscoveryTrait.java
@@ -26,9 +26,7 @@ public class TagDiscoveryTrait extends SCMSourceTrait {
* Constructor for stapler.
*/
@DataBoundConstructor
- public TagDiscoveryTrait() {
-
- }
+ public TagDiscoveryTrait() {}
/**
* {@inheritDoc}
@@ -80,21 +78,19 @@ public Class extends SCMSourceContext> getContextClass() {
public Class extends SCMSource> getSourceClass() {
return GitLabSCMSource.class;
}
-
}
/**
* Trusts tags from the origin project.
*/
- public static class TagSCMHeadAuthority extends
- SCMHeadAuthority {
+ public static class TagSCMHeadAuthority
+ extends SCMHeadAuthority {
/**
* {@inheritDoc}
*/
@Override
- protected boolean checkTrusted(@NonNull SCMSourceRequest request,
- @NonNull GitLabTagSCMHead head) {
+ protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull GitLabTagSCMHead head) {
return true;
}
@@ -117,11 +113,9 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
- public boolean isApplicableToOrigin(
- @NonNull Class extends SCMHeadOrigin> originClass) {
+ public boolean isApplicableToOrigin(@NonNull Class extends SCMHeadOrigin> originClass) {
return SCMHeadOrigin.Default.class.isAssignableFrom(originClass);
}
}
}
}
-
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/TriggerMRCommentTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/TriggerMRCommentTrait.java
index 1d7c1845..0baefdfe 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/TriggerMRCommentTrait.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/TriggerMRCommentTrait.java
@@ -88,6 +88,5 @@ public Class extends SCMSourceContext> getContextClass() {
public Class extends SCMSource> getSourceClass() {
return GitLabSCMSource.class;
}
-
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabAvatarCache.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabAvatarCache.java
index df798305..5b1778de 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabAvatarCache.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabAvatarCache.java
@@ -1,5 +1,10 @@
package io.jenkins.plugins.gitlabbranchsource.helpers;
+import static java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION;
+import static java.awt.RenderingHints.KEY_INTERPOLATION;
+import static java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY;
+import static java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC;
+
import com.damnhandy.uri.template.UriTemplate;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -47,11 +52,6 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
-import static java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION;
-import static java.awt.RenderingHints.KEY_INTERPOLATION;
-import static java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY;
-import static java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC;
-
/**
* An avatar cache that will serve URLs that have been recently registered
* through {@link #buildUrl(String, String)}
@@ -69,8 +69,12 @@ public class GitLabAvatarCache implements UnprotectedRootAction {
/**
* A background thread pool to refresh images.
*/
- private final ExecutorService service = new ThreadPoolExecutor(0, 4,
- 1L, TimeUnit.SECONDS, new SynchronousQueue(),
+ private final ExecutorService service = new ThreadPoolExecutor(
+ 0,
+ 4,
+ 1L,
+ TimeUnit.SECONDS,
+ new SynchronousQueue(),
new NamingThreadFactory(new DaemonThreadFactory(), getClass().getName()));
/**
* The lock to ensure we prevent concurrent requests for the same URL.
@@ -85,8 +89,7 @@ public class GitLabAvatarCache implements UnprotectedRootAction {
/**
* Constructor.
*/
- public GitLabAvatarCache() {
- }
+ public GitLabAvatarCache() {}
/**
* Builds the URL for the cached avatar image of the required size.
@@ -294,11 +297,7 @@ public HttpResponse doDynamic(StaplerRequest req, @QueryParameter String size) {
// serve a temporary avatar until we get the remote one, no caching as we could
// have the real deal
// real soon now
- return new ImageResponse(
- generateAvatar(avatar.url, targetSize),
- true,
- -1L,
- "no-cache, public");
+ return new ImageResponse(generateAvatar(avatar.url, targetSize), true, -1L, "no-cache, public");
}
long since = req.getDateHeader("If-Modified-Since");
if (avatar.lastModified <= since) {
@@ -314,11 +313,7 @@ public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object nod
}
if (avatar.image == null) {
// we can retry in an hour
- return new ImageResponse(
- generateAvatar(avatar.url, targetSize),
- true,
- -1L,
- "max-age=3600, public");
+ return new ImageResponse(generateAvatar(avatar.url, targetSize), true, -1L, "max-age=3600, public");
}
BufferedImage image = avatar.image;
@@ -436,7 +431,6 @@ public synchronized boolean pending() {
} catch (InterruptedException | ExecutionException e) {
// ignore
}
-
}
return true;
}
@@ -456,7 +450,6 @@ public void touch() {
public boolean isUnused() {
return lastAccessed > 0L && System.currentTimeMillis() - lastAccessed > TimeUnit.HOURS.toMillis(2);
}
-
}
private static class ImageResponse implements HttpResponse {
@@ -493,7 +486,6 @@ public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object nod
rsp.setContentLength(bytes.length);
rsp.getOutputStream().write(bytes);
}
-
}
private static class FetchImage implements Callable {
@@ -536,8 +528,9 @@ public CacheEntry call() throws Exception {
} finally {
long end = System.nanoTime();
long duration = TimeUnit.NANOSECONDS.toMillis(end - start);
- LOGGER.log(duration > 250 ? Level.INFO : Level.FINE, "Avatar lookup of {0} took {1}ms",
- new Object[] { url, duration });
+ LOGGER.log(duration > 250 ? Level.INFO : Level.FINE, "Avatar lookup of {0} took {1}ms", new Object[] {
+ url, duration
+ });
}
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabBrowser.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabBrowser.java
index 4cd1e936..c4629aea 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabBrowser.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabBrowser.java
@@ -1,5 +1,9 @@
package io.jenkins.plugins.gitlabbranchsource.helpers;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.commitUriTemplate;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getUriTemplateFromServer;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.splitPath;
+
import com.damnhandy.uri.template.UriTemplateBuilder;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
@@ -14,10 +18,6 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.commitUriTemplate;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getUriTemplateFromServer;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.splitPath;
-
public class GitLabBrowser extends GitRepositoryBrowser {
@DataBoundConstructor
@@ -31,52 +31,47 @@ public String getProjectUrl() {
@Override
public URL getChangeSetLink(GitChangeSet changeSet) throws IOException {
- return new URL(
- commitUriTemplate(getProjectUrl())
+ return new URL(commitUriTemplate(getProjectUrl())
.set("hash", changeSet.getId())
- .expand()
- );
+ .expand());
}
@Override
public URL getDiffLink(GitChangeSet.Path path) throws IOException {
- if (path.getEditType() != EditType.EDIT || path.getSrc() == null || path.getDst() == null
- || path.getChangeSet().getParentCommit() == null) {
+ if (path.getEditType() != EditType.EDIT
+ || path.getSrc() == null
+ || path.getDst() == null
+ || path.getChangeSet().getParentCommit() == null) {
return null;
}
return diffLink(path);
}
-
@Override
public URL getFileLink(GitChangeSet.Path path) throws IOException {
if (path.getEditType().equals(EditType.DELETE)) {
return diffLink(path);
} else {
- return new URL(
- getUriTemplateFromServer(getProjectUrl())
+ return new URL(getUriTemplateFromServer(getProjectUrl())
.literal("/blob")
.path(UriTemplateBuilder.var("changeSet"))
.path(UriTemplateBuilder.var("path", true))
.build()
.set("changeSet", path.getChangeSet().getId())
.set("path", splitPath(path.getPath()))
- .expand()
- );
+ .expand());
}
}
private URL diffLink(GitChangeSet.Path path) throws IOException {
- return new URL(
- getUriTemplateFromServer(getProjectUrl())
+ return new URL(getUriTemplateFromServer(getProjectUrl())
.literal("/commit")
.path(UriTemplateBuilder.var("changeSet"))
.fragment(UriTemplateBuilder.var("diff"))
.build()
.set("changeSet", path.getChangeSet().getId())
.set("diff", "#diff-" + getIndexOfPath(path))
- .expand()
- );
+ .expand());
}
@Extension
@@ -88,10 +83,8 @@ public String getDisplayName() {
}
@Override
- public GitLabBrowser newInstance(StaplerRequest req, @NonNull JSONObject jsonObject)
- throws FormException {
+ public GitLabBrowser newInstance(StaplerRequest req, @NonNull JSONObject jsonObject) throws FormException {
return req.bindJSON(GitLabBrowser.class, jsonObject);
}
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabGroup.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabGroup.java
index 3aae2d49..fcf314f3 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabGroup.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabGroup.java
@@ -5,8 +5,7 @@ public class GitLabGroup extends GitLabOwner {
private String fullName;
private String description;
- public GitLabGroup(String name, String webUrl, String avatarUrl, Long id,
- String fullName, String description) {
+ public GitLabGroup(String name, String webUrl, String avatarUrl, Long id, String fullName, String description) {
super(name, webUrl, avatarUrl, id);
this.fullName = fullName;
this.description = description;
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabHelper.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabHelper.java
index a346d945..17ca5122 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabHelper.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabHelper.java
@@ -30,37 +30,37 @@ public static GitLabApi apiBuilder(AccessControlled context, String serverName)
}
return new GitLabApi(serverUrl, GitLabServer.EMPTY_TOKEN, null, getProxyConfig(serverUrl));
}
- throw new IllegalStateException(
- String.format("No server found with the name: %s", serverName));
+ throw new IllegalStateException(String.format("No server found with the name: %s", serverName));
}
- public static Map getProxyConfig (String serverUrl) {
+ public static Map getProxyConfig(String serverUrl) {
ProxyConfiguration proxyConfiguration = Jenkins.get().getProxy();
if (proxyConfiguration != null) {
- final URL url;
- try {
- url = new URL(serverUrl);
- } catch (MalformedURLException e) {
- // let it crash somewhere else
- return null;
- }
- if (!"http".equals(url.getProtocol()) && !"https".equals(url.getProtocol())) {
- // non-http(s) URL, proxy won't handle it
- return null;
- }
- List nonProxyHostPatterns = proxyConfiguration.getNoProxyHostPatterns();
- if (nonProxyHostPatterns.stream().anyMatch(p -> p.matcher(url.getHost()).matches())) {
- // target host is excluded by proxy configuration
- return null;
- }
+ final URL url;
+ try {
+ url = new URL(serverUrl);
+ } catch (MalformedURLException e) {
+ // let it crash somewhere else
+ return null;
+ }
+ if (!"http".equals(url.getProtocol()) && !"https".equals(url.getProtocol())) {
+ // non-http(s) URL, proxy won't handle it
+ return null;
+ }
+ List nonProxyHostPatterns = proxyConfiguration.getNoProxyHostPatterns();
+ if (nonProxyHostPatterns.stream()
+ .anyMatch(p -> p.matcher(url.getHost()).matches())) {
+ // target host is excluded by proxy configuration
+ return null;
+ }
if (proxyConfiguration.getUserName() != null && proxyConfiguration.getSecretPassword() != null) {
return ProxyClientConfig.createProxyClientConfig(
- "http://" + proxyConfiguration.getName() + ":" + proxyConfiguration.getPort(),
- proxyConfiguration.getUserName(),
- proxyConfiguration.getSecretPassword().getPlainText());
+ "http://" + proxyConfiguration.getName() + ":" + proxyConfiguration.getPort(),
+ proxyConfiguration.getUserName(),
+ proxyConfiguration.getSecretPassword().getPlainText());
}
return ProxyClientConfig.createProxyClientConfig(
- "http://" + proxyConfiguration.getName() + ":" + proxyConfiguration.getPort());
+ "http://" + proxyConfiguration.getName() + ":" + proxyConfiguration.getPort());
}
return null;
}
@@ -90,33 +90,34 @@ public static UriTemplateBuilder getUriTemplateFromServer(String server) {
}
public static UriTemplate projectUriTemplate(String serverNameOrUrl) {
- return getUriTemplateFromServer(serverNameOrUrl)
- .template("{/project*}").build();
+ return getUriTemplateFromServer(serverNameOrUrl).template("{/project*}").build();
}
public static UriTemplate branchUriTemplate(String serverNameOrUrl) {
return getUriTemplateFromServer(serverNameOrUrl)
- .template("{/project*}/tree/{branch*}").build();
+ .template("{/project*}/tree/{branch*}")
+ .build();
}
public static UriTemplate mergeRequestUriTemplate(String serverNameOrUrl) {
return getUriTemplateFromServer(serverNameOrUrl)
- .template("{/project*}/merge_requests/{iid}").build();
+ .template("{/project*}/merge_requests/{iid}")
+ .build();
}
public static UriTemplate tagUriTemplate(String serverNameOrUrl) {
return getUriTemplateFromServer(serverNameOrUrl)
- .template("{/project*}/tree/{tag*}").build();
+ .template("{/project*}/tree/{tag*}")
+ .build();
}
public static UriTemplate commitUriTemplate(String serverNameOrUrl) {
return getUriTemplateFromServer(serverNameOrUrl)
- .template("{/project*}/commit/{hash}")
- .build();
+ .template("{/project*}/commit/{hash}")
+ .build();
}
public static String[] splitPath(String path) {
return path.split(Operator.PATH.getSeparator());
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabIcons.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabIcons.java
index 6b46d55d..7e641e11 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabIcons.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabIcons.java
@@ -1,5 +1,11 @@
package io.jenkins.plugins.gitlabbranchsource.helpers;
+import static org.jenkins.ui.icon.Icon.ICON_LARGE_STYLE;
+import static org.jenkins.ui.icon.Icon.ICON_MEDIUM_STYLE;
+import static org.jenkins.ui.icon.Icon.ICON_SMALL_STYLE;
+import static org.jenkins.ui.icon.Icon.ICON_XLARGE_STYLE;
+import static org.jenkins.ui.icon.IconSet.icons;
+
import hudson.init.Initializer;
import java.util.NoSuchElementException;
import jenkins.model.Jenkins;
@@ -7,12 +13,6 @@
import org.jenkins.ui.icon.Icon;
import org.kohsuke.stapler.Stapler;
-import static org.jenkins.ui.icon.Icon.ICON_LARGE_STYLE;
-import static org.jenkins.ui.icon.Icon.ICON_MEDIUM_STYLE;
-import static org.jenkins.ui.icon.Icon.ICON_SMALL_STYLE;
-import static org.jenkins.ui.icon.Icon.ICON_XLARGE_STYLE;
-import static org.jenkins.ui.icon.IconSet.icons;
-
public final class GitLabIcons {
public static final String ICON_PROJECT = "gitlab-project";
@@ -23,7 +23,9 @@ public final class GitLabIcons {
public static final String ICON_TAG = "gitlab-tag";
private static final String ICON_PATH = "plugin/gitlab-branch-source/images/";
- private GitLabIcons() { /* no instances allowed */}
+ private GitLabIcons() {
+ /* no instances allowed */
+ }
@Initializer
public static void initialize() {
@@ -42,8 +44,7 @@ public static String iconFileName(String name, Size size) {
}
JellyContext ctx = new JellyContext();
- ctx.setVariable("resURL",
- Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
+ ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
return icon.getQualifiedUrl(ctx);
}
@@ -57,9 +58,7 @@ private static String classSpec(String name, Size size) {
private static void addIcon(String name) {
for (Size size : Size.values()) {
- icons.addIcon(
- new Icon(classSpec(name, size), ICON_PATH + "/" + name + ".svg",
- size.style));
+ icons.addIcon(new Icon(classSpec(name, size), ICON_PATH + "/" + name + ".svg", size.style));
}
}
@@ -89,4 +88,3 @@ public static Size byDimensions(String dimensions) {
}
}
}
-
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabLink.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabLink.java
index ae13e414..4f521cd8 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabLink.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabLink.java
@@ -1,5 +1,7 @@
package io.jenkins.plugins.gitlabbranchsource.helpers;
+import static org.apache.commons.lang.StringUtils.defaultIfBlank;
+
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.Action;
import jenkins.model.Jenkins;
@@ -9,8 +11,6 @@
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.stapler.Stapler;
-import static org.apache.commons.lang.StringUtils.defaultIfBlank;
-
/**
* Link to GitLab
*/
@@ -83,8 +83,7 @@ public String getIconFileName() {
Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " icon-md");
if (icon != null) {
JellyContext ctx = new JellyContext();
- ctx.setVariable("resURL",
- Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
+ ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
return icon.getQualifiedUrl(ctx);
}
return null;
@@ -130,10 +129,6 @@ public boolean equals(Object o) {
@Override
public String toString() {
- return "GitLabLink{" +
- "iconClassName='" + iconClassName + '\'' +
- ", url='" + url + '\'' +
- '}';
+ return "GitLabLink{" + "iconClassName='" + iconClassName + '\'' + ", url='" + url + '\'' + '}';
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabOwner.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabOwner.java
index 4f24b7a9..adb5ca26 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabOwner.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabOwner.java
@@ -24,8 +24,13 @@ public GitLabOwner(String name, String webUrl, String avatarUrl, Long id) {
public static GitLabOwner fetchOwner(GitLabApi gitLabApi, String projectOwner) {
try {
Group group = gitLabApi.getGroupApi().getGroup(projectOwner);
- return new GitLabGroup(group.getName(), group.getWebUrl(), group.getAvatarUrl(),
- group.getId(), group.getFullName(), group.getDescription());
+ return new GitLabGroup(
+ group.getName(),
+ group.getWebUrl(),
+ group.getAvatarUrl(),
+ group.getId(),
+ group.getFullName(),
+ group.getDescription());
} catch (GitLabApiException e) {
if (e.getHttpStatus() != 404) {
throw new IllegalStateException("Unable to fetch Group", e);
@@ -36,10 +41,9 @@ public static GitLabOwner fetchOwner(GitLabApi gitLabApi, String projectOwner) {
// If user is not found, null is returned
if (user == null) {
throw new IllegalStateException(
- String.format("Owner '%s' is neither a user/group/subgroup", projectOwner));
+ String.format("Owner '%s' is neither a user/group/subgroup", projectOwner));
}
- return new GitLabUser(user.getName(), user.getWebUrl(), user.getAvatarUrl(),
- user.getId());
+ return new GitLabUser(user.getName(), user.getWebUrl(), user.getAvatarUrl(), user.getId());
} catch (GitLabApiException e1) {
throw new IllegalStateException("Unable to fetch User", e1);
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifier.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifier.java
index fa2ac7d5..a4aee2e7 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifier.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifier.java
@@ -73,10 +73,8 @@ private static String getRootUrl(Run, ?> build) {
}
}
- private static GitLabSCMSourceContext getSourceContext(Run, ?> build,
- GitLabSCMSource source) {
- return new GitLabSCMSourceContext(null, SCMHeadObserver.none())
- .withTraits((source.getTraits()));
+ private static GitLabSCMSourceContext getSourceContext(Run, ?> build, GitLabSCMSource source) {
+ return new GitLabSCMSourceContext(null, SCMHeadObserver.none()).withTraits((source.getTraits()));
}
private static GitLabSCMSource getSource(Run, ?> build) {
@@ -87,29 +85,40 @@ private static GitLabSCMSource getSource(Run, ?> build) {
return null;
}
- private static String getStatusName(final GitLabSCMSourceContext sourceContext, final Run, ?> build,
- @NonNull EnvVars envVars, final SCMRevision revision) {
+ private static String getStatusName(
+ final GitLabSCMSourceContext sourceContext,
+ final Run, ?> build,
+ @NonNull EnvVars envVars,
+ final SCMRevision revision) {
return getStatusName(sourceContext, build.getFullDisplayName(), revision, envVars);
}
- private static String getStatusName(final GitLabSCMSourceContext sourceContext, final Job, ?> job,
- @NonNull EnvVars envVars, final SCMRevision revision) {
+ private static String getStatusName(
+ final GitLabSCMSourceContext sourceContext,
+ final Job, ?> job,
+ @NonNull EnvVars envVars,
+ final SCMRevision revision) {
return getStatusName(sourceContext, job.getFullDisplayName(), revision, envVars);
}
- static String getStatusName(final GitLabSCMSourceContext sourceContext, final String fullDisplayName,
- final SCMRevision revision, @NonNull EnvVars envVars) {
+ static String getStatusName(
+ final GitLabSCMSourceContext sourceContext,
+ final String fullDisplayName,
+ final SCMRevision revision,
+ @NonNull EnvVars envVars) {
final String type;
if (revision instanceof BranchSCMRevision) {
type = "branch";
} else if (revision instanceof MergeRequestSCMRevision) {
- type = getMrBuildName((MergeRequestSCMRevision)revision);
+ type = getMrBuildName((MergeRequestSCMRevision) revision);
} else if (revision instanceof GitTagSCMRevision) {
type = "tag";
} else {
type = "UNKNOWN";
- LOGGER.log(Level.WARNING, () -> "Unknown SCMRevision implementation "
- + revision.getClass().getName() + ", append" + type + " to status name");
+ LOGGER.log(
+ Level.WARNING,
+ () -> "Unknown SCMRevision implementation "
+ + revision.getClass().getName() + ", append" + type + " to status name");
}
String pipelinePrefix = sourceContext.getBuildStatusNameCustomPart().trim();
@@ -155,8 +164,8 @@ private static void logComment(Run, ?> build, TaskListener listener) {
}
String url = getRootUrl(build);
if (url.isEmpty()) {
- listener.getLogger().println(
- "Can not determine Jenkins root URL. Comments are disabled until a root URL is"
+ listener.getLogger()
+ .println("Can not determine Jenkins root URL. Comments are disabled until a root URL is"
+ " configured in Jenkins global configuration.");
return;
}
@@ -194,28 +203,28 @@ private static void logComment(Run, ?> build, TaskListener listener) {
final String hash;
if (revision instanceof BranchSCMRevision) {
hash = ((BranchSCMRevision) revision).getHash();
- gitLabApi.getCommitsApi().addComment(
- source.getProjectPath(),
- hash,
- symbol + buildName + note + suffix);
+ gitLabApi
+ .getCommitsApi()
+ .addComment(source.getProjectPath(), hash, symbol + buildName + note + suffix);
} else if (revision instanceof MergeRequestSCMRevision) {
MergeRequestSCMHead head = (MergeRequestSCMHead) revision.getHead();
- gitLabApi.getNotesApi().createMergeRequestNote(
- source.getProjectPath(),
- Long.valueOf(head.getId()),
- symbol + buildName + note + suffix);
+ gitLabApi
+ .getNotesApi()
+ .createMergeRequestNote(
+ source.getProjectPath(),
+ Long.valueOf(head.getId()),
+ symbol + buildName + note + suffix);
} else if (revision instanceof GitTagSCMRevision) {
hash = ((GitTagSCMRevision) revision).getHash();
- gitLabApi.getCommitsApi().addComment(
- source.getProjectPath(),
- hash,
- symbol + buildName + note + suffix);
+ gitLabApi
+ .getCommitsApi()
+ .addComment(source.getProjectPath(), hash, symbol + buildName + note + suffix);
}
} catch (IOException | InterruptedException e) {
- LOGGER.log(Level.INFO,
- "Could not send status notification for " + build.getFullDisplayName()
- + " to " + source
- .getServerName(),
+ LOGGER.log(
+ Level.INFO,
+ "Could not send status notification for " + build.getFullDisplayName() + " to "
+ + source.getServerName(),
e);
}
} catch (GitLabApiException e) {
@@ -230,18 +239,18 @@ static Long getSourceProjectId(Job job, GitLabApi gitLabApi, String projectPath)
LOGGER.log(Level.INFO, "Getting source project ID from MR");
Matcher m = MERGE_REQUEST_JOB_NAME_FORMAT.matcher(job.getName());
if (!m.matches()) {
- LOGGER.log(Level.WARNING,
- String.format("Job name does not match expected format: [%s], [%s]", job.getName(),
- MERGE_REQUEST_JOB_NAME_FORMAT.pattern()));
+ LOGGER.log(
+ Level.WARNING,
+ String.format(
+ "Job name does not match expected format: [%s], [%s]",
+ job.getName(), MERGE_REQUEST_JOB_NAME_FORMAT.pattern()));
return null;
}
Long mrId = Long.parseLong(m.group(1));
MergeRequest mr;
try {
- mr = gitLabApi.getMergeRequestApi().getMergeRequest(
- projectPath,
- mrId);
+ mr = gitLabApi.getMergeRequestApi().getMergeRequest(projectPath, mrId);
} catch (GitLabApiException e) {
if (!e.getMessage().contains(("Cannot transition status"))) {
LOGGER.log(Level.WARNING, String.format("Exception caught: %s", e.getMessage()));
@@ -268,9 +277,10 @@ private static void sendNotifications(Run, ?> build, TaskListener listener) {
}
String url = getRootUrl(build);
if (url.isEmpty()) {
- listener.getLogger().println(
- "Can not determine Jenkins root URL. Commit status notifications are disabled until a root URL is"
- + " configured in Jenkins global configuration.");
+ listener.getLogger()
+ .println(
+ "Can not determine Jenkins root URL. Commit status notifications are disabled until a root URL is"
+ + " configured in Jenkins global configuration.");
return;
}
Result result = build.getResult();
@@ -306,17 +316,20 @@ private static void sendNotifications(Run, ?> build, TaskListener listener) {
String hash;
if (revision instanceof BranchSCMRevision) {
listener.getLogger()
- .format("[GitLab Pipeline Status] Notifying branch build status: %s %s%n",
+ .format(
+ "[GitLab Pipeline Status] Notifying branch build status: %s %s%n",
status.getStatus(), status.getDescription());
hash = ((BranchSCMRevision) revision).getHash();
} else if (revision instanceof MergeRequestSCMRevision) {
listener.getLogger()
- .format("[GitLab Pipeline Status] Notifying merge request build status: %s %s%n",
+ .format(
+ "[GitLab Pipeline Status] Notifying merge request build status: %s %s%n",
status.getStatus(), status.getDescription());
hash = ((MergeRequestSCMRevision) revision).getOrigin().getHash();
} else if (revision instanceof GitTagSCMRevision) {
listener.getLogger()
- .format("[GitLab Pipeline Status] Notifying tag build status: %s %s%n",
+ .format(
+ "[GitLab Pipeline Status] Notifying tag build status: %s %s%n",
status.getStatus(), status.getDescription());
hash = ((GitTagSCMRevision) revision).getHash();
} else {
@@ -327,8 +340,8 @@ private static void sendNotifications(Run, ?> build, TaskListener listener) {
status.setName(getStatusName(sourceContext, build, envVars, revision));
status.setRef(getRevisionRef(revision));
- final JobScheduledListener jsl = ExtensionList.lookup(QueueListener.class)
- .get(JobScheduledListener.class);
+ final JobScheduledListener jsl =
+ ExtensionList.lookup(QueueListener.class).get(JobScheduledListener.class);
if (jsl != null) {
// we are setting the status, so don't let the queue listener background thread
// change it to pending
@@ -342,18 +355,13 @@ private static void sendNotifications(Run, ?> build, TaskListener listener) {
if (revision instanceof MergeRequestSCMRevision) {
Long projectId = getSourceProjectId(build.getParent(), gitLabApi, source.getProjectPath());
- status.setRef(((MergeRequestSCMRevision) revision).getOrigin().getHead().getName());
- gitLabApi.getCommitsApi().addCommitStatus(
- projectId,
- hash,
- state,
- status);
+ status.setRef(((MergeRequestSCMRevision) revision)
+ .getOrigin()
+ .getHead()
+ .getName());
+ gitLabApi.getCommitsApi().addCommitStatus(projectId, hash, state, status);
} else {
- gitLabApi.getCommitsApi().addCommitStatus(
- source.getProjectPath(),
- hash,
- state,
- status);
+ gitLabApi.getCommitsApi().addCommitStatus(source.getProjectPath(), hash, state, status);
}
listener.getLogger().format("[GitLab Pipeline Status] Notified%n");
@@ -363,10 +371,10 @@ private static void sendNotifications(Run, ?> build, TaskListener listener) {
}
}
} catch (IOException | InterruptedException e) {
- LOGGER.log(Level.INFO,
- "Could not send status notification for " + build.getFullDisplayName()
- + " to " + source
- .getServerName(),
+ LOGGER.log(
+ Level.INFO,
+ "Could not send status notification for " + build.getFullDisplayName() + " to "
+ + source.getServerName(),
e);
}
}
@@ -392,9 +400,8 @@ public void onEnterWaiting(final Queue.WaitingItem wi) {
return;
}
final GitLabSCMSource source = (GitLabSCMSource) src;
- final GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(null,
- SCMHeadObserver.none())
- .withTraits((source.getTraits()));
+ final GitLabSCMSourceContext sourceContext =
+ new GitLabSCMSourceContext(null, SCMHeadObserver.none()).withTraits((source.getTraits()));
if (sourceContext.notificationsDisabled()) {
return;
}
@@ -410,21 +417,17 @@ public void onEnterWaiting(final Queue.WaitingItem wi) {
Computer.threadPoolForRemoting.submit(() -> {
try (ACLContext ctx = ACL.as(Tasks.getAuthenticationOf(wi.task))) {
final TaskListener listener = new LogTaskListener(LOGGER, Level.INFO);
- final SCMRevision revision = source
- .fetch(head, listener);
+ final SCMRevision revision = source.fetch(head, listener);
String hash;
final CommitStatus status = new CommitStatus();
if (revision instanceof BranchSCMRevision) {
- LOGGER.log(Level.INFO, "Notifying branch pending build {0}",
- job.getFullName());
+ LOGGER.log(Level.INFO, "Notifying branch pending build {0}", job.getFullName());
hash = ((BranchSCMRevision) revision).getHash();
} else if (revision instanceof MergeRequestSCMRevision) {
- LOGGER.log(Level.INFO, "Notifying merge request pending build {0}",
- job.getFullName());
+ LOGGER.log(Level.INFO, "Notifying merge request pending build {0}", job.getFullName());
hash = ((MergeRequestSCMRevision) revision).getOrigin().getHash();
} else if (revision instanceof GitTagSCMRevision) {
- LOGGER.log(Level.INFO, "Notifying tag pending build {0}",
- job.getFullName());
+ LOGGER.log(Level.INFO, "Notifying tag pending build {0}", job.getFullName());
hash = ((GitTagSCMRevision) revision).getHash();
} else {
return;
@@ -453,7 +456,8 @@ public void onEnterWaiting(final Queue.WaitingItem wi) {
synchronized (resolving) {
if (!nonce.equals(resolving.get(job))) {
// it's not our nonce, so drop
- LOGGER.log(Level.INFO,
+ LOGGER.log(
+ Level.INFO,
"{0} has already started, skipping notification of queued",
job.getFullName());
return;
@@ -464,18 +468,13 @@ public void onEnterWaiting(final Queue.WaitingItem wi) {
if (revision instanceof MergeRequestSCMRevision) {
Long projectId = getSourceProjectId(job, gitLabApi, source.getProjectPath());
- status.setRef(((MergeRequestSCMRevision) revision).getOrigin().getHead().getName());
- gitLabApi.getCommitsApi().addCommitStatus(
- projectId,
- hash,
- state,
- status);
+ status.setRef(((MergeRequestSCMRevision) revision)
+ .getOrigin()
+ .getHead()
+ .getName());
+ gitLabApi.getCommitsApi().addCommitStatus(projectId, hash, state, status);
} else {
- gitLabApi.getCommitsApi().addCommitStatus(
- source.getProjectPath(),
- hash,
- state,
- status);
+ gitLabApi.getCommitsApi().addCommitStatus(source.getProjectPath(), hash, state, status);
}
LOGGER.log(Level.INFO, "{0} Notified", job.getFullName());
@@ -485,22 +484,25 @@ public void onEnterWaiting(final Queue.WaitingItem wi) {
}
}
} catch (IOException | InterruptedException e) {
- LOGGER.log(Level.INFO,
- "Could not send commit status notification for " + job.getFullName()
- + " to " + source
- .getServerName(),
+ LOGGER.log(
+ Level.INFO,
+ "Could not send commit status notification for " + job.getFullName() + " to "
+ + source.getServerName(),
e);
}
});
}
-
}
@Extension
public static class JobCheckOutListener extends SCMListener {
@Override
- public void onCheckout(Run, ?> build, SCM scm, FilePath workspace, TaskListener listener,
+ public void onCheckout(
+ Run, ?> build,
+ SCM scm,
+ FilePath workspace,
+ TaskListener listener,
File changelogFile,
SCMRevisionState pollingBaseline) {
LOGGER.log(Level.FINE, String.format("SCMListener: Checkout > %s", build.getFullDisplayName()));
@@ -519,7 +521,6 @@ public void onCompleted(Run, ?> build, @NonNull TaskListener listener) {
LOGGER.log(Level.FINE, String.format("RunListener: Complete > %s", build.getFullDisplayName()));
sendNotifications(build, listener);
logComment(build, listener);
-
}
@Override
diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/package-info.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/package-info.java
index 1f59a960..d5cbfce0 100644
--- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/package-info.java
+++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/package-info.java
@@ -35,5 +35,4 @@
* {@linkplain jenkins.scm.api.trait.SCMSourceTrait}s
*
*/
-
package io.jenkins.plugins.gitlabbranchsource;
diff --git a/src/main/java/io/jenkins/plugins/gitlabserverconfig/action/GitlabAction.java b/src/main/java/io/jenkins/plugins/gitlabserverconfig/action/GitlabAction.java
index 022ecc1a..64fe4d1c 100644
--- a/src/main/java/io/jenkins/plugins/gitlabserverconfig/action/GitlabAction.java
+++ b/src/main/java/io/jenkins/plugins/gitlabserverconfig/action/GitlabAction.java
@@ -50,9 +50,8 @@ public HttpResponse doServerList() {
}
@RequirePOST
- public HttpResponse doProjectList(@AncestorInPath SCMSourceOwner context,
- @QueryParameter String server,
- @QueryParameter String owner) {
+ public HttpResponse doProjectList(
+ @AncestorInPath SCMSourceOwner context, @QueryParameter String server, @QueryParameter String owner) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return HttpResponses.errorJSON("no permission to get Gitlab server list");
}
@@ -65,8 +64,8 @@ public HttpResponse doProjectList(@AncestorInPath SCMSourceOwner context,
GitLabApi gitLabApi = GitLabHelper.apiBuilder(context, server);
try {
- for (Project project : gitLabApi.getProjectApi().getUserProjects(owner,
- new ProjectFilter().withOwned(true))) {
+ for (Project project :
+ gitLabApi.getProjectApi().getUserProjects(owner, new ProjectFilter().withOwned(true))) {
servers.add(project.getPathWithNamespace());
}
} catch (GitLabApiException e) {
diff --git a/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java b/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java
index d68f228b..090912a1 100644
--- a/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java
+++ b/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java
@@ -17,13 +17,11 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
-
/**
* Default implementation of {@link PersonalAccessToken} for use by {@link Jenkins} {@link
* CredentialsProvider} instances that store {@link Secret} locally.
*/
-public class PersonalAccessTokenImpl extends BaseStandardCredentials implements
- PersonalAccessToken {
+public class PersonalAccessTokenImpl extends BaseStandardCredentials implements PersonalAccessToken {
/**
* Our token.
@@ -41,10 +39,10 @@ public class PersonalAccessTokenImpl extends BaseStandardCredentials implements
*/
@DataBoundConstructor
public PersonalAccessTokenImpl(
- @CheckForNull CredentialsScope scope,
- @CheckForNull String id,
- @CheckForNull String description,
- @NonNull String token) {
+ @CheckForNull CredentialsScope scope,
+ @CheckForNull String id,
+ @CheckForNull String description,
+ @NonNull String token) {
super(scope, id, description);
this.token = Secret.fromString(token);
}
@@ -88,15 +86,12 @@ public FormValidation doCheckToken(@QueryParameter String value) {
Secret secret = Secret.fromString(value);
if (StringUtils.equals(value, secret.getPlainText())) {
if (value.length() < GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH) {
- return FormValidation
- .error(Messages.PersonalAccessTokenImpl_tokenWrongLength());
+ return FormValidation.error(Messages.PersonalAccessTokenImpl_tokenWrongLength());
}
} else if (secret.getPlainText().length() < GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH) {
return FormValidation.error(Messages.PersonalAccessTokenImpl_tokenWrongLength());
}
return FormValidation.ok();
}
-
}
-
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/package-info.java b/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/package-info.java
index 75a53bd6..89e62b7d 100644
--- a/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/package-info.java
+++ b/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/package-info.java
@@ -4,5 +4,4 @@
* implementations that store credentials external from {@link jenkins.model.Jenkins} can use {@link
* java.lang.reflect.Proxy} to lazily instantiate {@link hudson.util.Secret} properties on access.
*/
-
package io.jenkins.plugins.gitlabserverconfig.credentials;
diff --git a/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java b/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java
index 42628f87..c77a4d88 100644
--- a/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java
+++ b/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java
@@ -1,5 +1,11 @@
package io.jenkins.plugins.gitlabserverconfig.servers;
+import static com.cloudbees.plugins.credentials.CredentialsMatchers.withId;
+import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
+import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
+import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getProxyConfig;
+import static org.apache.commons.lang.StringUtils.defaultIfBlank;
+
import com.cloudbees.plugins.credentials.CredentialsMatcher;
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
@@ -47,12 +53,6 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;
-import static com.cloudbees.plugins.credentials.CredentialsMatchers.withId;
-import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
-import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
-import static io.jenkins.plugins.gitlabbranchsource.helpers.GitLabHelper.getProxyConfig;
-import static org.apache.commons.lang.StringUtils.defaultIfBlank;
-
/**
* Represents a GitLab Server instance.
*/
@@ -61,8 +61,8 @@ public class GitLabServer extends AbstractDescribableImpl {
/**
* The credentials matcher for GitLab Personal Access Token
*/
- public static final CredentialsMatcher CREDENTIALS_MATCHER = CredentialsMatchers
- .instanceOf(PersonalAccessToken.class);
+ public static final CredentialsMatcher CREDENTIALS_MATCHER =
+ CredentialsMatchers.instanceOf(PersonalAccessToken.class);
/**
* Default name for community SaaS version server
*/
@@ -75,7 +75,8 @@ public class GitLabServer extends AbstractDescribableImpl {
* Used as default token value if no any credentials found by given
* credentialsId.
*/
- public final static String EMPTY_TOKEN = "";
+ public static final String EMPTY_TOKEN = "";
+
public static final Logger LOGGER = Logger.getLogger(GitLabServer.class.getName());
private static final SecureRandom RANDOM = new SecureRandom();
/**
@@ -86,13 +87,7 @@ public class GitLabServer extends AbstractDescribableImpl {
/**
* Common prefixes that we should remove when inferring a display name.
*/
- private static final String[] COMMON_PREFIX_HOSTNAMES = {
- "git.",
- "gitlab.",
- "vcs.",
- "scm.",
- "source."
- };
+ private static final String[] COMMON_PREFIX_HOSTNAMES = {"git.", "gitlab.", "vcs.", "scm.", "source."};
/**
* A unique name used to identify the endpoint.
@@ -146,12 +141,11 @@ public class GitLabServer extends AbstractDescribableImpl {
@NonNull
private String webhookSecretCredentialsId;
-
/**
* The credentials matcher for StringCredentials
*/
- public static final CredentialsMatcher WEBHOOK_SECRET_CREDENTIALS_MATCHER = CredentialsMatchers
- .instanceOf(StringCredentials.class);
+ public static final CredentialsMatcher WEBHOOK_SECRET_CREDENTIALS_MATCHER =
+ CredentialsMatchers.instanceOf(StringCredentials.class);
/**
* {@code true} if and only if Jenkins should trigger a build immediately on a
@@ -176,12 +170,9 @@ public class GitLabServer extends AbstractDescribableImpl {
* GitLab Server Authentication to access GitLab APIs
*/
@DataBoundConstructor
- public GitLabServer(@NonNull String serverUrl, @NonNull String name,
- @NonNull String credentialsId) {
+ public GitLabServer(@NonNull String serverUrl, @NonNull String name, @NonNull String credentialsId) {
this.serverUrl = defaultIfBlank(StringUtils.trim(serverUrl), GITLAB_SERVER_URL);
- this.name = StringUtils.isBlank(name)
- ? getRandomName()
- : StringUtils.trim(name);
+ this.name = StringUtils.isBlank(name) ? getRandomName() : StringUtils.trim(name);
this.credentialsId = credentialsId;
this.webhookSecretCredentialsId = "";
}
@@ -192,7 +183,9 @@ public GitLabServer(@NonNull String serverUrl, @NonNull String name,
* @return String
*/
private String getRandomName() {
- return String.format("%s-%s", SCMName.fromUrl(this.serverUrl, COMMON_PREFIX_HOSTNAMES),
+ return String.format(
+ "%s-%s",
+ SCMName.fromUrl(this.serverUrl, COMMON_PREFIX_HOSTNAMES),
RandomStringUtils.randomNumeric(SHORT_NAME_LENGTH));
}
@@ -284,12 +277,16 @@ public PersonalAccessToken getCredentials(AccessControlled context) {
} else {
context.checkPermission(CredentialsProvider.USE_OWN);
}
- return StringUtils.isBlank(credentialsId) ? null
- : CredentialsMatchers.firstOrNull(lookupCredentials(
- PersonalAccessToken.class,
- jenkins,
- ACL.SYSTEM,
- fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()), withId(credentialsId));
+ return StringUtils.isBlank(credentialsId)
+ ? null
+ : CredentialsMatchers.firstOrNull(
+ lookupCredentials(
+ PersonalAccessToken.class,
+ jenkins,
+ ACL.SYSTEM,
+ fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL))
+ .build()),
+ withId(credentialsId));
}
/**
@@ -312,7 +309,8 @@ public String getHooksRootUrl() {
return Util.ensureEndsWith(Util.fixEmptyAndTrim(hooksRootUrl), "/");
}
- @DataBoundSetter @Deprecated
+ @DataBoundSetter
+ @Deprecated
public void setSecretToken(Secret token) {
this.secretToken = token;
}
@@ -335,28 +333,40 @@ public StringCredentials getWebhookSecretCredentials(AccessControlled context) {
Jenkins jenkins = Jenkins.get();
if (context == null) {
jenkins.checkPermission(CredentialsProvider.USE_OWN);
- return StringUtils.isBlank(webhookSecretCredentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials(
- StringCredentials.class,
- jenkins,
- ACL.SYSTEM,
- fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
- ), withId(webhookSecretCredentialsId));
+ return StringUtils.isBlank(webhookSecretCredentialsId)
+ ? null
+ : CredentialsMatchers.firstOrNull(
+ lookupCredentials(
+ StringCredentials.class,
+ jenkins,
+ ACL.SYSTEM,
+ fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL))
+ .build()),
+ withId(webhookSecretCredentialsId));
} else {
context.checkPermission(CredentialsProvider.USE_OWN);
if (context instanceof ItemGroup) {
- return StringUtils.isBlank(webhookSecretCredentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials(
- StringCredentials.class,
- (ItemGroup) context,
- ACL.SYSTEM,
- fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
- ), withId(webhookSecretCredentialsId));
+ return StringUtils.isBlank(webhookSecretCredentialsId)
+ ? null
+ : CredentialsMatchers.firstOrNull(
+ lookupCredentials(
+ StringCredentials.class,
+ (ItemGroup) context,
+ ACL.SYSTEM,
+ fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL))
+ .build()),
+ withId(webhookSecretCredentialsId));
} else {
- return StringUtils.isBlank(webhookSecretCredentialsId) ? null : CredentialsMatchers.firstOrNull( lookupCredentials(
- StringCredentials.class,
- (Item) context,
- ACL.SYSTEM,
- fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()
- ), withId(webhookSecretCredentialsId));
+ return StringUtils.isBlank(webhookSecretCredentialsId)
+ ? null
+ : CredentialsMatchers.firstOrNull(
+ lookupCredentials(
+ StringCredentials.class,
+ (Item) context,
+ ACL.SYSTEM,
+ fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL))
+ .build()),
+ withId(webhookSecretCredentialsId));
}
}
}
@@ -376,14 +386,12 @@ public Secret getSecretToken() {
private StringCredentials getWebhookSecretCredentials(String webhookSecretCredentialsId) {
Jenkins jenkins = Jenkins.get();
- return StringUtils.isBlank(webhookSecretCredentialsId) ? null
- : CredentialsMatchers.firstOrNull(lookupCredentials(
- StringCredentials.class,
- jenkins,
- ACL.SYSTEM,
- new ArrayList()),
- withId(webhookSecretCredentialsId)
- );
+ return StringUtils.isBlank(webhookSecretCredentialsId)
+ ? null
+ : CredentialsMatchers.firstOrNull(
+ lookupCredentials(
+ StringCredentials.class, jenkins, ACL.SYSTEM, new ArrayList()),
+ withId(webhookSecretCredentialsId));
}
public String getSecretTokenAsPlainText() {
@@ -398,7 +406,7 @@ public String getSecretTokenAsPlainText() {
}
private Object readResolve() {
- if(StringUtils.isBlank(webhookSecretCredentialsId) && secretToken != null) {
+ if (StringUtils.isBlank(webhookSecretCredentialsId) && secretToken != null) {
migrateWebhookSecretCredentials();
}
return this;
@@ -408,8 +416,8 @@ private Object readResolve() {
* Migrate webhook secret token to Jenkins credentials
*/
private void migrateWebhookSecretCredentials() {
- final List credentials =
- CredentialsProvider.lookupCredentials(StringCredentials.class, Jenkins.get(), ACL.SYSTEM, Collections.emptyList());
+ final List credentials = CredentialsProvider.lookupCredentials(
+ StringCredentials.class, Jenkins.get(), ACL.SYSTEM, Collections.emptyList());
for (final StringCredentials cred : credentials) {
if (StringUtils.equals(secretToken.getPlainText(), Secret.toString(cred.getSecret()))) {
// If a credential has the same secret, use it.
@@ -419,12 +427,11 @@ private void migrateWebhookSecretCredentials() {
}
if (StringUtils.isBlank(webhookSecretCredentialsId)) {
// If we couldn't find any existing credentials, create new credential
- final StringCredentials newCredentials =
- new StringCredentialsImpl(
- CredentialsScope.GLOBAL,
- null,
- "Migrated from gitlab-branch-source-plugin webhook secret",
- secretToken);
+ final StringCredentials newCredentials = new StringCredentialsImpl(
+ CredentialsScope.GLOBAL,
+ null,
+ "Migrated from gitlab-branch-source-plugin webhook secret",
+ secretToken);
SystemCredentialsProvider.getInstance().getCredentials().add(newCredentials);
webhookSecretCredentialsId = newCredentials.getId();
}
@@ -568,8 +575,7 @@ public String getDisplayName() {
@RequirePOST
@Restricted(DoNotUse.class)
@SuppressWarnings("unused")
- public FormValidation doTestConnection(@QueryParameter String serverUrl,
- @QueryParameter String credentialsId) {
+ public FormValidation doTestConnection(@QueryParameter String serverUrl, @QueryParameter String credentialsId) {
PersonalAccessToken credentials = getCredentials(serverUrl, credentialsId);
String privateToken = "";
if (credentials != null) {
@@ -588,23 +594,21 @@ public FormValidation doTestConnection(@QueryParameter String serverUrl,
return FormValidation.ok("Valid GitLab Server but no credentials specified");
} catch (GitLabApiException e) {
LOGGER.log(Level.SEVERE, "Invalid GitLab Server Url");
- return FormValidation
- .errorWithMarkup(Messages
- .GitLabServer_credentialsNotResolved(Util.escape(credentialsId)));
+ return FormValidation.errorWithMarkup(
+ Messages.GitLabServer_credentialsNotResolved(Util.escape(credentialsId)));
}
} else {
GitLabApi gitLabApi = new GitLabApi(serverUrl, privateToken, null, getProxyConfig(serverUrl));
try {
User user = gitLabApi.getUserApi().getCurrentUser();
- LOGGER.log(Level.FINEST, String
- .format("Connection established with the GitLab Server for %s", user.getUsername()));
- return FormValidation
- .ok(String.format("Credentials verified for user %s", user.getUsername()));
+ LOGGER.log(
+ Level.FINEST,
+ String.format("Connection established with the GitLab Server for %s", user.getUsername()));
+ return FormValidation.ok(String.format("Credentials verified for user %s", user.getUsername()));
} catch (GitLabApiException e) {
LOGGER.log(Level.SEVERE, "Failed to connect with GitLab Server - %s", e.getMessage());
- return FormValidation.error(e,
- Messages.GitLabServer_failedValidation(Util.escape(e.getMessage())));
+ return FormValidation.error(e, Messages.GitLabServer_failedValidation(Util.escape(e.getMessage())));
}
}
}
@@ -618,15 +622,16 @@ public FormValidation doTestConnection(@QueryParameter String serverUrl,
*/
@Restricted(NoExternalUse.class) // stapler
@SuppressWarnings("unused")
- public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl,
- @QueryParameter String credentialsId) {
+ public ListBoxModel doFillCredentialsIdItems(
+ @QueryParameter String serverUrl, @QueryParameter String credentialsId) {
Jenkins jenkins = Jenkins.get();
if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
return new StandardListBoxModel().includeCurrentValue(credentialsId);
}
return new StandardListBoxModel()
.includeEmptyValue()
- .includeMatchingAs(ACL.SYSTEM,
+ .includeMatchingAs(
+ ACL.SYSTEM,
jenkins,
StandardCredentials.class,
fromUri(serverUrl).build(),
@@ -641,34 +646,35 @@ public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl,
*/
@Restricted(NoExternalUse.class) // stapler
@SuppressWarnings("unused")
- public ListBoxModel doFillWebhookSecretCredentialsIdItems(@QueryParameter String serverUrl,
- @QueryParameter String webhookSecretCredentialsId) {
+ public ListBoxModel doFillWebhookSecretCredentialsIdItems(
+ @QueryParameter String serverUrl, @QueryParameter String webhookSecretCredentialsId) {
Jenkins jenkins = Jenkins.get();
if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
return new StandardListBoxModel().includeCurrentValue(webhookSecretCredentialsId);
}
return new StandardListBoxModel()
- .includeEmptyValue()
- .includeMatchingAs(ACL.SYSTEM,
- jenkins,
- StringCredentials.class,
- fromUri(serverUrl).build(),
- WEBHOOK_SECRET_CREDENTIALS_MATCHER
- );
+ .includeEmptyValue()
+ .includeMatchingAs(
+ ACL.SYSTEM,
+ jenkins,
+ StringCredentials.class,
+ fromUri(serverUrl).build(),
+ WEBHOOK_SECRET_CREDENTIALS_MATCHER);
}
private PersonalAccessToken getCredentials(String serverUrl, String credentialsId) {
Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Jenkins.ADMINISTER);
- return StringUtils.isBlank(credentialsId) ? null
+ return StringUtils.isBlank(credentialsId)
+ ? null
: CredentialsMatchers.firstOrNull(
lookupCredentials(
PersonalAccessToken.class,
jenkins,
ACL.SYSTEM,
- fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()),
+ fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL))
+ .build()),
withId(credentialsId));
}
-
}
}
diff --git a/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers.java b/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers.java
index 93c227eb..c81d73b7 100644
--- a/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers.java
+++ b/src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers.java
@@ -1,5 +1,7 @@
package io.jenkins.plugins.gitlabserverconfig.servers;
+import static hudson.Util.fixNull;
+
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
@@ -21,8 +23,6 @@
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
-import static hudson.Util.fixNull;
-
/**
* Represents the global configuration of GitLab servers.
*/
@@ -54,8 +54,7 @@ public static GitLabServers get() {
* @param In this case it is server
* @return a predicate to filter servers list
*/
- private static Predicate distinctByKey(
- Function super T, ?> keyExtractor) {
+ private static Predicate distinctByKey(Function super T, ?> keyExtractor) {
Map