Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Cilia2018-07-25 13:59:03 +0000
committerThomas Wolf2018-12-14 21:02:53 +0000
commit6be10360ff6ad2173696c08a2ccaf8d304426747 (patch)
treec7a3cc77173356022fd02e97700b02d21ee0e114 /org.eclipse.egit.github.core
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>
Diffstat (limited to 'org.eclipse.egit.github.core')
-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
4 files changed, 310 insertions, 5 deletions
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