Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Cilia2018-07-25 09:59:03 -0400
committerThomas Wolf2018-12-14 16:02:53 -0500
commit6be10360ff6ad2173696c08a2ccaf8d304426747 (patch)
treec7a3cc77173356022fd02e97700b02d21ee0e114
parent03f87a38a842acf0f2958ef41d5dc34936eff074 (diff)
downloadegit-github-6be10360ff6ad2173696c08a2ccaf8d304426747.tar.gz
egit-github-6be10360ff6ad2173696c08a2ccaf8d304426747.tar.xz
egit-github-6be10360ff6ad2173696c08a2ccaf8d304426747.zip
Implement merging API for repository
Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365799a Signed-off-by: Frédéric Cilia <frederic.cilia@hardis.fr>
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingResponseTest.java69
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingTest.java48
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java18
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMerging.java78
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMergingResponse.java196
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java2
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java39
7 files changed, 445 insertions, 5 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingResponseTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingResponseTest.java
new file mode 100644
index 00000000..bc92cc1c
--- /dev/null
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingResponseTest.java
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * Copyright (c) 2018 Frédéric Cilia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Frédéric Cilia - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.github.core.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+
+import org.eclipse.egit.github.core.Commit;
+import org.eclipse.egit.github.core.RepositoryMergingResponse;
+import org.eclipse.egit.github.core.User;
+import org.junit.Test;
+
+/**
+ * Unit tests of {@link RepositoryMergingResponse}
+ */
+public class RepositoryMergingResponseTest {
+
+ /**
+ * Test default state of response
+ */
+ @Test
+ public void defaultState() {
+ RepositoryMergingResponse response = new RepositoryMergingResponse();
+ assertNull(response.getSha());
+ assertNull(response.getNodeId());
+ assertNull(response.getCommit());
+ assertNull(response.getUrl());
+ assertNull(response.getHtmlUrl());
+ assertNull(response.getCommentsUrl());
+ assertNull(response.getAuthor());
+ assertNull(response.getCommitter());
+ assertNull(response.getParents());
+ }
+
+ /**
+ * Test updating response fields
+ */
+ @Test
+ public void updateFields() {
+ RepositoryMergingResponse response = new RepositoryMergingResponse();
+ assertEquals("sha", response.setSha("sha").getSha());
+ assertEquals("nodeId", response.setNodeId("nodeId").getNodeId());
+ User author = new User().setLogin("author");
+ assertEquals(author, response.setAuthor(author).getAuthor());
+ Commit gitCommit = new Commit().setSha("abc");
+ assertEquals(gitCommit, response.setCommit(gitCommit).getCommit());
+ User committer = new User().setLogin("committer");
+ assertEquals(committer, response.setCommitter(committer).getCommitter());
+ assertEquals("url", response.setUrl("url").getUrl());
+ assertEquals("htmlUrl", response.setHtmlUrl("htmlUrl").getHtmlUrl());
+ assertEquals("commentsUrl",
+ response.setCommentsUrl("commentsUrl").getCommentsUrl());
+ assertEquals(new ArrayList<Commit>(),
+ response.setParents(new ArrayList<Commit>()).getParents());
+
+ }
+}
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingTest.java
new file mode 100644
index 00000000..f5467b78
--- /dev/null
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryMergingTest.java
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * Copyright (c) 2018 Frédéric Cilia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Frédéric Cilia - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.github.core.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.eclipse.egit.github.core.RepositoryMerging;
+import org.junit.Test;
+
+/**
+ * Unit test of {@link RepositoryMerging}
+ */
+public class RepositoryMergingTest {
+
+ /**
+ * Test default state of merging
+ */
+ @Test
+ public void defaultState() {
+ RepositoryMerging merging = new RepositoryMerging();
+ assertNull(merging.getBase());
+ assertNull(merging.getCommitMessage());
+ assertNull(merging.getHead());
+ }
+
+ /**
+ * Test updating merging fields
+ */
+ @Test
+ public void updateFields() {
+ RepositoryMerging merging = new RepositoryMerging();
+ assertEquals("baseMerging", merging.setBase("baseMerging").getBase());
+ assertEquals("headMerging", merging.setHead("headMerging").getHead());
+ assertEquals("messageMerging",
+ merging.setCommitMessage("messageMerging").getCommitMessage());
+ }
+}
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java
index dbd39311..b623d09b 100644
--- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java
@@ -25,6 +25,8 @@ import java.util.Map;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryHook;
import org.eclipse.egit.github.core.RepositoryId;
+import org.eclipse.egit.github.core.RepositoryMerging;
+import org.eclipse.egit.github.core.RepositoryMergingResponse;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
@@ -625,4 +627,20 @@ public class RepositoryServiceTest {
service.testHook(repo, 5609);
verify(client).post("/repos/o/n/hooks/5609/test");
}
+
+ /**
+ * Run merge in repository
+ *
+ * @throws IOException
+ */
+ @Test
+ public void runMerge() throws IOException {
+ RepositoryMerging merge = new RepositoryMerging();
+ merge.setBase("develop");
+ merge.setHead("master");
+ merge.setCommitMessage("Test Merge");
+ service.mergingBranches(repo, merge);
+ verify(client).post("/repos/o/n/merges", merge,
+ RepositoryMergingResponse.class);
+ }
}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMerging.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMerging.java
new file mode 100644
index 00000000..804c6cb6
--- /dev/null
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMerging.java
@@ -0,0 +1,78 @@
+/******************************************************************************
+ * Copyright (c) 2018 Frédéric Cilia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Frédéric Cilia - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.github.core;
+
+import java.io.Serializable;
+
+/**
+ * Repository merging model class
+ */
+public class RepositoryMerging implements Serializable {
+
+ private static final long serialVersionUID = 6179934015396875505L;
+
+ private String base;
+
+ private String head;
+
+ private String commitMessage;
+
+ /**
+ * @return base
+ */
+ public String getBase() {
+ return base;
+ }
+
+ /**
+ * @param base
+ * @return this merge
+ */
+ public RepositoryMerging setBase(String base) {
+ this.base = base;
+ return this;
+ }
+
+ /**
+ * @return head
+ */
+ public String getHead() {
+ return head;
+ }
+
+ /**
+ * @param head
+ * @return this merge
+ */
+ public RepositoryMerging setHead(String head) {
+ this.head = head;
+ return this;
+ }
+
+ /**
+ * @return commitMessage
+ */
+ public String getCommitMessage() {
+ return commitMessage;
+ }
+
+ /**
+ * @param commitMessage
+ * @return this merge
+ */
+ public RepositoryMerging setCommitMessage(String commitMessage) {
+ this.commitMessage = commitMessage;
+ return this;
+ }
+
+}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMergingResponse.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMergingResponse.java
new file mode 100644
index 00000000..015a2eff
--- /dev/null
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/RepositoryMergingResponse.java
@@ -0,0 +1,196 @@
+/******************************************************************************
+ * Copyright (c) 2018 Frédéric Cilia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Frédéric Cilia - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.github.core;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Repository merging response model class
+ */
+public class RepositoryMergingResponse implements Serializable {
+
+ private static final long serialVersionUID = 3450081957091778831L;
+
+ private String sha;
+
+ private String nodeId;
+
+ private Commit commit;
+
+ private String url;
+
+ private String htmlUrl;
+
+ private String commentsUrl;
+
+ private User author;
+
+ private User committer;
+
+ private List<Commit> parents;
+
+ /**
+ * @return the sha
+ */
+ public String getSha() {
+ return sha;
+ }
+
+ /**
+ * @param sha
+ * the sha to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setSha(String sha) {
+ this.sha = sha;
+ return this;
+ }
+
+ /**
+ * @return the nodeId
+ */
+ public String getNodeId() {
+ return nodeId;
+ }
+
+ /**
+ * @param nodeId
+ * the nodeId to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setNodeId(String nodeId) {
+ this.nodeId = nodeId;
+ return this;
+ }
+
+ /**
+ * @return the commit
+ */
+ public Commit getCommit() {
+ return commit;
+ }
+
+ /**
+ * @param commit
+ * the commit to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setCommit(Commit commit) {
+ this.commit = commit;
+ return this;
+ }
+
+ /**
+ * @return the url
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * @param url
+ * the url to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setUrl(String url) {
+ this.url = url;
+ return this;
+ }
+
+ /**
+ * @return the htmlUrl
+ */
+ public String getHtmlUrl() {
+ return htmlUrl;
+ }
+
+ /**
+ * @param htmlUrl
+ * the htmlUrl to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setHtmlUrl(String htmlUrl) {
+ this.htmlUrl = htmlUrl;
+ return this;
+ }
+
+ /**
+ * @return the commentsUrl
+ */
+ public String getCommentsUrl() {
+ return commentsUrl;
+ }
+
+ /**
+ * @param commentsUrl
+ * the commentsUrl to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setCommentsUrl(String commentsUrl) {
+ this.commentsUrl = commentsUrl;
+ return this;
+ }
+
+ /**
+ * @return the author
+ */
+ public User getAuthor() {
+ return author;
+ }
+
+ /**
+ * @param author
+ * the author to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setAuthor(User author) {
+ this.author = author;
+ return this;
+ }
+
+ /**
+ * @return the committer
+ */
+ public User getCommitter() {
+ return committer;
+ }
+
+ /**
+ * @param committer
+ * the committer to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setCommitter(User committer) {
+ this.committer = committer;
+ return this;
+ }
+
+ /**
+ * @return the parents
+ */
+ public List<Commit> getParents() {
+ return parents;
+ }
+
+ /**
+ * @param parents
+ * the parents to set
+ * @return this merge response
+ */
+ public RepositoryMergingResponse setParents(List<Commit> parents) {
+ this.parents = parents;
+ return this;
+ }
+
+}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java
index d1cfff4c..0af84173 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java
@@ -133,6 +133,8 @@ public interface IGitHubConstants {
/** */
String SEGMENT_MERGE = "/merge"; //$NON-NLS-1$
/** */
+ String SEGMENT_MERGES = "/merges"; //$NON-NLS-1$
+ /** */
String SEGMENT_MILESTONES = "/milestones"; //$NON-NLS-1$
/** */
String SEGMENT_NETWORKS = "/networks"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java
index 7a056224..c0671356 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java
@@ -21,6 +21,7 @@ import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_FORKS
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_HOOKS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_LANGUAGES;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_LEGACY;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_MERGES;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_ORGS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOSITORIES;
@@ -49,6 +50,8 @@ import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryBranch;
import org.eclipse.egit.github.core.RepositoryHook;
import org.eclipse.egit.github.core.RepositoryId;
+import org.eclipse.egit.github.core.RepositoryMerging;
+import org.eclipse.egit.github.core.RepositoryMergingResponse;
import org.eclipse.egit.github.core.RepositoryTag;
import org.eclipse.egit.github.core.SearchRepository;
import org.eclipse.egit.github.core.client.GitHubClient;
@@ -111,8 +114,8 @@ public class RepositoryService extends GitHubService {
*/
public static final String TYPE_ALL = "all"; //$NON-NLS-1$
- private static class RepositoryContainer implements
- IResourceProvider<SearchRepository> {
+ private static class RepositoryContainer
+ implements IResourceProvider<SearchRepository> {
private List<SearchRepository> repositories;
@@ -488,8 +491,8 @@ public class RepositoryService extends GitHubService {
if (query.length() == 0)
throw new IllegalArgumentException("Query cannot be empty"); //$NON-NLS-1$
- StringBuilder uri = new StringBuilder(SEGMENT_LEGACY + SEGMENT_REPOS
- + SEGMENT_SEARCH);
+ StringBuilder uri = new StringBuilder(
+ SEGMENT_LEGACY + SEGMENT_REPOS + SEGMENT_SEARCH);
final String encodedQuery = URLEncoder.encode(query, CHARSET_UTF8)
.replace("+", "%20") //$NON-NLS-1$ //$NON-NLS-2$
.replace(".", "%2E"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -653,7 +656,8 @@ public class RepositoryService extends GitHubService {
* @param repository
* @return iterator over repositories
*/
- public PageIterator<Repository> pageForks(IRepositoryIdProvider repository) {
+ public PageIterator<Repository> pageForks(
+ IRepositoryIdProvider repository) {
return pageForks(repository, PAGE_SIZE);
}
@@ -982,4 +986,29 @@ public class RepositoryService extends GitHubService {
uri.append(SEGMENT_TEST);
client.post(uri.toString());
}
+
+ /**
+ * Merge branches in repository. This will merge branch and push result to
+ * the repository.
+ *
+ * @param repository
+ * @param merging
+ * @return merging result or null if there is nothing to merge
+ * @throws IOException
+ */
+ public RepositoryMergingResponse mergingBranches(
+ IRepositoryIdProvider repository, RepositoryMerging merging)
+ throws IOException {
+ String id = getId(repository);
+ StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
+ uri.append('/').append(id);
+ uri.append(SEGMENT_MERGES);
+ RepositoryMergingResponse result = client.post(uri.toString(), merging,
+ RepositoryMergingResponse.class);
+ if (result != null && result.getCommit() != null
+ && result.getCommit().getSha() == null) {
+ result.getCommit().setSha(result.getSha());
+ }
+ return result;
+ }
}

Back to the top