From 00fdf580b2eeedc7f0d6c08494a1640044cf711d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Tabin?= Date: Thu, 18 May 2017 17:36:24 +0200 Subject: [PATCH 1/3] fixes getProjects(namespace, name) with a search --- src/main/java/org/gitlab/api/GitlabAPI.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index 47089f44..d81e23e0 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -585,8 +585,15 @@ public GitlabProject getProject(Serializable projectId) throws IOException { * use namespace & project name to get project */ public GitlabProject getProject(String namespace, String projectName) throws IOException{ - String tailUrl = GitlabProject.URL + "/" + namespace + "%2F" + projectName; - return retrieve().to(tailUrl, GitlabProject.class); + String fullName = namespace+" / "+projectName; + String tailUrl = GitlabProject.URL + "?search=" + projectName; + GitlabProject[] projects = retrieve().to(tailUrl, GitlabProject[].class); + for(GitlabProject gp : projects) { + if(gp.getNameWithNamespace().equals(fullName)) { + return gp; + } + } + return null; } /** From 641557b370247da49588c47a39e9c02d344db690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Tabin?= Date: Thu, 18 May 2017 17:52:58 +0200 Subject: [PATCH 2/3] fixes Travis build --- src/main/java/org/gitlab/api/GitlabAPI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index d81e23e0..36e7069c 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -593,7 +593,7 @@ public GitlabProject getProject(String namespace, String projectName) throws IOE return gp; } } - return null; + throw new FileNotFoundException("Project not found: "+fullName); } /** From c5988dec8ba24e8740574613fc2953f8c595eb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Tabin?= Date: Wed, 31 May 2017 22:56:31 +0200 Subject: [PATCH 3/3] better implementation of getProject() method to check the namespace's name instead of the full name --- src/main/java/org/gitlab/api/GitlabAPI.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index 36e7069c..3e9d9427 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -585,15 +585,15 @@ public GitlabProject getProject(Serializable projectId) throws IOException { * use namespace & project name to get project */ public GitlabProject getProject(String namespace, String projectName) throws IOException{ - String fullName = namespace+" / "+projectName; String tailUrl = GitlabProject.URL + "?search=" + projectName; GitlabProject[] projects = retrieve().to(tailUrl, GitlabProject[].class); for(GitlabProject gp : projects) { - if(gp.getNameWithNamespace().equals(fullName)) { + String pNamespace = gp.getNamespace().getName(); + if(pNamespace.equals(namespace)) { return gp; } } - throw new FileNotFoundException("Project not found: "+fullName); + throw new FileNotFoundException("Project not found: "+namespace+" / "+projectName); } /**