Skip to content

Commit a00d6f1

Browse files
added branch support for info-repository and added more retrieve info for User
1 parent 6b68cb5 commit a00d6f1

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.francescodisales</groupId>
1212
<artifactId>gitCliShell</artifactId>
13-
<version>0.7.3</version>
13+
<version>0.8.7</version>
1414
<name>gitCliShell</name>
1515
<description>Cli interface that navigates in github</description>
1616

src/main/java/com/francescodisalesdev/gitcli/service/GitService.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.kohsuke.github.*;
1515

1616

17-
import javax.print.Doc;
1817
import java.io.File;
1918
import java.io.IOException;
2019
import java.util.*;
@@ -84,11 +83,11 @@ public void cloneRepositoryBranch(String repository,String localPath,String bran
8483
{
8584
String gitRepository = repository+".git";
8685

87-
ProcessBuilder processBuilder = new ProcessBuilder("git","clone","-b",branch,gitRepository);
88-
8986
if(localPath.contains("\\"))
9087
localPath.replace("\\","\\\\");
9188

89+
ProcessBuilder processBuilder = new ProcessBuilder("git","clone","-b",branch,gitRepository);
90+
9291
processBuilder.directory(new File(localPath));
9392
Process process = processBuilder.start();
9493

@@ -100,9 +99,18 @@ public void cloneRepositoryBranch(String repository,String localPath,String bran
10099

101100
}
102101

103-
public void getInfoRepository(String repository) throws IOException
102+
public void getInfoRepository(String repository,String username,String branch) throws IOException
104103
{
105-
Document document = Jsoup.connect(repository).get();
104+
105+
String URL;
106+
107+
if(branch.equals("master"))
108+
URL = "https://github.com/"+username+"/"+repository;
109+
else
110+
URL = "https://github.com/"+username+"/"+repository+"/tree/"+branch;
111+
112+
System.out.println(URL);
113+
Document document = Jsoup.connect(URL).get();
106114

107115
Elements elements = document.select("a");
108116
List<String> info = new ArrayList<String>();
@@ -233,8 +241,10 @@ public int getUserPages(String username) throws IOException
233241
Document document = Jsoup.connect(URL).get();
234242
Elements elementsLinks = document.select("em");
235243

236-
int value = Integer.parseInt(elementsLinks.attr("data-total-pages").toString());
237-
return value;
244+
if(elementsLinks.attr("data-total-pages").toString().isEmpty())
245+
return 0;
246+
247+
return Integer.parseInt(elementsLinks.attr("data-total-pages").toString());
238248

239249
}
240250

@@ -278,5 +288,18 @@ public void getUserInfo(String username) throws IOException
278288

279289
}
280290

291+
public void getBranchRepository(String repository,String username) throws IOException
292+
{
293+
GitHub gitHub = new GitHubBuilder().build();
294+
GHUser user = gitHub.getUser(username);
295+
Map<String,GHBranch> branches = user.getRepository(repository).getBranches();
296+
297+
for(Map.Entry<String,GHBranch> branchMap : branches.entrySet())
298+
{
299+
System.out.println(branchMap.getValue());
300+
}
301+
302+
}
303+
281304

282305
}

src/main/java/com/francescodisalesdev/gitcli/shellcomponents/GitCliShellRepository.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public void searchRepository(String repository,@ShellOption(defaultValue = "1")
5555

5656

5757
@ShellMethod("see a list of files in a repository")
58-
public void infoRepository(String repository)
58+
public void infoRepository(String repository,String username,@ShellOption(defaultValue = "master") String branch)
5959
{
6060
GitService gitService = new GitService();
6161

6262
try
6363
{
64-
gitService.getInfoRepository(repository);
64+
gitService.getInfoRepository(repository,username,branch);
6565

6666
}
6767
catch (IOException e)
@@ -71,4 +71,22 @@ public void infoRepository(String repository)
7171
}
7272

7373
}
74+
75+
@ShellMethod("show all the branches of a repository")
76+
public void infoBranch(String repository,String username)
77+
{
78+
GitService gitService = new GitService();
79+
80+
try
81+
{
82+
gitService.getBranchRepository(repository,username);
83+
84+
}
85+
catch (IOException e)
86+
{
87+
System.out.println(ErrorMessages.SOMETHING_BAD);
88+
System.out.println(e.getMessage());
89+
}
90+
}
91+
7492
}

src/main/java/com/francescodisalesdev/gitcli/shellcomponents/GitCliShellUser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import com.francescodisalesdev.gitcli.service.GitService;
44
import com.francescodisalesdev.gitcli.utility.ErrorMessages;
55
import com.francescodisalesdev.gitcli.utility.SystemMessages;
6+
67
import org.json.simple.parser.ParseException;
7-
import org.kohsuke.github.GHUser;
8+
89
import org.springframework.shell.standard.ShellComponent;
910
import org.springframework.shell.standard.ShellMethod;
1011
import org.springframework.shell.standard.ShellOption;
@@ -53,7 +54,6 @@ public void infoUser(String user)
5354
{
5455
GitService gitService = new GitService();
5556

56-
5757
try
5858
{
5959
if(!user.isEmpty())

0 commit comments

Comments
 (0)