#89 -- Divide git api services
parent
aeab50cfb8
commit
3de664abb1
@ -0,0 +1,61 @@
|
||||
package ru.ulstu.extractor.gitrepository.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.branch.model.Branch;
|
||||
import ru.ulstu.extractor.http.HttpService;
|
||||
|
||||
@Service
|
||||
public class GithubApi implements GitApi {
|
||||
private final HttpService httpService;
|
||||
private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches";
|
||||
private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s";
|
||||
private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open";
|
||||
private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open";
|
||||
private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches";
|
||||
|
||||
public GithubApi(HttpService httpService) {
|
||||
this.httpService = httpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getBranchesCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL))
|
||||
.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStarsCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL))
|
||||
.getJSONObject(0)
|
||||
.getInt("stars_count");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getOpenIssuesCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL))
|
||||
.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedUrl(String gitRepositoryUrl, String template) {
|
||||
String[] urlParts = gitRepositoryUrl.split("/");
|
||||
return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getAuthorsCompletedIssues(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL))
|
||||
.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getAuthorsCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL))
|
||||
.length();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package ru.ulstu.extractor.gitrepository.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.branch.model.Branch;
|
||||
import ru.ulstu.extractor.http.HttpService;
|
||||
|
||||
@Service
|
||||
public class GitlabApi implements GitApi {
|
||||
private final HttpService httpService;
|
||||
private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches";
|
||||
private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s";
|
||||
private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open";
|
||||
private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open";
|
||||
private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches";
|
||||
|
||||
public GitlabApi(HttpService httpService) {
|
||||
this.httpService = httpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getBranchesCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL))
|
||||
.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStarsCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL))
|
||||
.getJSONObject(0)
|
||||
.getInt("stars_count");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getOpenIssuesCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL))
|
||||
.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedUrl(String gitRepositoryUrl, String template) {
|
||||
String[] urlParts = gitRepositoryUrl.split("/");
|
||||
return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getAuthorsCompletedIssues(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL))
|
||||
.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getAuthorsCount(Branch branch) {
|
||||
return httpService
|
||||
.get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL))
|
||||
.length();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue