diff --git a/bot-app/src/main/resources/application.yaml b/bot-app/src/main/resources/application.yaml
index c55905f..12bd763 100644
--- a/bot-app/src/main/resources/application.yaml
+++ b/bot-app/src/main/resources/application.yaml
@@ -22,12 +22,7 @@ telegram-config:
bot-username: ${TELEGRAM_BOT_USERNAME}
bot-token: ${TELEGRAM_BOT_TOKEN}
gitlab-bot:
- version: 2.15.3
- scheduler:
- comment:
- settings:
- no-comment-count: 20
- comment-count: 100
+ version: 0.0.2 Beta
person:
telegram-id: ${TELEGRAM_PERSON_ID}
token: ${GITLAB_PERSONAL_TOKEN}
@@ -35,15 +30,16 @@ 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,number,integer}/notes?&page={2, number, integer}&per_page=100"
+ 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,#}"
- url-pipelines: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines?&page={1,number,integer}&per_page=100"
- url-pipeline: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines/{1,number,integer}"
+ url-pipelines: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines?&page={1,number,#}&per_page=100"
+ 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"
teamcity:
token: ${TEAMCITY_ADMIN_TOKEN}
project-url: ${TEAMCITY_URL}/app/rest/projects
diff --git a/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml
index df4999b..888a700 100644
--- a/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml
+++ b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml
@@ -189,4 +189,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java
index 9568ebc..8658518 100644
--- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java
+++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java
@@ -87,6 +87,9 @@ public class MergeRequest implements BasicEntity {
@Column(name = "label")
private Set labels = new HashSet<>();
+ @Column(name = "date_last_commit")
+ private LocalDateTime dateLastCommit;
+
// @JoinTable
// @OneToMany(fetch = FetchType.LAZY)
// private List notes = new ArrayList<>();
diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/TaskRepository.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/TaskRepository.java
index 47705e5..a803a2e 100644
--- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/TaskRepository.java
+++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/TaskRepository.java
@@ -6,8 +6,12 @@ import org.sadtech.haiti.context.page.Pagination;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
+import java.util.List;
+
public interface TaskRepository extends SimpleManagerRepository {
Sheet findAllByResolved(boolean resolved, @NonNull Pagination pagination);
+ List findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved);
+
}
diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/TaskService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/TaskService.java
index 795a9ed..40ab0cf 100644
--- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/TaskService.java
+++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/TaskService.java
@@ -6,8 +6,12 @@ import org.sadtech.haiti.context.page.Pagination;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.context.service.SimpleManagerService;
+import java.util.List;
+
public interface TaskService extends SimpleManagerService {
Sheet getAllByResolved(boolean resolved, @NonNull Pagination pagination);
+ List getAllPersonTask(@NonNull Long userId, boolean resolved);
+
}
diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/AppProperty.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/AppProperty.java
index 09008bf..66ea171 100644
--- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/AppProperty.java
+++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/AppProperty.java
@@ -13,7 +13,7 @@ import org.springframework.context.annotation.Configuration;
@Getter
@Setter
@Configuration
-@ConfigurationProperties(prefix = "bitbucketbot")
+@ConfigurationProperties(prefix = "gitlab-bot")
public class AppProperty {
private String version;
diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java
index 80cfb2a..b6080f9 100644
--- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java
+++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java
@@ -52,4 +52,6 @@ public class GitlabProperty {
private String urlPipeline;
+ private String urlCommit;
+
}
diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java
index 674e18d..d2247b3 100644
--- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java
+++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java
@@ -66,9 +66,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService new NotFoundException("Проект не найден"));
@@ -120,7 +121,10 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService implements NoteService {
private final NoteRepository noteRepository;
+ private final PersonService personService;
public NoteServiceImpl(
NoteRepository noteRepository,
NotifyService notifyService,
- PersonInformation personInformation
- ) {
+ PersonInformation personInformation,
+ PersonService personService) {
super(noteRepository, notifyService, personInformation);
this.noteRepository = noteRepository;
+ this.personService = personService;
}
@Override
public Note create(@NonNull Note note) {
+ personService.create(note.getAuthor());
+
final Note newNote = noteRepository.save(note);
notificationPersonal(note);
return newNote;
diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/note/TaskServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/note/TaskServiceImpl.java
index 968c75d..c4ff04f 100644
--- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/note/TaskServiceImpl.java
+++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/note/TaskServiceImpl.java
@@ -7,37 +7,54 @@ import org.sadtech.bot.gitlab.context.domain.notify.task.TaskCloseNotify;
import org.sadtech.bot.gitlab.context.domain.notify.task.TaskNewNotify;
import org.sadtech.bot.gitlab.context.repository.TaskRepository;
import org.sadtech.bot.gitlab.context.service.NotifyService;
+import org.sadtech.bot.gitlab.context.service.PersonService;
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;
+import java.util.List;
+
@Service
public class TaskServiceImpl extends AbstractNoteService implements TaskService {
private final TaskRepository taskRepository;
private final NotifyService notifyService;
private final PersonInformation personInformation;
+ private final PersonService personService;
public TaskServiceImpl(
TaskRepository taskRepository,
NotifyService notifyService,
- PersonInformation personInformation) {
+ PersonInformation personInformation,
+ PersonService personService
+ ) {
super(taskRepository, notifyService, personInformation);
this.taskRepository = taskRepository;
this.notifyService = notifyService;
this.personInformation = personInformation;
+ this.personService = personService;
}
@Override
public Task create(@NonNull Task task) {
+ createPerson(task);
+
final Task newTask = taskRepository.save(task);
notifyNewTask(task);
notificationPersonal(task);
return newTask;
}
+ private void createPerson(@NonNull Task task) {
+ personService.create(task.getAuthor());
+ if (task.getResolvedBy() != null) {
+ personService.create(task.getResolvedBy());
+ }
+ personService.create(task.getResponsible());
+ }
+
@Override
public Task update(@NonNull Task task) {
final Task oldTask = taskRepository.findById(task.getId())
@@ -92,4 +109,9 @@ public class TaskServiceImpl extends AbstractNoteService implements TaskSe
return taskRepository.findAllByResolved(resolved, pagination);
}
+ @Override
+ public List getAllPersonTask(@NonNull Long userId, boolean resolved) {
+ return taskRepository.findAllByResponsibleIdAndResolved(userId, resolved);
+ }
+
}
diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java
index 5f4d63e..29d2af4 100644
--- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java
+++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java
@@ -10,6 +10,7 @@ import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
import org.sadtech.bot.gitlab.context.service.ProjectService;
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.CommitJson;
import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson;
import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.context.exception.NotFoundException;
@@ -55,7 +56,11 @@ public class MergeRequestParser {
.header(ACCEPT)
.header(AUTHORIZATION, BEARER + personProperty.getToken())
.execute(MergeRequestJson.class)
- .map(json -> conversionService.convert(json, MergeRequest.class))
+ .map(json -> {
+ final MergeRequest newMergeRequest = conversionService.convert(json, MergeRequest.class);
+ parsingCommits(newMergeRequest);
+ return newMergeRequest;
+ })
.orElseThrow(() -> new NotFoundException("МержРеквест не найден, возможно удален"));
mergeRequestsService.update(mergeRequest);
}
@@ -93,8 +98,13 @@ public class MergeRequestParser {
if (!existsContainer.isAllFound()) {
final List newMergeRequests = mergeRequestJsons.stream()
.filter(json -> existsContainer.getIdNoFound().contains(json.getId()))
- .map(json -> conversionService.convert(json, MergeRequest.class))
+ .map(json -> {
+ final MergeRequest mergeRequest = conversionService.convert(json, MergeRequest.class);
+ parsingCommits(mergeRequest);
+ return mergeRequest;
+ })
.collect(Collectors.toList());
+
mergeRequestsService.createAll(newMergeRequests);
}
@@ -102,6 +112,16 @@ public class MergeRequestParser {
}
}
+ private void parsingCommits(MergeRequest mergeRequest) {
+ final List commitJson = HttpParse.request(
+ MessageFormat.format(gitlabProperty.getUrlCommit(), mergeRequest.getProjectId(), mergeRequest.getTwoId())
+ )
+ .header(ACCEPT)
+ .header(AUTHORIZATION, BEARER + personProperty.getToken())
+ .executeList(CommitJson.class);
+ mergeRequest.setDateLastCommit(commitJson.get(0).getCreatedDate());
+ }
+
private List getMergeRequestJsons(Project project, int page) {
return HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequestOpen(), project.getId(), page))
.header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken()))
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/TaskRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/TaskRepositoryImpl.java
index 763f330..7c618da 100644
--- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/TaskRepositoryImpl.java
+++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/TaskRepositoryImpl.java
@@ -10,6 +10,8 @@ import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerReposi
import org.sadtech.haiti.database.util.Converter;
import org.springframework.stereotype.Repository;
+import java.util.List;
+
@Repository
public class TaskRepositoryImpl extends AbstractSimpleManagerRepository implements TaskRepository {
@@ -26,4 +28,9 @@ public class TaskRepositoryImpl extends AbstractSimpleManagerRepository findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) {
+ return taskRepositoryJpa.findAllByResponsibleIdAndResolved(userId, resolved);
+ }
}
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/TaskRepositoryJpa.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/TaskRepositoryJpa.java
index ff51647..69b9534 100644
--- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/TaskRepositoryJpa.java
+++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/TaskRepositoryJpa.java
@@ -5,8 +5,12 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
+import java.util.List;
+
public interface TaskRepositoryJpa extends JpaRepository {
Page findAllByResolved(boolean resolved, Pageable pageable);
+ List findAllByResponsibleIdAndResolved(Long responsibleId, boolean resolved);
+
}
diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/CommitJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/CommitJson.java
new file mode 100644
index 0000000..ab6377c
--- /dev/null
+++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/CommitJson.java
@@ -0,0 +1,27 @@
+package org.sadtech.bot.gitlab.sdk.domain;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * // TODO: 19.01.2021 Добавить описание.
+ *
+ * @author upagge 19.01.2021
+ */
+@Data
+public class CommitJson {
+
+ private String id;
+
+ @JsonSerialize(using = LocalDateTimeSerializer.class)
+ @JsonDeserialize(using = LocalDateTimeDeserializer.class)
+ @JsonProperty("created_at")
+ private LocalDateTime createdDate;
+
+}
diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestStateJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestStateJson.java
index 946b713..6bdbb22 100644
--- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestStateJson.java
+++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestStateJson.java
@@ -15,7 +15,7 @@ public enum MergeRequestStateJson {
CLOSED,
@JsonProperty("locked")
LOCKED,
- @JsonProperty("merger")
+ @JsonProperty("merged")
MERGED
}
diff --git a/pom.xml b/pom.xml
index 6dc4287..6d36c21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,7 +78,7 @@
1.8
3.0.1-RELEASE
- 3.0.1-RELEASE
+ 1.0.0-SNAPSHOT
3.0.1-RELEASE
3.0.1-RELEASE
3.0.1-RELEASE
diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/StartNotify.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/StartNotify.java
new file mode 100644
index 0000000..c5e18eb
--- /dev/null
+++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/StartNotify.java
@@ -0,0 +1,38 @@
+package org.sadtech.bot.gitlab.telegram.service;
+
+import lombok.RequiredArgsConstructor;
+import org.sadtech.bot.gitlab.context.domain.notify.SimpleTextNotify;
+import org.sadtech.bot.gitlab.context.service.AppSettingService;
+import org.sadtech.bot.gitlab.context.service.NotifyService;
+import org.sadtech.bot.gitlab.core.config.properties.AppProperty;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * // TODO: 19.01.2021 Добавить описание.
+ *
+ * @author upagge 19.01.2021
+ */
+@Component
+@RequiredArgsConstructor
+public class StartNotify {
+
+ private final NotifyService notifyService;
+ private final AppProperty appProperty;
+ private final AppSettingService settingService;
+
+ @PostConstruct
+ public void sendStartNotification() {
+ if (!settingService.isFirstStart()) {
+ notifyService.send(
+ SimpleTextNotify.builder()
+ .message("Привет. Желаю продуктивного дня :)" +
+ "\n-- -- -- -- --\n" +
+ "Version " + appProperty.getVersion() + " | Developer: [uPagge](https://uPagge.ru)")
+ .build()
+ );
+ }
+ }
+
+}
diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java
index b0e0f12..4dae814 100644
--- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java
+++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java
@@ -1,6 +1,9 @@
package org.sadtech.bot.gitlab.telegram.unit;
+import org.sadtech.bot.gitlab.context.domain.PersonInformation;
+import org.sadtech.bot.gitlab.context.domain.entity.Note;
import org.sadtech.bot.gitlab.context.service.AppSettingService;
+import org.sadtech.bot.gitlab.context.service.TaskService;
import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
import org.sadtech.bot.gitlab.core.service.parser.ProjectParser;
import org.sadtech.social.bot.domain.unit.AnswerText;
@@ -29,7 +32,8 @@ public class MenuConfig {
public AnswerText menu(
AppSettingService settingService,
AnswerText settings,
- AnswerText textAddNewProject
+ AnswerText textAddNewProject,
+ AnswerText getTasks
) {
return AnswerText.builder()
.boxAnswer(message ->
@@ -66,6 +70,7 @@ public class MenuConfig {
)
.nextUnit(settings)
.nextUnit(textAddNewProject)
+ .nextUnit(getTasks)
.build();
}
@@ -114,4 +119,24 @@ public class MenuConfig {
.build();
}
+ @Bean
+ public AnswerText getTasks(
+ TaskService taskService,
+ AppSettingService settingService,
+ PersonInformation personInformation
+ ) {
+ return AnswerText.builder()
+ .boxAnswer(message ->
+ {
+ final Long userId = personInformation.getId();
+ final String text = taskService.getAllPersonTask(userId, false).stream()
+// .collect(Collectors.groupingBy())
+ .map(Note::getBody)
+ .collect(Collectors.joining("\n"));
+ return BoxAnswer.of(text);
+ })
+ .phrase(settingService.getMessage("ui.menu.task"))
+ .build();
+ }
+
}
diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/utils/GeneratorKeyBoards.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/utils/GeneratorKeyBoards.java
deleted file mode 100644
index 8eb7ec5..0000000
--- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/utils/GeneratorKeyBoards.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.sadtech.bot.gitlab.telegram.utils;
-
-import org.springframework.context.annotation.Configuration;
-
-/**
- * // TODO: 20.09.2020 Добавить описание.
- *
- * @author upagge 20.09.2020
- */
-@Configuration
-public class GeneratorKeyBoards {
-
-
-}