Добавление функционала апрува
This commit is contained in:
parent
905e13053e
commit
76ffd566af
@ -92,6 +92,17 @@ public class MergeRequest {
|
||||
)
|
||||
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")
|
||||
private String targetBranch;
|
||||
|
||||
|
@ -46,6 +46,11 @@ public class GitlabProperty {
|
||||
*/
|
||||
private String mergeRequestUrl;
|
||||
|
||||
/**
|
||||
* Адрес, по которому можно получить апрувы.
|
||||
*/
|
||||
private String mergeRequestApprovalUrl;
|
||||
|
||||
private String projectAddUrl;
|
||||
|
||||
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.utils.HttpParse;
|
||||
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.MergeRequestJson;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -32,6 +34,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
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.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResult;
|
||||
@ -77,6 +80,7 @@ public class MergeRequestParser {
|
||||
.map(mergeRequestJson -> {
|
||||
final MergeRequest newMergeRequest = conversionService.convert(mergeRequestJson, MergeRequest.class);
|
||||
parsingCommits(newMergeRequest);
|
||||
parsingApprovals(newMergeRequest);
|
||||
return newMergeRequest;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
@ -124,6 +128,7 @@ public class MergeRequestParser {
|
||||
.map(json -> {
|
||||
final MergeRequest mergeRequest = conversionService.convert(json, MergeRequest.class);
|
||||
parsingCommits(mergeRequest);
|
||||
parsingApprovals(mergeRequest);
|
||||
return mergeRequest;
|
||||
})
|
||||
.toList();
|
||||
@ -179,6 +184,7 @@ public class MergeRequestParser {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO [19.01.2024|uPagge]: Переделать в многопоточный режим
|
||||
private void parsingCommits(MergeRequest mergeRequest) {
|
||||
final List<CommitJson> commitJson = HttpParse.request(
|
||||
MessageFormat.format(gitlabProperty.getLastCommitOfMergeRequestUrl(), mergeRequest.getProjectId(), mergeRequest.getTwoId())
|
||||
@ -186,9 +192,30 @@ public class MergeRequestParser {
|
||||
.header(ACCEPT)
|
||||
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
|
||||
.executeList(CommitJson.class);
|
||||
if (commitJson != null && !commitJson.isEmpty()) {
|
||||
if (checkNotEmpty(commitJson)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,6 +55,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"
|
||||
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-approval-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/approvals"
|
||||
project-add-url: "${GITLAB_URL}/api/v4/projects/"
|
||||
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,#}"
|
||||
|
@ -4,5 +4,6 @@
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.17.xsd">
|
||||
|
||||
<include file="v.1.0.0/changelog.xml" relativeToChangelogFile="true"/>
|
||||
<include file="v.2.0.0/changelog.xml" relativeToChangelogFile="true"/>
|
||||
|
||||
</databaseChangeLog>
|
@ -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>
|
@ -0,0 +1,12 @@
|
||||
<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-add-tab-v-2-0-0" author="uPagge">
|
||||
<tagDatabase tag="v.2.0.0"/>
|
||||
</changeSet>
|
||||
|
||||
<include file="2024-01-20-create-merge-request-approvals.xml" relativeToChangelogFile="true"/>
|
||||
|
||||
</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