Рабочий вариант с ответами
This commit is contained in:
parent
adb5c6124f
commit
82a730c616
@ -36,6 +36,7 @@ public class SchedulerService {
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void newDiscussion() {
|
||||
discussionParser.scanOldDiscussions();
|
||||
discussionParser.scanNewDiscussion();
|
||||
}
|
||||
|
||||
|
@ -41,4 +41,5 @@ gitlab-bot:
|
||||
url-pipeline: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines/{1,number,#}"
|
||||
url-commit: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/commits?&page=1&per_page=1"
|
||||
url-new-note: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions/{2}/notes?body={3}"
|
||||
url-discussion: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions?&page={2,number,integer}&per_page=100"
|
||||
url-discussion: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions?&page={2,number,integer}&per_page=100"
|
||||
url-one-discussion: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions/{2}"
|
@ -173,9 +173,6 @@
|
||||
</column>
|
||||
<column name="noteable_iid" type="int"/>
|
||||
<column name="web_url" type="varchar(300)"/>
|
||||
<column name="responsible_id" type="integer">
|
||||
<constraints foreignKeyName="note_responsible_id_person_id" references="person(id)"/>
|
||||
</column>
|
||||
<column name="discussion_id" type="varchar(200)">
|
||||
<constraints foreignKeyName="note_discussion_id" references="discussion(id)" deleteCascade="true"/>
|
||||
</column>
|
||||
|
@ -8,6 +8,7 @@ import org.sadtech.haiti.context.domain.BasicEntity;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
@ -46,6 +47,7 @@ public class Discussion implements BasicEntity<String> {
|
||||
|
||||
@OneToMany(
|
||||
mappedBy = "discussion",
|
||||
fetch = FetchType.EAGER,
|
||||
cascade = {
|
||||
CascadeType.PERSIST,
|
||||
CascadeType.MERGE
|
||||
|
@ -55,6 +55,9 @@ public class Note implements BasicEntity<Long> {
|
||||
@Column(name = "web_url")
|
||||
private String webUrl;
|
||||
|
||||
@Column(name = "resolvable")
|
||||
private boolean resolvable;
|
||||
|
||||
@Column(name = "resolved")
|
||||
private Boolean resolved;
|
||||
|
||||
|
@ -58,4 +58,6 @@ public class GitlabProperty {
|
||||
|
||||
private String urlDiscussion;
|
||||
|
||||
private String urlOneDiscussion;
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public class NoteJsonConvert implements Converter<NoteJson, Note> {
|
||||
note.setNoteableIid(source.getNoteableIid());
|
||||
note.setSystem(source.isSystem());
|
||||
note.setResolved(source.getResolved());
|
||||
note.setResolvable(source.isResolvable());
|
||||
if (source.getResolvedBy() != null) {
|
||||
note.setResolvedBy(personConverter.convert(source.getResolvedBy()));
|
||||
}
|
||||
|
@ -69,10 +69,13 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
|
||||
|
||||
@Override
|
||||
public Discussion update(@NonNull Discussion discussion) {
|
||||
final Map<Long, Note> noteMap = discussionRepository.findById(discussion.getId()).orElseThrow(() -> new NotFoundException("Дискуссия не найдена"))
|
||||
final Discussion oldDiscussion = discussionRepository.findById(discussion.getId()).orElseThrow(() -> new NotFoundException("Дискуссия не найдена"));
|
||||
final Map<Long, Note> noteMap = oldDiscussion
|
||||
.getNotes().stream()
|
||||
.collect(Collectors.toMap(Note::getId, note -> note));
|
||||
|
||||
discussion.setMergeRequest(oldDiscussion.getMergeRequest());
|
||||
discussion.setResponsible(oldDiscussion.getResponsible());
|
||||
discussion.getNotes().forEach(note -> updateNote(note, noteMap));
|
||||
|
||||
return discussionRepository.save(discussion);
|
||||
@ -81,9 +84,9 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
|
||||
private void updateNote(Note note, Map<Long, Note> noteMap) {
|
||||
if (noteMap.containsKey(note.getId())) {
|
||||
final Note oldNote = noteMap.get(note.getId());
|
||||
if (!oldNote.getUpdated().equals(note.getUpdated())) {
|
||||
note.setWebUrl(oldNote.getWebUrl());
|
||||
}
|
||||
note.setWebUrl(oldNote.getWebUrl());
|
||||
} else {
|
||||
notificationPersonal(note);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
|
||||
import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.DiscussionJson;
|
||||
import org.sadtech.haiti.context.domain.ExistsContainer;
|
||||
import org.sadtech.haiti.context.exception.ConvertException;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.core.page.PaginationImpl;
|
||||
import org.sadtech.haiti.utils.network.HttpParse;
|
||||
@ -104,4 +105,27 @@ public class DiscussionParser {
|
||||
.executeList(DiscussionJson.class);
|
||||
}
|
||||
|
||||
public void scanOldDiscussions() {
|
||||
int page = 0;
|
||||
Sheet<Discussion> discussionSheet = discussionService.getAll(PaginationImpl.of(page, 100));
|
||||
|
||||
while (discussionSheet.hasContent()) {
|
||||
final List<Discussion> discussions = discussionSheet.getContent();
|
||||
|
||||
for (Discussion discussion : discussions) {
|
||||
final Discussion newDiscussion = HttpParse.request(MessageFormat.format(gitlabProperty.getUrlOneDiscussion(), discussion.getMergeRequest().getProjectId(), discussion.getMergeRequest().getTwoId(), discussion.getId()))
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.execute(DiscussionJson.class)
|
||||
.map(json -> conversionService.convert(json, Discussion.class))
|
||||
.orElseThrow(() -> new ConvertException("Ошибка парсинга дискуссии"));
|
||||
discussionService.update(newDiscussion);
|
||||
}
|
||||
|
||||
discussionSheet = discussionService.getAll(PaginationImpl.of(++page, 100));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class NoteJson {
|
||||
@JsonProperty("noteable_type")
|
||||
private String noteableType;
|
||||
|
||||
private Boolean resolvable;
|
||||
private boolean resolvable;
|
||||
|
||||
private Boolean resolved;
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class UnitConfig {
|
||||
final String discussionId = note.getDiscussion().getId();
|
||||
discussionService.answer(discussionId, MessageFormat.format("@{0}, {1}", note.getAuthor().getUserName(), message.getText()));
|
||||
}
|
||||
return BoxAnswer.of("Победа");
|
||||
return BoxAnswer.of("");
|
||||
}
|
||||
}
|
||||
return BoxAnswer.of("Ошибка");
|
||||
|
Loading…
Reference in New Issue
Block a user