0.0.2
This commit is contained in:
parent
ba5e70f8d5
commit
bb2be82b4c
@ -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
|
||||
|
@ -189,4 +189,10 @@
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="2020-01-19-create-table-commit" author="uPagge">
|
||||
<addColumn tableName="merge_request">
|
||||
<column name="date_last_commit" type="datetime"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
@ -87,6 +87,9 @@ public class MergeRequest implements BasicEntity<Long> {
|
||||
@Column(name = "label")
|
||||
private Set<String> labels = new HashSet<>();
|
||||
|
||||
@Column(name = "date_last_commit")
|
||||
private LocalDateTime dateLastCommit;
|
||||
|
||||
// @JoinTable
|
||||
// @OneToMany(fetch = FetchType.LAZY)
|
||||
// private List<Note> notes = new ArrayList<>();
|
||||
|
@ -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<Task, Long> {
|
||||
|
||||
Sheet<Task> findAllByResolved(boolean resolved, @NonNull Pagination pagination);
|
||||
|
||||
List<Task> findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved);
|
||||
|
||||
}
|
||||
|
@ -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<Task, Long> {
|
||||
|
||||
Sheet<Task> getAllByResolved(boolean resolved, @NonNull Pagination pagination);
|
||||
|
||||
List<Task> getAllPersonTask(@NonNull Long userId, boolean resolved);
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -52,4 +52,6 @@ public class GitlabProperty {
|
||||
|
||||
private String urlPipeline;
|
||||
|
||||
private String urlCommit;
|
||||
|
||||
}
|
||||
|
@ -66,9 +66,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
|
||||
final MergeRequest newMergeRequest = mergeRequestRepository.save(mergeRequest);
|
||||
|
||||
// if (!settingService.isFirstStart()) {
|
||||
notifyNewPr(newMergeRequest);
|
||||
// }
|
||||
|
||||
return newMergeRequest;
|
||||
}
|
||||
@ -104,7 +102,10 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
mergeRequest.setNotification(oldMergeRequest.getNotification());
|
||||
}
|
||||
|
||||
if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate())) {
|
||||
if (
|
||||
!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate())
|
||||
&& !personInformation.getId().equals(oldMergeRequest.getAuthor().getId())
|
||||
) {
|
||||
final Project project = projectService.getById(mergeRequest.getProjectId())
|
||||
.orElseThrow(() -> new NotFoundException("Проект не найден"));
|
||||
|
||||
@ -120,7 +121,10 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
}
|
||||
|
||||
private void notifyUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
|
||||
if (!personInformation.getId().equals(mergeRequest.getAuthor().getId())) {
|
||||
if (
|
||||
!personInformation.getId().equals(mergeRequest.getAuthor().getId())
|
||||
&& !oldMergeRequest.getDateLastCommit().equals(mergeRequest.getDateLastCommit())
|
||||
) {
|
||||
notifyService.send(
|
||||
UpdatePrNotify.builder()
|
||||
.author(oldMergeRequest.getAuthor().getName())
|
||||
|
@ -7,24 +7,29 @@ import org.sadtech.bot.gitlab.context.exception.NotFoundException;
|
||||
import org.sadtech.bot.gitlab.context.repository.NoteRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.NoteService;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
import org.sadtech.bot.gitlab.context.service.PersonService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class NoteServiceImpl extends AbstractNoteService<Note> 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;
|
||||
|
@ -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<Task> 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<Task> implements TaskSe
|
||||
return taskRepository.findAllByResolved(resolved, pagination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getAllPersonTask(@NonNull Long userId, boolean resolved) {
|
||||
return taskRepository.findAllByResponsibleIdAndResolved(userId, resolved);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<MergeRequest> 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> 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<MergeRequestJson> getMergeRequestJsons(Project project, int page) {
|
||||
return HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequestOpen(), project.getId(), page))
|
||||
.header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken()))
|
||||
|
@ -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<Task, Long> implements TaskRepository {
|
||||
|
||||
@ -26,4 +28,9 @@ public class TaskRepositoryImpl extends AbstractSimpleManagerRepository<Task, Lo
|
||||
taskRepositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) {
|
||||
return taskRepositoryJpa.findAllByResponsibleIdAndResolved(userId, resolved);
|
||||
}
|
||||
}
|
||||
|
@ -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<Task, Long> {
|
||||
|
||||
Page<Task> findAllByResolved(boolean resolved, Pageable pageable);
|
||||
|
||||
List<Task> findAllByResponsibleIdAndResolved(Long responsibleId, boolean resolved);
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ public enum MergeRequestStateJson {
|
||||
CLOSED,
|
||||
@JsonProperty("locked")
|
||||
LOCKED,
|
||||
@JsonProperty("merger")
|
||||
@JsonProperty("merged")
|
||||
MERGED
|
||||
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -78,7 +78,7 @@
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
||||
<gitlab.core.version>3.0.1-RELEASE</gitlab.core.version>
|
||||
<gitlab.app.version>3.0.1-RELEASE</gitlab.app.version>
|
||||
<gitlab.app.version>1.0.0-SNAPSHOT</gitlab.app.version>
|
||||
<gitlab.teamcity.version>3.0.1-RELEASE</gitlab.teamcity.version>
|
||||
<gitlab.teamcity.core.version>3.0.1-RELEASE</gitlab.teamcity.core.version>
|
||||
<gitlab.teamcity.sdk.version>3.0.1-RELEASE</gitlab.teamcity.sdk.version>
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user