release-0.0.2
This commit is contained in:
parent
167843d8b2
commit
c0188f59ea
@ -35,4 +35,9 @@ public class SchedulerService {
|
||||
noteParser.scanNewCommentAndTask();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void oldTaskParser() {
|
||||
noteParser.scanOldTask();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,12 +35,13 @@ gitlab-bot:
|
||||
url-project: ${GITLAB_URL}/api/v4/projects?page={0, number, integer}&per_page=100
|
||||
url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests?state=opened&page={1, number, integer}&per_page=100
|
||||
url-pull-request-close: ${GITLAB_URL}
|
||||
url-pull-request-comment: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests/{1}/notes
|
||||
url-pull-request-comment: "${GITLAB_URL}/api/v4/projects/{0,number,integer}/merge_requests/{1,number,integer}/notes?&page={2, number, integer}&per_page=100"
|
||||
url-pull-request: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests/{1, number, integer}?page={2, number, integer}&per_page=100
|
||||
url-merge-request-add: ${GITLAB_URL}/api/v4/projects/{0}%2F{1}
|
||||
user-url: ${GITLAB_URL}/api/v4/user
|
||||
users-url: ${GITLAB_URL}/api/v4/users
|
||||
url-note: "{0}#note_{1,number,#}"
|
||||
url-note-api: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes/{2,number,#}"
|
||||
teamcity:
|
||||
token: ${TEAMCITY_ADMIN_TOKEN}
|
||||
project-url: ${TEAMCITY_URL}/app/rest/projects
|
||||
|
@ -156,10 +156,11 @@
|
||||
<createTable tableName="merge_request_notes">
|
||||
<column name="merge_request_id" type="int">
|
||||
<constraints nullable="false" foreignKeyName="merge_request_notes_merge_request_id"
|
||||
references="note(id)" deleteCascade="true"/>
|
||||
references="merge_request(id)" deleteCascade="true"/>
|
||||
</column>
|
||||
<column name="notes_id" type="int">
|
||||
<constraints nullable="false" foreignKeyName="merge_request_notes_note_id" references="note(id)"/>
|
||||
<constraints nullable="false" foreignKeyName="merge_request_notes_note_id" references="note(id)"
|
||||
deleteCascade="true"/>
|
||||
</column>
|
||||
</createTable>
|
||||
|
||||
|
@ -4,7 +4,7 @@ ui.lang_changed=Language changed successfully
|
||||
ui.monitor_private_projects=Start tracking private projects?
|
||||
ui.monitor_project_private_success=Projects have been successfully added to tracking
|
||||
ui.monitor_owner_projects=Start tracking public projects that you own?
|
||||
ui.setup_finished=Configuration completed successfully
|
||||
ui.setup_finished=Configuration completed successfully\n-- -- -- -- --\nDeveloper: [uPagge](https://uPagge.ru)
|
||||
ui.menu.header=This is the bot menu, select a new item
|
||||
ui.menu.task=My tasks
|
||||
ui.menu.mr=Merge Request
|
||||
|
@ -4,7 +4,7 @@ ui.lang_changed=Язык успешно изменен
|
||||
ui.monitor_private_projects=Начать отслеживать приватные проекты?
|
||||
ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание
|
||||
ui.monitor_owner_projects=Начать отслеживать публичные проекты, владельцем которых вы являетесь?
|
||||
ui.setup_finished=Настройка успешно завершена
|
||||
ui.setup_finished=Настройка успешно завершена\n-- -- -- -- --\nРазработчик: [uPagge](https://uPagge.ru)
|
||||
ui.menu.header=Это меню бота, выберите новый пункт
|
||||
ui.menu.task=Мои задачи
|
||||
ui.menu.mr=Merge Request
|
||||
|
@ -12,17 +12,12 @@ import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -92,8 +87,8 @@ public class MergeRequest implements BasicEntity<Long> {
|
||||
@Column(name = "label")
|
||||
private Set<String> labels = new HashSet<>();
|
||||
|
||||
@JoinTable
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
private List<Note> notes = new ArrayList<>();
|
||||
// @JoinTable
|
||||
// @OneToMany(fetch = FetchType.LAZY)
|
||||
// private List<Note> notes = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
@ -62,4 +63,12 @@ public class Note implements BasicEntity<Long> {
|
||||
@Column(name = "web_url")
|
||||
private String webUrl;
|
||||
|
||||
@ManyToOne
|
||||
@JoinTable(
|
||||
name = "merge_request_notes",
|
||||
joinColumns = @JoinColumn(name = "notes_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "merge_request_id")
|
||||
)
|
||||
private MergeRequest mergeRequest;
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.sadtech.bot.gitlab.context.repository;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
@ -10,4 +11,6 @@ import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
*/
|
||||
public interface NoteRepository extends SimpleManagerRepository<Note, Long> {
|
||||
|
||||
void link(@NonNull Long noteId, @NonNull Long mergeRequestId);
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package org.sadtech.bot.gitlab.context.repository;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.haiti.context.page.Pagination;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
public interface TaskRepository extends SimpleManagerRepository<Task, Long> {
|
||||
|
||||
Sheet<Task> findAllByResolved(boolean resolved, @NonNull Pagination pagination);
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package org.sadtech.bot.gitlab.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.haiti.context.service.SimpleManagerService;
|
||||
|
||||
public interface NoteService extends SimpleManagerService<Note, Long> {
|
||||
|
||||
void link(@NonNull Long noteId, Long mergeRequestId);
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package org.sadtech.bot.gitlab.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.haiti.context.page.Pagination;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.context.service.SimpleManagerService;
|
||||
|
||||
public interface TaskService extends SimpleManagerService<Task, Long> {
|
||||
|
||||
Sheet<Task> getAllByResolved(boolean resolved, @NonNull Pagination pagination);
|
||||
|
||||
}
|
||||
|
@ -46,4 +46,6 @@ public class GitlabProperty {
|
||||
|
||||
private String urlNote;
|
||||
|
||||
private String urlNoteApi;
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class NoteServiceImpl extends AbstractNoteService<Note> implements NoteSe
|
||||
|
||||
if (!oldNote.getUpdated().equals(note.getUpdated())) {
|
||||
note.setWebUrl(oldNote.getWebUrl());
|
||||
return noteRepository.save(oldNote);
|
||||
return noteRepository.save(note);
|
||||
}
|
||||
// updateAnswer(oldNote, note);
|
||||
|
||||
@ -70,4 +70,9 @@ public class NoteServiceImpl extends AbstractNoteService<Note> implements NoteSe
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link(@NonNull Long noteId, @NonNull Long mergeRequestId) {
|
||||
noteRepository.link(noteId, mergeRequestId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import org.sadtech.bot.gitlab.context.repository.TaskRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
import org.sadtech.bot.gitlab.context.service.TaskService;
|
||||
import org.sadtech.haiti.context.exception.NotFoundException;
|
||||
import org.sadtech.haiti.context.page.Pagination;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@ -41,14 +43,15 @@ public class TaskServiceImpl extends AbstractNoteService<Task> implements TaskSe
|
||||
final Task oldTask = taskRepository.findById(task.getId())
|
||||
.orElseThrow(() -> new NotFoundException("Задача не найдена"));
|
||||
|
||||
if (oldTask.getUpdated().equals(task.getUpdated())) {
|
||||
if (!oldTask.getUpdated().equals(task.getUpdated())) {
|
||||
|
||||
task.setMergeRequest(oldTask.getMergeRequest());
|
||||
task.setWebUrl(oldTask.getWebUrl());
|
||||
task.setResponsible(oldTask.getResponsible());
|
||||
|
||||
notifyUpdateStatus(oldTask, task);
|
||||
|
||||
return taskRepository.save(oldTask);
|
||||
return taskRepository.save(task);
|
||||
}
|
||||
return oldTask;
|
||||
}
|
||||
@ -56,8 +59,6 @@ public class TaskServiceImpl extends AbstractNoteService<Task> implements TaskSe
|
||||
private void notifyUpdateStatus(Task oldTask, Task task) {
|
||||
if (
|
||||
personInformation.getId().equals(oldTask.getAuthor().getId())
|
||||
&& !personInformation.getId().equals(oldTask.getResolvedBy().getId())
|
||||
|
||||
) {
|
||||
final boolean oldStatus = oldTask.getResolved();
|
||||
final boolean newStatus = task.getResolved();
|
||||
@ -86,4 +87,9 @@ public class TaskServiceImpl extends AbstractNoteService<Task> implements TaskSe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet<Task> getAllByResolved(boolean resolved, @NonNull Pagination pagination) {
|
||||
return taskRepository.findAllByResolved(resolved, pagination);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.sadtech.bot.gitlab.core.service.parser;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
@ -11,6 +10,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.NoteJson;
|
||||
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;
|
||||
@ -122,7 +122,8 @@ public class NoteParser {
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
taskService.createAll(newNotes);
|
||||
final List<Task> newTasks = taskService.createAll(newNotes);
|
||||
newTasks.forEach(task -> noteService.link(task.getId(), mergeRequest.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@ public class NoteParser {
|
||||
final ExistsContainer<Note, Long> existsContainer = noteService.existsById(jsonIds);
|
||||
|
||||
if (!existsContainer.isAllFound()) {
|
||||
final List<Note> newNotes = newJsons.stream()
|
||||
final List<Note> notes = newJsons.stream()
|
||||
.filter(json -> existsContainer.getIdNoFound().contains(json.getId()))
|
||||
.map(json -> conversionService.convert(json, Note.class))
|
||||
.peek(note -> note.setWebUrl(
|
||||
@ -146,7 +147,36 @@ public class NoteParser {
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
noteService.createAll(newNotes);
|
||||
final List<Note> newNotes = noteService.createAll(notes);
|
||||
newNotes.forEach(note -> noteService.link(note.getId(), mergeRequest.getId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void scanOldTask() {
|
||||
int page = 0;
|
||||
Sheet<Task> taskSheet = taskService.getAllByResolved(false, PaginationImpl.of(page, COUNT));
|
||||
|
||||
while (taskSheet.hasContent()) {
|
||||
final List<Task> tasks = taskSheet.getContent();
|
||||
|
||||
for (Task task : tasks) {
|
||||
final MergeRequest mergeRequest = task.getMergeRequest();
|
||||
final Task newTask = HttpParse.request(MessageFormat.format(
|
||||
gitlabProperty.getUrlNoteApi(),
|
||||
mergeRequest.getProjectId(),
|
||||
mergeRequest.getTwoId(),
|
||||
task.getId())
|
||||
)
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.execute(NoteJson.class)
|
||||
.map(json -> conversionService.convert(json, Task.class))
|
||||
.orElseThrow(() -> new ConvertException("Ошибка обработки задачи"));
|
||||
taskService.update(newTask);
|
||||
}
|
||||
|
||||
taskSheet = taskService.getAllByResolved(false, PaginationImpl.of(++page, COUNT));
|
||||
}
|
||||
|
||||
}
|
||||
@ -207,65 +237,4 @@ public class NoteParser {
|
||||
// .collect(Collectors.toList());
|
||||
// }
|
||||
|
||||
private String generateUrl(@NonNull Long id, @NonNull String pullRequestUrl) {
|
||||
return MessageFormat.format("{0}/overview?commentId={1}", pullRequestUrl, Long.toString(id));
|
||||
}
|
||||
|
||||
private String getCommentUrl(long commentId, MergeRequest mergeRequest) {
|
||||
// return gitlabProperty.getUrlPullRequestComment()
|
||||
// .replace("{projectKey}", mergeRequest.getProjectKey())
|
||||
// .replace("{repositorySlug}", mergeRequest.getRepositorySlug())
|
||||
// .replace("{pullRequestId}", mergeRequest.getBitbucketId().toString())
|
||||
// .replace("{commentId}", String.valueOf(commentId));
|
||||
return null;
|
||||
}
|
||||
|
||||
public void scanOldComment() {
|
||||
// final List<Comment> comments = commentService.getAllBetweenDate(
|
||||
// LocalDateTime.now().minusDays(20), LocalDateTime.now()
|
||||
// );
|
||||
// for (Comment oldComment : comments) {
|
||||
// final Optional<CommentJson> optCommentJson = Utils.urlToJson(
|
||||
// oldComment.getUrlApi(),
|
||||
// gitlabProperty.getToken(),
|
||||
// CommentJson.class
|
||||
// );
|
||||
// if (optCommentJson.isPresent()) {
|
||||
// final CommentJson json = optCommentJson.get();
|
||||
// if (Severity.BLOCKER.equals(json.getSeverity())) {
|
||||
// taskService.convert(oldComment);
|
||||
// } else {
|
||||
// final Comment newComment = conversionService.convert(json, Comment.class);
|
||||
// commentService.update(newComment);
|
||||
// }
|
||||
// } else {
|
||||
// commentService.deleteById(oldComment.getId());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void scanOldTask() {
|
||||
// final List<Task> tasks = taskService.getAllBetweenDate(
|
||||
// LocalDateTime.now().minusDays(20), LocalDateTime.now()
|
||||
// );
|
||||
// for (Task oldTask : tasks) {
|
||||
// final Optional<CommentJson> optCommentJson = Utils.urlToJson(
|
||||
// oldTask.getUrlApi(),
|
||||
// gitlabProperty.getToken(),
|
||||
// CommentJson.class
|
||||
// );
|
||||
// if (optCommentJson.isPresent()) {
|
||||
// final CommentJson json = optCommentJson.get();
|
||||
// if (Severity.NORMAL.equals(json.getSeverity())) {
|
||||
// commentService.convert(oldTask);
|
||||
// } else {
|
||||
// final Task newTask = conversionService.convert(json, Task.class);
|
||||
// taskService.update(newTask);
|
||||
// }
|
||||
// } else {
|
||||
// taskService.deleteById(oldTask.getId());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.sadtech.bot.gitlab.data.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.repository.NoteRepository;
|
||||
import org.sadtech.bot.gitlab.data.jpa.CommentRepositoryJpa;
|
||||
@ -21,4 +22,9 @@ public class NoteRepositoryImpl extends AbstractSimpleManagerRepository<Note, Lo
|
||||
this.repositoryJpa = repositoryJpa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link(@NonNull Long noteId, @NonNull Long mergeRequestId) {
|
||||
repositoryJpa.link(noteId, mergeRequestId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package org.sadtech.bot.gitlab.data.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.context.repository.TaskRepository;
|
||||
import org.sadtech.bot.gitlab.data.jpa.TaskRepositoryJpa;
|
||||
import org.sadtech.haiti.context.page.Pagination;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
||||
import org.sadtech.haiti.database.util.Converter;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@ -16,4 +20,10 @@ public class TaskRepositoryImpl extends AbstractSimpleManagerRepository<Task, Lo
|
||||
this.taskRepositoryJpa = taskRepositoryJpa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet<Task> findAllByResolved(boolean resolved, @NonNull Pagination pagination) {
|
||||
return Converter.page(
|
||||
taskRepositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,16 @@ package org.sadtech.bot.gitlab.data.jpa;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public interface CommentRepositoryJpa extends JpaRepository<Note, Long> {
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "INSERT INTO gitlab_bot.public.merge_request_notes(merge_request_id, notes_id) values (:mergeRequestId, :noteId)", nativeQuery = true)
|
||||
void link(@Param("noteId") Long noteId, @Param("mergeRequestId") Long mergeRequestId);
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package org.sadtech.bot.gitlab.data.jpa;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface TaskRepositoryJpa extends JpaRepository<Task, Long> {
|
||||
|
||||
Page<Task> findAllByResolved(boolean resolved, Pageable pageable);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user