Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[egit-dev] PushOption for gitlab-ci

Hello,

First of all, I am Brazilian and not English native spoken, I am willing to reply you if my communication is not so clear.
At my company, we have gitlab-ci for managing CI runners. Sometimes, the developer needs run the runner with
custom variable and he should use --push-option parameter, like Push Options | GitLab. And, the push-option works
in jgit command line.


I tried to add the push.pushOption to the repo properties on Git Perspective. But, it was not working.

So, I patched the org.eclipse.egit.core.op.PushOperation class for supporting push.pushOption repository
properties. I could upload "ci.skip" option. But, the problem is when I pushed ci.variable="MY_ENV_VARIABLE=test123",
it is not lauching the CI runner at all.

I attached the patch file.

Where should I look: jgit or egit? And how can I debug to check what is arriving on gitlab, I tracked all jgit transport classes,
and I couldnt see any problem?

regards
Leandro




diff --git a/org.eclipse.egit.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.egit.core/.settings/org.eclipse.jdt.core.prefs
index 3b7997d13..b6136b60b 100644
--- a/org.eclipse.egit.core/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.egit.core/.settings/org.eclipse.jdt.core.prefs
@@ -18,6 +18,7 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
 org.eclipse.jdt.core.compiler.doc.comment.support=enabled
 org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.autoboxing=warning
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java
index 134fbde85..d0897b56a 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java
@@ -17,7 +17,9 @@
 import java.io.OutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URISyntaxException;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.SubMonitor;
@@ -26,6 +28,7 @@
 import org.eclipse.egit.core.internal.CoreText;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.transport.CredentialsProvider;
 import org.eclipse.jgit.transport.PushResult;
@@ -103,7 +106,8 @@ private PushOperation(final Repository localDb, final String remoteName,
 	/**
 	 * @param credentialsProvider
 	 */
-	public void setCredentialsProvider(CredentialsProvider credentialsProvider) {
+	public void setCredentialsProvider(
+			CredentialsProvider credentialsProvider) {
 		this.credentialsProvider = credentialsProvider;
 	}
 
@@ -167,6 +171,10 @@ public void run(IProgressMonitor actMonitor)
 
 		operationResult = new PushOperationResult();
 		try (Git git = new Git(localDb)) {
+			Config config = git.getRepository().getConfig();
+			List<String> pushOptions = Arrays
+					.asList(config.getStringList("push", null, "pushOption")); //$NON-NLS-1$ //$NON-NLS-2$
+
 			if (specification != null)
 				for (final URIish uri : specification.getURIs()) {
 					if (progress.isCanceled()) {
@@ -184,6 +192,7 @@ public void run(IProgressMonitor actMonitor)
 					try (Transport transport = Transport.open(localDb, uri)) {
 						transport.setDryRun(dryRun);
 						transport.setTimeout(timeout);
+						transport.setPushOptions(pushOptions);
 						if (credentialsProvider != null) {
 							transport.setCredentialsProvider(
 									credentialsProvider);
@@ -197,7 +206,8 @@ public void run(IProgressMonitor actMonitor)
 								result.getRemoteUpdates());
 					} catch (JGitInternalException e) {
 						String errorMessage = e.getCause() != null
-								? e.getCause().getMessage() : e.getMessage();
+								? e.getCause().getMessage()
+								: e.getMessage();
 						String userMessage = NLS.bind(
 								CoreText.PushOperation_InternalExceptionOccurredMessage,
 								errorMessage);
@@ -211,8 +221,9 @@ public void run(IProgressMonitor actMonitor)
 						progress.newChild(totalWork));
 				try {
 					Iterable<PushResult> results = git.push()
-							.setRemote(remoteName).setDryRun(dryRun)
-							.setTimeout(timeout).setProgressMonitor(gitMonitor)
+							.setPushOptions(pushOptions).setRemote(remoteName)
+							.setDryRun(dryRun).setTimeout(timeout)
+							.setProgressMonitor(gitMonitor)
 							.setCredentialsProvider(credentialsProvider)
 							.setOutputStream(out).call();
 					for (PushResult result : results) {
@@ -221,7 +232,8 @@ public void run(IProgressMonitor actMonitor)
 					}
 				} catch (JGitInternalException e) {
 					String errorMessage = e.getCause() != null
-							? e.getCause().getMessage() : e.getMessage();
+							? e.getCause().getMessage()
+							: e.getMessage();
 					String userMessage = NLS.bind(
 							CoreText.PushOperation_InternalExceptionOccurredMessage,
 							errorMessage);
@@ -254,8 +266,8 @@ private URIish getPushURIForErrorHandling() {
 		RemoteConfig rc = null;
 		try {
 			rc = new RemoteConfig(localDb.getConfig(), remoteName);
-			return rc.getPushURIs().isEmpty() ? rc.getURIs().get(0) : rc
-					.getPushURIs().get(0);
+			return rc.getPushURIs().isEmpty() ? rc.getURIs().get(0)
+					: rc.getPushURIs().get(0);
 		} catch (URISyntaxException e) {
 			// should not happen
 			Activator.logError("Reading RemoteConfig failed", e); //$NON-NLS-1$

Back to the top