Skip to content

Commit b28f428

Browse files
new architecture + added info user + changed query to search-usr
1 parent c91b132 commit b28f428

7 files changed

Lines changed: 280 additions & 1 deletion

File tree

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
<version>1.1.1</version>
5555
</dependency>
5656

57+
<!-- https://mvnrepository.com/artifact/org.kohsuke/github-api -->
58+
<dependency>
59+
<groupId>org.kohsuke</groupId>
60+
<artifactId>github-api</artifactId>
61+
<version>1.116</version>
62+
</dependency>
63+
5764

5865
</dependencies>
5966

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import org.jsoup.nodes.Element;
1212
import org.jsoup.select.Elements;
1313
import org.jsoup.Jsoup;
14+
import org.kohsuke.github.*;
1415

1516

17+
import javax.print.Doc;
1618
import java.io.File;
1719
import java.io.IOException;
1820
import java.util.*;
@@ -232,9 +234,40 @@ public int getUserPages(String username) throws IOException
232234

233235
}
234236

235-
public void getUserInfo(String user)
237+
public void getUserInfo(String username) throws IOException
236238
{
237239

240+
GitHub gitHub = new GitHubBuilder().build();
241+
GHUser user = gitHub.getUser(username);
242+
String email = user.getEmail();
243+
244+
if(email == null)
245+
email = ErrorMessages.MAIL_NOT_SETTED.toString();
246+
247+
System.out.println("username: "+username);
248+
System.out.println("email: "+email );
249+
250+
System.out.print("followers: ");
251+
252+
GHPersonSet<GHUser> followers = user.getFollowers();
253+
for(GHUser myuser : followers)
254+
{
255+
System.out.print(myuser.getLogin() + " ");
256+
}
257+
258+
System.out.print("\nfollowing: ");
259+
GHPersonSet<GHUser> follows = user.getFollows();
260+
261+
for(GHUser myuser : follows)
262+
{
263+
System.out.print(myuser.getLogin()+" ");
264+
}
265+
266+
System.out.print("\nrepository: ");
267+
Map<String,GHRepository> repository = user.getRepositories();
268+
System.out.println(repository.keySet());
269+
270+
238271
}
239272

