Merge branch 'approvals' into develop
This commit is contained in:
commit
7b0019f4fe
@ -95,6 +95,17 @@ public class MergeRequest {
|
|||||||
)
|
)
|
||||||
private List<Person> reviewers = new ArrayList<>();
|
private List<Person> reviewers = new ArrayList<>();
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
fetch = FetchType.LAZY,
|
||||||
|
cascade = {CascadeType.PERSIST, CascadeType.MERGE}
|
||||||
|
)
|
||||||
|
@JoinTable(
|
||||||
|
name = "merge_request_approvals",
|
||||||
|
joinColumns = @JoinColumn(name = "merge_request_id", referencedColumnName = "id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "person_id", referencedColumnName = "id")
|
||||||
|
)
|
||||||
|
private List<Person> approvals = new ArrayList<>();
|
||||||
|
|
||||||
@Column(name = "target_branch")
|
@Column(name = "target_branch")
|
||||||
private String targetBranch;
|
private String targetBranch;
|
||||||
|
|
||||||
|
@ -46,6 +46,11 @@ public class GitlabProperty {
|
|||||||
*/
|
*/
|
||||||
private String mergeRequestUrl;
|
private String mergeRequestUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Адрес, по которому можно получить апрувы.
|
||||||
|
*/
|
||||||
|
private String mergeRequestApprovalUrl;
|
||||||
|
|
||||||
private String projectAddUrl;
|
private String projectAddUrl;
|
||||||
|
|
||||||
private String noteUrl;
|
private String noteUrl;
|
||||||
|
@ -13,6 +13,8 @@ import dev.struchkov.bot.gitlab.core.service.parser.forktask.GetAllMergeRequestF
|
|||||||
import dev.struchkov.bot.gitlab.core.service.parser.forktask.GetSingleMergeRequestTask;
|
import dev.struchkov.bot.gitlab.core.service.parser.forktask.GetSingleMergeRequestTask;
|
||||||
import dev.struchkov.bot.gitlab.core.utils.HttpParse;
|
import dev.struchkov.bot.gitlab.core.utils.HttpParse;
|
||||||
import dev.struchkov.bot.gitlab.core.utils.StringUtils;
|
import dev.struchkov.bot.gitlab.core.utils.StringUtils;
|
||||||
|
import dev.struchkov.bot.gitlab.sdk.domain.ApprovalContainerJson;
|
||||||
|
import dev.struchkov.bot.gitlab.sdk.domain.ApprovalJson;
|
||||||
import dev.struchkov.bot.gitlab.sdk.domain.CommitJson;
|
import dev.struchkov.bot.gitlab.sdk.domain.CommitJson;
|
||||||
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson;
|
import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -32,6 +34,7 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static dev.struchkov.bot.gitlab.core.utils.HttpParse.ACCEPT;
|
import static dev.struchkov.bot.gitlab.core.utils.HttpParse.ACCEPT;
|
||||||
|
import static dev.struchkov.haiti.context.exception.ConvertException.convertException;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||||
import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResult;
|
import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResult;
|
||||||
@ -77,6 +80,7 @@ public class MergeRequestParser {
|
|||||||
.map(mergeRequestJson -> {
|
.map(mergeRequestJson -> {
|
||||||
final MergeRequest newMergeRequest = conversionService.convert(mergeRequestJson, MergeRequest.class);
|
final MergeRequest newMergeRequest = conversionService.convert(mergeRequestJson, MergeRequest.class);
|
||||||
parsingCommits(newMergeRequest);
|
parsingCommits(newMergeRequest);
|
||||||
|
parsingApprovals(newMergeRequest);
|
||||||
return newMergeRequest;
|
return newMergeRequest;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -124,6 +128,7 @@ public class MergeRequestParser {
|
|||||||
.map(json -> {
|
.map(json -> {
|
||||||
final MergeRequest mergeRequest = conversionService.convert(json, MergeRequest.class);
|
final MergeRequest mergeRequest = conversionService.convert(json, MergeRequest.class);
|
||||||
parsingCommits(mergeRequest);
|
parsingCommits(mergeRequest);
|
||||||
|
parsingApprovals(mergeRequest);
|
||||||
return mergeRequest;
|
return mergeRequest;
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
@ -179,6 +184,7 @@ public class MergeRequestParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO [19.01.2024|uPagge]: Переделать в многопоточный режим
|
||||||
private void parsingCommits(MergeRequest mergeRequest) {
|
private void parsingCommits(MergeRequest mergeRequest) {
|
||||||
final List<CommitJson> commitJson = HttpParse.request(
|
final List<CommitJson> commitJson = HttpParse.request(
|
||||||
MessageFormat.format(gitlabProperty.getLastCommitOfMergeRequestUrl(), mergeRequest.getProjectId(), mergeRequest.getTwoId())
|
MessageFormat.format(gitlabProperty.getLastCommitOfMergeRequestUrl(), mergeRequest.getProjectId(), mergeRequest.getTwoId())
|
||||||
@ -186,9 +192,30 @@ public class MergeRequestParser {
|
|||||||
.header(ACCEPT)
|
.header(ACCEPT)
|
||||||
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
|
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
|
||||||
.executeList(CommitJson.class);
|
.executeList(CommitJson.class);
|
||||||
if (commitJson != null && !commitJson.isEmpty()) {
|
if (checkNotEmpty(commitJson)) {
|
||||||
mergeRequest.setDateLastCommit(commitJson.get(0).getCreatedDate());
|
mergeRequest.setDateLastCommit(commitJson.get(0).getCreatedDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO [19.01.2024|uPagge]: Переделать в многопоточный режим
|
||||||
|
private void parsingApprovals(MergeRequest mergeRequest) {
|
||||||
|
final ApprovalContainerJson approvalContainer = HttpParse.request(
|
||||||
|
MessageFormat.format(gitlabProperty.getMergeRequestApprovalUrl(), mergeRequest.getProjectId(), mergeRequest.getTwoId())
|
||||||
|
)
|
||||||
|
.header(ACCEPT)
|
||||||
|
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
|
||||||
|
.execute(ApprovalContainerJson.class)
|
||||||
|
.orElseThrow(convertException("Error request approvals"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (checkNotEmpty(approvalContainer.getApprovals())) {
|
||||||
|
final List<Person> approvals = approvalContainer.getApprovals().stream()
|
||||||
|
.map(ApprovalJson::getUser)
|
||||||
|
.map(personJson -> conversionService.convert(personJson, Person.class))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
mergeRequest.setApprovals(approvals);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ gitlab-bot:
|
|||||||
close-merge-requests-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests?state=closed&page={1, number, integer}&per_page=100"
|
close-merge-requests-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests?state=closed&page={1, number, integer}&per_page=100"
|
||||||
comments-of-merge-request-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes?&page={2,number,#}&per_page=100"
|
comments-of-merge-request-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes?&page={2,number,#}&per_page=100"
|
||||||
merge-request-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}"
|
merge-request-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}"
|
||||||
|
merge-request-approval-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/approvals"
|
||||||
project-add-url: "${GITLAB_URL}/api/v4/projects/"
|
project-add-url: "${GITLAB_URL}/api/v4/projects/"
|
||||||
note-url: "{0}#note_{1,number,#}"
|
note-url: "{0}#note_{1,number,#}"
|
||||||
notes-of-merge-request-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes/{2,number,#}"
|
notes-of-merge-request-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes/{2,number,#}"
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
<databaseChangeLog
|
||||||
|
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.17.xsd">
|
||||||
|
|
||||||
|
<changeSet id="2024-01-20-create-table-approvals" author="struchkov">
|
||||||
|
<createTable tableName="merge_request_approvals">
|
||||||
|
<column name="merge_request_id" type="int">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_merge_request_approvals_merge_request_id"
|
||||||
|
references="merge_request(id)" deleteCascade="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="person_id" type="int">
|
||||||
|
<constraints nullable="false" foreignKeyName="fk_merge_request_approvals_person_id"
|
||||||
|
references="person(id)" deleteCascade="true"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<addPrimaryKey tableName="merge_request_approvals" columnNames="merge_request_id, person_id"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
@ -9,5 +9,6 @@
|
|||||||
|
|
||||||
<include file="2024-02-06-change-varchar.xml" relativeToChangelogFile="true"/>
|
<include file="2024-02-06-change-varchar.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="2024-08-21-add-milestone.xml" relativeToChangelogFile="true"/>
|
<include file="2024-08-21-add-milestone.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="2024-01-20-create-merge-request-approvals.xml" relativeToChangelogFile="true"/>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
@ -0,0 +1,14 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.sdk.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApprovalContainerJson {
|
||||||
|
|
||||||
|
@JsonProperty("approved_by")
|
||||||
|
private List<ApprovalJson> approvals;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.sdk.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApprovalJson {
|
||||||
|
|
||||||
|
private PersonJson user;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user