Skip to content

The Unified and Autonomous Development Platform

Fix the issue that input @ in image field when initialize repository will fail

Robin Shene4d977be657e
diff --git a/server-core/src/main/java/io/onedev/server/ci/job/Job.java b/server-core/src/main/java/io/onedev/server/ci/job/Job.java
index d0d255a855..b9520a0c2c 100644
--- a/server-core/src/main/java/io/onedev/server/ci/job/Job.java
+++ b/server-core/src/main/java/io/onedev/server/ci/job/Job.java
@@ -20,6 +20,7 @@ import javax.validation.constraints.Size;
import org.apache.wicket.Component;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.hibernate.validator.constraints.NotEmpty;
import io.onedev.commons.codeassist.InputSuggestion;
@@ -129,8 +130,15 @@ public class Job implements Serializable, Validatable {
JobAware jobAware = WicketUtils.findInnermost(component, JobAware.class);
if (jobAware != null) {
Job job = jobAware.getJob();
- if (job != null)
- suggestions.addAll(SuggestionUtils.suggestVariables(page.getProject(), page.getCommit(), job, matchWith));
+ if (job != null) {
+ RevCommit commit;
+ if (page.getBlobIdent().revision != null)
+ commit = page.getCommit();
+ else
+ commit = null;
+ suggestions.addAll(SuggestionUtils.suggestVariables(page.getProject(), commit, job, matchWith));
+
+ }
}
return suggestions;
}
@@ -162,7 +170,7 @@ public class Job implements Serializable, Validatable {
return variables;
}
- @Editable(order=130, name="Parameter Specs", description="Define parameter specifications of the job")
+ @Editable(order=130, name="Parameter Specs", description="Optionally define parameter specifications of the job")
@Valid
public List<ParamSpec> getParamSpecs() {
return paramSpecs;
diff --git a/server-core/src/main/java/io/onedev/server/model/support/Secret.java b/server-core/src/main/java/io/onedev/server/model/support/Secret.java
index e43515459a..7f41c5cbb1 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/Secret.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/Secret.java
@@ -7,7 +7,9 @@ import org.eclipse.jgit.lib.ObjectId;
import org.hibernate.validator.constraints.NotEmpty;
import io.onedev.commons.codeassist.InputSuggestion;
+import io.onedev.commons.utils.match.PathMatcher;
import io.onedev.server.model.Project;
+import io.onedev.server.util.patternset.PatternSet;
import io.onedev.server.util.validation.annotation.DnsName;
import io.onedev.server.web.editable.annotation.Editable;
import io.onedev.server.web.editable.annotation.NameOfEmptyValue;
@@ -82,4 +84,8 @@ public class Secret implements Serializable {
return authorizedBranches == null || project.isCommitOnBranches(commitId, authorizedBranches);
}
+ public boolean isAuthorized(Project project, String branch) {
+ return authorizedBranches == null
+ || PatternSet.fromString(authorizedBranches).matches(new PathMatcher(), branch);
+ }
}
diff --git a/server-core/src/main/java/io/onedev/server/web/util/SuggestionUtils.java b/server-core/src/main/java/io/onedev/server/web/util/SuggestionUtils.java
index 3a8afa88ff..774ecd1ff2 100644
--- a/server-core/src/main/java/io/onedev/server/web/util/SuggestionUtils.java
+++ b/server-core/src/main/java/io/onedev/server/web/util/SuggestionUtils.java
@@ -10,6 +10,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
+import javax.annotation.Nullable;
+
import org.eclipse.jgit.lib.ObjectId;
import com.google.common.base.Preconditions;
@@ -91,7 +93,7 @@ public class SuggestionUtils {
return suggestions;
}
- public static List<InputSuggestion> suggestVariables(Project project, ObjectId commitId,
+ public static List<InputSuggestion> suggestVariables(Project project, @Nullable ObjectId commitId,
Job job, String matchWith) {
matchWith = matchWith.toLowerCase();
int numSuggestions = 0;
@@ -104,8 +106,10 @@ public class SuggestionUtils {
variables.put(VariableInterpolator.PARAMS_PREFIX + paramSpec.getName(), paramSpec.getDescription());
for (Secret secret: project.getSecrets()) {
String varName = VariableInterpolator.SECRETS_PREFIX + secret.getName();
- if (!variables.containsKey(varName) && secret.isAuthorized(project, commitId))
+ if (!variables.containsKey(varName)
+ && (commitId != null && secret.isAuthorized(project, commitId) || commitId == null && secret.isAuthorized(project, "master"))) {
variables.put(varName, null);
+ }
}
for (GroovyScript script: OneDev.getInstance(SettingManager.class).getGroovyScripts()) {
String varName = VariableInterpolator.SCRIPTS_PREFIX + script.getName();