240273

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.francescodisalesdev.gitcli.shellcomponents;
2+
3+
import com.francescodisalesdev.gitcli.service.GitService;
4+
import com.francescodisalesdev.gitcli.utility.ErrorMessages;
5+
6+
import org.springframework.shell.standard.ShellComponent;
7+
import org.springframework.shell.standard.ShellMethod;
8+
9+
import java.io.IOException;
10+
11+
@ShellComponent
12+
public class GitCliNavigation
13+
{
14+
15+
@ShellMethod("check a file")
16+
public void checkFile(String path)
17+
{
18+
GitService gitService = new GitService();
19+
20+
try
21+
{
22+
gitService.checkFileService(path);
23+
}
24+
catch(IOException e)
25+
{
26+
System.out.println(ErrorMessages.SOMETHING_BAD);
27+
System.out.println(e.getMessage());
28+
}
29+
30+
}
31+
32+
@ShellMethod("go to a specific folder")
33+
public void navigate(String path)
34+
{
35+
GitService gitService = new GitService();
36+
37+
try
38+
{
39+
gitService.navigateService(path);
40+
}
41+
catch (IOException e)
42+
{
43+
System.out.println(ErrorMessages.SOMETHING_BAD);
44+
System.out.println(e.getMessage());
45+
}
46+
47+
}
48+
49+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.francescodisalesdev.gitcli.shellcomponents;
2+
3+
import com.francescodisalesdev.gitcli.service.GitService;
4+
import com.francescodisalesdev.gitcli.utility.ErrorMessages;
5+
import org.springframework.shell.standard.ShellComponent;
6+
import org.springframework.shell.standard.ShellMethod;
7+
import org.springframework.shell.standard.ShellOption;
8+
9+
import java.io.IOException;
10+
11+
@ShellComponent
12+
public class GitCliShellClone
13+
{
14+
15+
@ShellMethod("clone the repository given an url")
16+
public void clone(String repository, String localPath, @ShellOption(value = "master")String branch)
17+
{
18+
GitService gitService = new GitService();
19+
20+
try
21+
{
22+
gitService.cloneRepositoryBranch(repository,localPath,branch);
23+
}
24+
catch(IOException | InterruptedException e)
25+
{
26+
System.out.println(ErrorMessages.SOMETHING_BAD);
27+
System.out.println(e.getMessage());
28+
}
29+
30+
}
31+
32+
33+
34+
35+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.francescodisalesdev.gitcli.shellcomponents;
2+
3+
import com.francescodisalesdev.gitcli.service.GitService;
4+
import com.francescodisalesdev.gitcli.utility.ErrorMessages;
5+
import com.francescodisalesdev.gitcli.utility.SystemMessages;
6+
import org.json.simple.parser.ParseException;
7+
import org.springframework.shell.standard.ShellComponent;
8+
import org.springframework.shell.standard.ShellMethod;
9+
import org.springframework.shell.standard.ShellOption;
10+
11+
import java.io.IOException;
12+
import java.util.Iterator;
13+
import java.util.List;
14+
15+
@ShellComponent
16+
public class GitCliShellRepository
17+
{
18+
19+
@ShellMethod("search for a git repository")
20+
public void searchRepository(String repository,@ShellOption(defaultValue = "1") int page)
21+
{
22+
try
23+
{
24+
25+
GitService gitService = new GitService();
26+
List<String> result = gitService.getResult(repository,page);
27+
28+
if(result==null)
29+
System.out.println("page number must be bigger than 0");
30+
else
31+
{
32+
Iterator responseIterator = result.iterator();
33+
34+
while(responseIterator.hasNext())
35+
{
36+
System.out.println(responseIterator.next());
37+
}
38+
39+
int pagesRepository = gitService.getPages(repository);
40+
41+
if(pagesRepository>1)
42+
System.out.println(SystemMessages.TOTAL_PAGES.toString()+pagesRepository);
43+
44+
}
45+
46+
47+
}
48+
catch(IOException | ParseException e)
49+
{
50+
System.out.println(ErrorMessages.SOMETHING_BAD);
51+
System.out.println(e.getMessage());
52+
}
53+
54+
}
55+
56+
57+
@ShellMethod("see a list of files in a repository")
58+
public void infoRepository(String repository)
59+
{
60+
GitService gitService = new GitService();
61+
62+
try
63+
{
64+
gitService.getInfoRepository(repository);
65+
66+
}
67+
catch (IOException e)
68+
{
69+
System.out.println(ErrorMessages.SOMETHING_BAD);
70+
System.out.println(e.getMessage());
71+
}
72+
73+
}
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.francescodisalesdev.gitcli.shellcomponents;
2+
3+
import com.francescodisalesdev.gitcli.service.GitService;
4+
import com.francescodisalesdev.gitcli.utility.ErrorMessages;
5+
import com.francescodisalesdev.gitcli.utility.SystemMessages;
6+
import org.json.simple.parser.ParseException;
7+
import org.kohsuke.github.GHUser;
8+
import org.springframework.shell.standard.ShellComponent;
9+
import org.springframework.shell.standard.ShellMethod;
10+
import org.springframework.shell.standard.ShellOption;
11+
12+
import java.io.IOException;
13+
import java.util.Iterator;
14+
import java.util.Set;
15+
16+
@ShellComponent
17+
public class GitCliShellUser
18+
{
19+
@ShellMethod("search for a specific user")
20+
public void searchUser(String username,@ShellOption(defaultValue = "1") int page)
21+
{
22+
GitService gitService = new GitService();
23+
24+
try
25+
{
26+
Set<String> usersResult = gitService.searchUserService(username,page);
27+
28+
if(usersResult == null)
29+
System.out.println(ErrorMessages.USER_NOT_FOUND.toString());
30+
else
31+
{
32+
Iterator iterator = usersResult.iterator();
33+
34+
while(iterator.hasNext())
35+
System.out.println(iterator.next());
36+
}
37+
38+
int pages = gitService.getUserPages(username);
39+
if(pages > 1)
40+
System.out.println(SystemMessages.TOTAL_PAGES.toString()+pages);
41+
42+
}
43+
catch (IOException | ParseException e)
44+
{
45+
System.out.println(ErrorMessages.SOMETHING_BAD);
46+
System.out.println(e.getMessage());
47+
}
48+
49+
}
50+
51+
@ShellMethod("gets information about a user")
52+
public void infoUser(String user)
53+
{
54+
GitService gitService = new GitService();
55+
56+
57+
try
58+
{
59+
if(!user.isEmpty())
60+
gitService.getUserInfo(user);
61+
else
62+
System.out.println(ErrorMessages.USER_NOT_FOUND.toString());
63+
}
64+
catch(IOException e)
65+
{
66+
System.out.println(ErrorMessages.SOMETHING_BAD);
67+
System.out.println(e.getMessage());
68+
}
69+
70+
71+
}
72+
73+
74+
}

src/main/java/com/francescodisalesdev/gitcli/utility/ErrorMessages.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@ public String toString() {
3131
public String toString() {
3232
return "User not found";
3333
}
34+
},
35+
MAIL_NOT_SETTED
36+
{
37+
@Override
38+
public String toString() {
39+
return "Mail not setted";
40+
}
3441
}
3542
}

0 commit comments

Comments
 (0)