You are viewing a plain text version of this content. The canonical link for it is here.
Posted to submarine-dev@hadoop.apache.org by GitBox <gi...@apache.org> on 2019/10/24 05:40:03 UTC

[GitHub] [hadoop-submarine] LinhaoZhu commented on a change in pull request #51: SUBMARINE-236. Add JGit Utils class

LinhaoZhu commented on a change in pull request #51: SUBMARINE-236. Add JGit Utils class
URL: https://github.com/apache/hadoop-submarine/pull/51#discussion_r338388929
 
 

 ##########
 File path: submarine-workbench/workbench-server/src/main/java/org/apache/submarine/server/WorkbenchGitHubServer.java
 ##########
 @@ -0,0 +1,323 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.submarine.server;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.ListBranchCommand;
+import org.eclipse.jgit.api.PullResult;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.PushResult;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.List;
+
+public class WorkbenchGitHubServer {
+  private static final Logger LOG = LoggerFactory.getLogger(WorkbenchGitHubServer.class);
+
+  /**
+   * To execute clone command
+   * @param remotePath
+   * @param localPath
+   * @param token
+   * @param branch
+   * @throws GitAPIException
+   */
+  public void clone(String remotePath, String localPath, String token, String branch) {
+    // Clone the code base command
+    // Sets the token on the remote server
+    CredentialsProvider credentialsProvider =
+        new UsernamePasswordCredentialsProvider("PRIVATE-TOKEN", token);
+
+    Git git = null;
+    try {
+      git = Git.cloneRepository().setURI(remotePath) // Set remote URI
+          .setBranch(branch) // Set the branch down from clone
+          .setDirectory(new File(localPath)) // Set the download path
+          .setCredentialsProvider(credentialsProvider) // Set permission validation
+          .call();
+    } catch (GitAPIException e) {
+      LOG.error(e.getMessage(), e);
+    } finally {
+      if (git != null) {
+        git.close();
+      }
+    }
+    LOG.info("git.tag(): {}", git.tag());
+  }
+
+  /**
+   * To execute add command
+   * @param localPath
+   * @param fileName
+   *          relative path
+   * @throws IOException
+   * @throws GitAPIException
+   */
+  public DirCache add(String localPath, String fileName) {
+    // Git repository address
+    File myfile = new File(localPath + fileName);
+    if (!myfile.exists()) {
+      myfile.getParentFile().mkdirs();
+      try {
+        myfile.createNewFile();
+      } catch (IOException e) {
+        LOG.error(e.getMessage(), e);
+      }
+    }
+    DirCache dirCache = null;
+    // try (Git git = new Git(new FileRepository(localPath + ".git"))) {
 
 Review comment:
   Done.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services