You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/07/19 05:51:12 UTC

[camel] branch master updated: CAMEL-12666: Create push tag operation

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 2d3b486  CAMEL-12666: Create push tag operation
2d3b486 is described below

commit 2d3b486dd7e15dba4b545e4b4e4920ded949d516
Author: valtoni <va...@gmail.com>
AuthorDate: Wed Jul 18 15:09:30 2018 -0300

    CAMEL-12666: Create push tag operation
---
 .../camel-git/src/main/docs/git-component.adoc     |  2 ++
 .../camel/component/git/producer/GitOperation.java |  1 +
 .../camel/component/git/producer/GitProducer.java  | 28 ++++++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/components/camel-git/src/main/docs/git-component.adoc b/components/camel-git/src/main/docs/git-component.adoc
index fe84ad8..22b5a89 100644
--- a/components/camel-git/src/main/docs/git-component.adoc
+++ b/components/camel-git/src/main/docs/git-component.adoc
@@ -134,6 +134,8 @@ from("direct:start")
         .setHeader(GitConstants.GIT_COMMIT_MESSAGE, constant("first commit"))
         .to("git:///tmp/testRepo?operation=commit")
         .to("git:///tmp/testRepo?operation=push&remotePath=https://foo.com/test/test.git&username=xxx&password=xxx")
+        .to("git:///tmp/testRepo?operation=createTag&tagName=myTag")
+        .to("git:///tmp/testRepo?operation=pushTag&tagName=myTag&remoteName=origin")
 --------------------------------------------------------------------------------------------------------------------
 
 ### Consumer Example
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
index d2373a7..d5f63fa 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
@@ -31,6 +31,7 @@ public interface GitOperation {
     String STATUS_OPERATION = "status";
     String LOG_OPERATION = "log";
     String PUSH_OPERATION = "push";
+    String PUSH_TAG_OPERATION = "pushTag";
     String PULL_OPERATION = "pull";
     String MERGE_OPERATION = "merge";
     String SHOW_BRANCHES_OPERATION = "showBranches";
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
index 07ef434..7ac108f 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
@@ -36,6 +36,7 @@ import org.eclipse.jgit.api.MergeResult;
 import org.eclipse.jgit.api.PullResult;
 import org.eclipse.jgit.api.RemoteAddCommand;
 import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.Repository;
@@ -49,6 +50,7 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 public class GitProducer extends DefaultProducer {
 
     private static final Logger LOG = LoggerFactory.getLogger(GitProducer.class);
@@ -140,6 +142,10 @@ public class GitProducer extends DefaultProducer {
             doPush(exchange, operation);
             break;
 
+        case GitOperation.PUSH_TAG_OPERATION:
+            doPushTag(exchange, operation);
+            break;
+
         case GitOperation.PULL_OPERATION:
             doPull(exchange, operation);
             break;
@@ -407,6 +413,28 @@ public class GitProducer extends DefaultProducer {
         updateExchange(exchange, result);
     }
 
+    protected void doPushTag(Exchange exchange, String operation) throws Exception {
+        Iterable<PushResult> result = null;
+        try {
+            if (ObjectHelper.isEmpty(endpoint.getRemoteName())) {
+                throw new IllegalArgumentException("Remote name must be specified to execute " + operation);
+            }
+            if (ObjectHelper.isEmpty(endpoint.getTagName())) {
+                throw new IllegalArgumentException("Tag Name must be specified to execute " + operation);
+            }
+            if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
+                UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
+                result = git.push().setCredentialsProvider(credentials).setRemote(endpoint.getRemoteName()).add(Constants.R_TAGS + endpoint.getTagName()).call();
+            } else {
+                result = git.push().setRemote(endpoint.getRemoteName()).add(Constants.R_TAGS + endpoint.getTagName()).call();
+            }
+        } catch (Exception e) {
+            LOG.error("There was an error in Git " + operation + " operation");
+            throw e;
+        }
+        updateExchange(exchange, result);
+    }
+
     protected void doPull(Exchange exchange, String operation) throws Exception {
         PullResult result = null;
         try {