Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public FetchUsersFromTeam(UserExternalRepository userExternalRepository) {
this.userExternalRepository = userExternalRepository;
}

public List<User> execute(Integer organizationId, Integer teamId) throws HttpException {
return this.userExternalRepository.fetchUsersFromTeam(organizationId, teamId);
public List<User> execute(String organizationName, String teamName) throws HttpException {
return this.userExternalRepository.fetchUsersFromTeam(organizationName, teamName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public FetchTeamsFromOrganization(TeamExternalRepository teamExternalRepository)
this.teamExternalRepository = teamExternalRepository;
}

public List<Team> execute(Integer organizationId) throws HttpException {
return teamExternalRepository.fetchTeamsFromOrganization(organizationId);
public List<Team> execute(String organizationName) throws HttpException {
return teamExternalRepository.fetchTeamsFromOrganization(organizationName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Organization {
@JsonProperty("id")
private Integer id;

@Column
@JsonProperty("login")
private String login;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.pakland.mdas.githubstats.domain;

import java.util.Map;
import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -29,7 +30,6 @@ public class Repository {
private String name;

@Column(name = "owner_login")
@JsonProperty("owner.login")
private String ownerLogin;

@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -41,4 +41,9 @@ public class Repository {
orphanRemoval = true
)
private List<PullRequest> pullRequests = new ArrayList<>();

@JsonProperty("owner")
private void unpackNameFromNestedObject(Map<String, String> owner) {
this.ownerLogin = owner.get("login");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import java.util.List;

public interface TeamExternalRepository {
List<Team> fetchTeamsFromOrganization(Integer organizationId) throws HttpException;
List<Team> fetchTeamsFromOrganization(String organizationName) throws HttpException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import java.util.List;

public interface UserExternalRepository {
List<User> fetchUsersFromTeam(Integer organizationId, Integer teamId) throws HttpException;
List<User> fetchUsersFromTeam(String organizationName, String teamName) throws HttpException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public PullRequestGitHubRepository(WebClientConfiguration webClientConfiguration
}

@Override
public List<PullRequest> fetchPullRequestsFromRepository(String repositoryOwnerLogin, String repositoryName) throws HttpException {
public List<PullRequest> fetchPullRequestsFromRepository(String repositoryOwner, String repositoryName) throws HttpException {
try {
return this.webClientConfiguration.getWebClient().get()
.uri(String.format("/organizations/%d/team/%d/repos", repositoryOwnerLogin, repositoryName))
.uri(String.format("/repos/%s/%s/pulls", repositoryOwner, repositoryName))
.retrieve()
.bodyToFlux(PullRequest.class)
.collectList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public List<Repository> fetchTeamRepositories(String organizationLogin, String t
throws HttpException {
try {
return this.webClientConfiguration.getWebClient().get()
.uri(String.format("/organizations/%d/team/%d/repos", organizationLogin, teamSlug))
.uri(String.format("/orgs/%s/teams/%s/repos", organizationLogin, teamSlug))
.retrieve()
.bodyToFlux(Repository.class)
.collectList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public TeamGitHubRepository(WebClientConfiguration webClientConfiguration) {
}

@Override
public List<Team> fetchTeamsFromOrganization(Integer organizationId) throws HttpException {
public List<Team> fetchTeamsFromOrganization(String organizationName) throws HttpException {
try {
return this.webClientConfiguration.getWebClient().get()
.uri(String.format("/orgs/%d/teams", organizationId))
.uri(String.format("/orgs/%s/teams", organizationName))
.retrieve()
.bodyToFlux(Team.class)
.collectList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public UserGitHubRepository(WebClientConfiguration webClientConfiguration) {
}

@Override
public List<User> fetchUsersFromTeam(Integer organizationId, Integer teamId) throws HttpException {
public List<User> fetchUsersFromTeam(String organizationName, String teamName) throws HttpException {
try {
return this.webClientConfiguration.getWebClient().get()
.uri(String.format("/orgs/%d/teams/%d/members", organizationId, teamId))
.uri(String.format("/orgs/%s/teams/%s/members", organizationName, teamName))
.retrieve()
.bodyToFlux(User.class)
.collectList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public void execute() {
for (Organization organization : organizationList) {
// Fetch the teams belonging to the available organization.
List<Team> teamList = new FetchTeamsFromOrganization(teamExternalRepository)
.execute(organization.getId());
.execute(organization.getLogin());

for (Team team : teamList) {
// Fetch the members of each team.
logger.info(organization.getLogin());
List<User> userList = new FetchUsersFromTeam(userExternalRepository)
.execute(organization.getId(), team.getId());
.execute(organization.getLogin(), team.getSlug());
// Fetch the repositories for each team.
List<Repository> repositoryList = new FetchRepositoriesFromTeam(repositoryExternalRepository)
.execute(organization.getLogin(), team.getSlug());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class TeamGitHubRepositoryTest {
private TeamGitHubRepository teamGitHubRepository;
private String organizationTeamsListResponse;

private final Integer organizationId = 119930124;
private final Integer teamId = 7098104;
private final String organizationName = "github-stats-22";
private final String teamName = "gs-developers";

@BeforeAll
void setup() throws IOException {
Expand All @@ -53,22 +53,22 @@ void givenValidTeamMembersRequest_shouldCallTeamMembersEndpoint() throws Interru
.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
mockWebServer.enqueue(mockResponse);

teamGitHubRepository.fetchTeamsFromOrganization(this.organizationId);
teamGitHubRepository.fetchTeamsFromOrganization(this.organizationName);

RecordedRequest request = mockWebServer.takeRequest();
assertEquals(String.format("/orgs/%d/teams", this.organizationId), request.getPath());
assertEquals(String.format("/orgs/%s/teams", this.organizationName), request.getPath());
}

@Test
void givenValidTeamId_shouldReturnTeamMembers() throws HttpException {
void givenValidTeamName_shouldReturnTeamMembers() throws HttpException {
MockResponse mockResponse = new MockResponse()
.setBody(this.organizationTeamsListResponse)
.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
mockWebServer.enqueue(mockResponse);

List<Team> response = teamGitHubRepository.fetchTeamsFromOrganization(this.organizationId);
List<Team> response = teamGitHubRepository.fetchTeamsFromOrganization(this.organizationName);
List<Team> expected = new ArrayList<>();
expected.add(0, new Team(this.teamId, "gs-developers", null, new ArrayList<User>(), new ArrayList<Repository>()));
expected.add(0, new Team(7098104, "gs-developers", null, new ArrayList<User>(), new ArrayList<Repository>()));

assertEquals(1, response.size());
assertArrayEquals(response.toArray(), expected.toArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class UserGitHubRepositoryTest {
private UserGitHubRepository userGitHubRepository;
private String teamMembersListResponse;

private final Integer organizationId = 119930124;
private final Integer teamId = 7098104;
private final String organizationName = "github-stats-22";
private final String teamName = "gs-developers";

@BeforeAll
void setup() throws IOException {
Expand All @@ -51,10 +51,10 @@ void givenValidTeamMembersRequest_shouldCallTeamMembersEndpoint() throws Interru
.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
mockWebServer.enqueue(mockResponse);

userGitHubRepository.fetchUsersFromTeam(this.organizationId, this.teamId);
userGitHubRepository.fetchUsersFromTeam(this.organizationName, this.teamName);

RecordedRequest request = mockWebServer.takeRequest();
assertEquals(String.format("/orgs/%d/teams/%d/members", this.organizationId, this.teamId), request.getPath());
assertEquals(String.format("/orgs/%s/teams/%s/members", this.organizationName, this.teamName), request.getPath());
}

@Test
Expand All @@ -65,7 +65,7 @@ void givenValidTeamId_shouldReturnTeamMembers() throws HttpException {
.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
mockWebServer.enqueue(mockResponse);

List<User> response = userGitHubRepository.fetchUsersFromTeam(this.organizationId, this.teamId);
List<User> response = userGitHubRepository.fetchUsersFromTeam(this.organizationName, this.teamName);
List<User> expected = new ArrayList<>();
expected.add(0, new User(33031570, "manerow", null, new ArrayList<>(), new ArrayList<>()));
expected.add(1, new User(48334745, "mikededo", null, new ArrayList<>(), new ArrayList<>()));
Expand Down