diff --git a/.drone.yml b/.drone.yml index 23dc182..1682622 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,13 +3,17 @@ kind: pipeline type: docker name: develop build +image_pull_secrets: + - DOCKER_AUTH + trigger: branch: - develop services: - name: docker - image: docker:20.10.22-dind-alpine3.17 + # https://hub.docker.com/r/library/docker + image: hub.docker.struchkov.dev/docker:27.0.3-dind-alpine3.20 privileged: true volumes: - name: dockersock @@ -24,7 +28,8 @@ volumes: steps: - name: create jar - image: maven:3.8.6-eclipse-temurin-17 + # https://hub.docker.com/_/maven + image: hub.docker.struchkov.dev/maven:3.9-eclipse-temurin-17-alpine volumes: - name: m2 path: /root/.m2/repository @@ -32,26 +37,15 @@ steps: - mvn -U clean package - name: docker publish develop - image: upagge/docker-buildx:latest + image: docker.struchkov.dev/docker-buildx:latest environment: - STRUCHKOV_DOCKER_REGISTRY_TOKEN: - from_secret: STRUCHKOV_DOCKER_REGISTRY_TOKEN - STRUCHKOV_DOCKER_IMAGE_NAME: - from_secret: STRUCHKOV_DOCKER_IMAGE_NAME - DOCKER_REGISTRY_TOKEN: - from_secret: DOCKER_REGISTRY_TOKEN - DOCKER_IMAGE_NAME: - from_secret: DOCKER_IMAGE_NAME - DOCKER_REGISTRY_USER: from_secret: DOCKER_REGISTRY_USER volumes: - name: dockersock path: /var/run commands: - - echo "$STRUCHKOV_DOCKER_REGISTRY_TOKEN" | docker login git.struchkov.dev --username $DOCKER_REGISTRY_USER --password-stdin - - echo "$DOCKER_REGISTRY_TOKEN" | docker login docker.io --username $DOCKER_REGISTRY_USER --password-stdin - docker buildx create --use - - docker buildx build -f Dockerfile-develop --push --platform linux/amd64,linux/arm64/v8 -t "$DOCKER_IMAGE_NAME:develop" -t "git.struchkov.dev/$STRUCHKOV_DOCKER_IMAGE_NAME:develop" . + - docker buildx build -f Dockerfile-develop --push --platform linux/amd64,linux/arm64/v8 -t "docker.struchkov.dev/gitlab-notify:develop" . --- @@ -59,13 +53,17 @@ kind: pipeline type: docker name: release build +image_pull_secrets: + - DOCKER_AUTH + trigger: ref: - refs/tags/v.*.*.* services: - name: docker - image: docker:20.10.22-dind-alpine3.17 + # https://hub.docker.com/r/library/docker + image: hub.docker.struchkov.dev/docker:27.0.3-dind-alpine3.20 privileged: true volumes: - name: dockersock @@ -88,122 +86,111 @@ steps: - mvn -U clean package - name: docker publish release - image: upagge/docker-buildx:latest - environment: - STRUCHKOV_DOCKER_REGISTRY_TOKEN: - from_secret: STRUCHKOV_DOCKER_REGISTRY_TOKEN - STRUCHKOV_DOCKER_IMAGE_NAME: - from_secret: STRUCHKOV_DOCKER_IMAGE_NAME - DOCKER_REGISTRY_TOKEN: - from_secret: DOCKER_REGISTRY_TOKEN - DOCKER_IMAGE_NAME: - from_secret: DOCKER_IMAGE_NAME - DOCKER_REGISTRY_USER: - from_secret: DOCKER_REGISTRY_USER + image: docker.struchkov.dev/docker-buildx:latest volumes: - name: dockersock path: /var/run commands: - - echo "$STRUCHKOV_DOCKER_REGISTRY_TOKEN" | docker login git.struchkov.dev --username $DOCKER_REGISTRY_USER --password-stdin - - echo "$DOCKER_REGISTRY_TOKEN" | docker login docker.io --username $DOCKER_REGISTRY_USER --password-stdin - docker buildx create --use - - docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t "$DOCKER_IMAGE_NAME:latest" -t "$DOCKER_IMAGE_NAME:$DRONE_TAG" -t "git.struchkov.dev/$STRUCHKOV_DOCKER_IMAGE_NAME:latest" -t "git.struchkov.dev/$STRUCHKOV_DOCKER_IMAGE_NAME:$DRONE_TAG" . + - docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t "docker.struchkov.dev/gitlab-notify:latest" -t "docker.struchkov.dev/gitlab-notify:$DRONE_TAG" . ---- -kind: pipeline -type: docker -name: create-develop-docs-site +#--- +#kind: pipeline +#type: docker +#name: create-develop-docs-site +# +#trigger: +# branch: +# - develop +# - docs +# +#clone: +# disable: true +# +#steps: +# +# - name: build docs +# image: git.struchkov.dev/upagge/mkdocs-material-insiders:latest +# volumes: +# - name: mkdocs_cache +# path: ${DRONE_WORKSPACE}/documentation/ru/.cache +# environment: +# GIT_SSH: +# from_secret: GIT_SSH +# GIT_SSH_COMMAND: "ssh -i ~/.ssh/id_rsa -p 222" +# commands: +# - eval $(ssh-agent -s) +# - mkdir -p ~/.ssh +# - chmod 700 ~/.ssh +# - echo "$GIT_SSH" >> ~/.ssh/id_rsa +# - chmod 600 ~/.ssh/id_rsa +# - ssh-keyscan -p 222 git.struchkov.dev >> ~/.ssh/known_hosts +# - chmod 644 ~/.ssh/known_hosts +# - git config --global user.name "${DRONE_COMMIT_AUTHOR_NAME}" +# - git config --global user.email "${DRONE_COMMIT_AUTHOR_EMAIL}" +# - git clone ssh://git@git.struchkov.dev:222/Telegram-Bots/gitlab-notification.git . +# - git checkout $DRONE_COMMIT +# - cd documentation/ru +# - mike deploy --prefix gitlab-notification/ru --branch docs-deploy --push --update-aliases develop +# +#image_pull_secrets: +# - DOCKER_AUTH +# +#volumes: +# - name: mkdocs_cache +# host: +# path: /drone/volume/mkdocs_cache/gitlab_notification/ru +# +#--- +#kind: pipeline +#type: docker +#name: create-release-docs-site +# +#trigger: +# ref: +# - refs/tags/v.*.*.* +# +#clone: +# disable: true +# +#steps: +# +# - name: build docs +# image: git.struchkov.dev/upagge/mkdocs-material-insiders:latest +# volumes: +# - name: mkdocs_cache +# path: ${DRONE_WORKSPACE}/documentation/ru/.cache +# environment: +# GIT_SSH: +# from_secret: GIT_SSH +# GIT_SSH_COMMAND: "ssh -i ~/.ssh/id_rsa -p 222" +# commands: +# - eval $(ssh-agent -s) +# - mkdir -p ~/.ssh +# - chmod 700 ~/.ssh +# - echo "$GIT_SSH" >> ~/.ssh/id_rsa +# - chmod 600 ~/.ssh/id_rsa +# - ssh-keyscan -p 222 git.struchkov.dev >> ~/.ssh/known_hosts +# - chmod 644 ~/.ssh/known_hosts +# - git config --global user.name "${DRONE_COMMIT_AUTHOR_NAME}" +# - git config --global user.email "${DRONE_COMMIT_AUTHOR_EMAIL}" +# - git clone ssh://git@git.struchkov.dev:222/Telegram-Bots/gitlab-notification.git . +# - git checkout $DRONE_COMMIT +# - cd documentation/ru +# - mike deploy --prefix gitlab-notification/ru --branch docs-deploy --push --update-aliases ${DRONE_TAG} +# - mike deploy --prefix gitlab-notification/ru --branch docs-deploy --push --update-aliases latest +# +#image_pull_secrets: +# - DOCKER_AUTH +# +#volumes: +# - name: mkdocs_cache +# host: +# path: /drone/volume/mkdocs_cache/gitlab_notification\ -trigger: - branch: - - develop - - docs - -clone: - disable: true - -steps: - - - name: build docs - image: git.struchkov.dev/upagge/mkdocs-material-insiders:latest - volumes: - - name: mkdocs_cache - path: ${DRONE_WORKSPACE}/documentation/ru/.cache - environment: - GIT_SSH: - from_secret: GIT_SSH - GIT_SSH_COMMAND: "ssh -i ~/.ssh/id_rsa -p 222" - commands: - - eval $(ssh-agent -s) - - mkdir -p ~/.ssh - - chmod 700 ~/.ssh - - echo "$GIT_SSH" >> ~/.ssh/id_rsa - - chmod 600 ~/.ssh/id_rsa - - ssh-keyscan -p 222 git.struchkov.dev >> ~/.ssh/known_hosts - - chmod 644 ~/.ssh/known_hosts - - git config --global user.name "${DRONE_COMMIT_AUTHOR_NAME}" - - git config --global user.email "${DRONE_COMMIT_AUTHOR_EMAIL}" - - git clone ssh://git@git.struchkov.dev:222/Telegram-Bots/gitlab-notification.git . - - git checkout $DRONE_COMMIT - - cd documentation/ru - - mike deploy --prefix gitlab-notification/ru --branch docs-deploy --push --update-aliases develop - -image_pull_secrets: - - DOCKER_AUTH - -volumes: - - name: mkdocs_cache - host: - path: /drone/volume/mkdocs_cache/gitlab_notification/ru - ---- -kind: pipeline -type: docker -name: create-release-docs-site - -trigger: - ref: - - refs/tags/v.*.*.* - -clone: - disable: true - -steps: - - - name: build docs - image: git.struchkov.dev/upagge/mkdocs-material-insiders:latest - volumes: - - name: mkdocs_cache - path: ${DRONE_WORKSPACE}/documentation/ru/.cache - environment: - GIT_SSH: - from_secret: GIT_SSH - GIT_SSH_COMMAND: "ssh -i ~/.ssh/id_rsa -p 222" - commands: - - eval $(ssh-agent -s) - - mkdir -p ~/.ssh - - chmod 700 ~/.ssh - - echo "$GIT_SSH" >> ~/.ssh/id_rsa - - chmod 600 ~/.ssh/id_rsa - - ssh-keyscan -p 222 git.struchkov.dev >> ~/.ssh/known_hosts - - chmod 644 ~/.ssh/known_hosts - - git config --global user.name "${DRONE_COMMIT_AUTHOR_NAME}" - - git config --global user.email "${DRONE_COMMIT_AUTHOR_EMAIL}" - - git clone ssh://git@git.struchkov.dev:222/Telegram-Bots/gitlab-notification.git . - - git checkout $DRONE_COMMIT - - cd documentation/ru - - mike deploy --prefix gitlab-notification/ru --branch docs-deploy --push --update-aliases ${DRONE_TAG} - - mike deploy --prefix gitlab-notification/ru --branch docs-deploy --push --update-aliases latest - -image_pull_secrets: - - DOCKER_AUTH - -volumes: - - name: mkdocs_cache - host: - path: /drone/volume/mkdocs_cache/gitlab_notification +# drone sign --save Telegram-Bots/gitlab-notification --- kind: signature -hmac: cf1bd0800e8f6bb49dae0a6c5f607676b87d5ee713f4203f4f1ed08a17f71f68 +hmac: 0f4fa66591566ee4272ac8c36e887966037a407a1441575ef26e1813205a7ae8 ... diff --git a/Dockerfile b/Dockerfile index 4c4e97e..ae5aecf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17 as app-build +FROM eclipse-temurin:17 AS app-build ENV RELEASE=17 WORKDIR /opt/build diff --git a/Dockerfile-develop b/Dockerfile-develop index f1faba1..9341a57 100644 --- a/Dockerfile-develop +++ b/Dockerfile-develop @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17 as app-build +FROM eclipse-temurin:17 AS app-build ENV RELEASE=17 WORKDIR /opt/build diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AssigneeChanged.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AssigneeChanged.java index de57c81..32bce74 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AssigneeChanged.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/AssigneeChanged.java @@ -4,8 +4,7 @@ import dev.struchkov.bot.gitlab.context.domain.entity.Person; import lombok.Getter; import lombok.RequiredArgsConstructor; -import static dev.struchkov.haiti.utils.Checker.checkNotNull; -import static dev.struchkov.haiti.utils.Checker.checkNull; +import java.util.Optional; @Getter @RequiredArgsConstructor @@ -18,18 +17,18 @@ public enum AssigneeChanged { private final boolean changed; - public static AssigneeChanged valueOf(Long gitlabUserId, Person oldAssignee, Person newAssignee) { - if (checkNull(oldAssignee) && checkNotNull(newAssignee) && gitlabUserId.equals(newAssignee.getId())) { + public static AssigneeChanged valueOf(Long gitlabUserId, Optional oldAssignee, Optional newAssignee) { + if (oldAssignee.isEmpty() && newAssignee.isPresent() && gitlabUserId.equals(newAssignee.get().getId())) { return AssigneeChanged.BECOME; } - if (checkNotNull(oldAssignee) && checkNull(newAssignee) && gitlabUserId.equals(oldAssignee.getId())) { + if (oldAssignee.isPresent() && newAssignee.isEmpty() && gitlabUserId.equals(oldAssignee.get().getId())) { return AssigneeChanged.DELETED; } - if (checkNotNull(oldAssignee) && checkNotNull(newAssignee) && !oldAssignee.getId().equals(newAssignee.getId())) { - if (gitlabUserId.equals(oldAssignee.getId())) { + if (oldAssignee.isPresent() && newAssignee.isPresent() && !oldAssignee.get().getId().equals(newAssignee.get().getId())) { + if (gitlabUserId.equals(oldAssignee.get().getId())) { return AssigneeChanged.DELETED; } - if (gitlabUserId.equals(newAssignee.getId())) { + if (gitlabUserId.equals(newAssignee.get().getId())) { return AssigneeChanged.BECOME; } return AssigneeChanged.NOT_AFFECT_USER; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java index a296630..d463002 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java @@ -57,6 +57,9 @@ public class MergeRequest { @Column(name = "description") private String description; + @Column(name = "milestone") + private String milestone; + @Enumerated(EnumType.STRING) @Column(name = "state") private MergeRequestState state; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrNotify.java index 311da6e..4dd42cc 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrNotify.java @@ -20,9 +20,10 @@ public class ConflictMrNotify extends MrNotify { String name, String url, String projectKey, - String sourceBranch + String sourceBranch, + String milestone ) { - super(mrId, projectKey, name, url); + super(mrId, projectKey, name, url, milestone); this.sourceBranch = sourceBranch; } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrNotify.java index 7486f25..2a0c129 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrNotify.java @@ -20,9 +20,10 @@ public class ConflictResolveMrNotify extends MrNotify { String name, String url, String projectKey, - String sourceBranch + String sourceBranch, + String milestone ) { - super(mrId, projectKey, name, url); + super(mrId, projectKey, name, url, milestone); this.sourceBranch = sourceBranch; } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrNotify.java index 7fb9e4e..d4c7f0c 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrNotify.java @@ -10,17 +10,20 @@ public abstract class MrNotify implements Notify { protected final String projectName; protected final String title; protected final String url; + protected final String milestone; protected MrNotify( Long mrId, String projectName, String title, - String url + String url, + String milestone ) { this.mrId = mrId; this.projectName = projectName; this.title = title; this.url = url; + this.milestone = milestone; } } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java index 5c5747f..3a22ebc 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java @@ -33,7 +33,8 @@ public class NewMrForAssignee extends NewMrNotify { Set labels, @Singular List reviewers, String oldAssigneeName, - String newAssigneeName + String newAssigneeName, + String milestone ) { super( mrId, @@ -44,7 +45,8 @@ public class NewMrForAssignee extends NewMrNotify { projectName, targetBranch, sourceBranch, - labels + labels, + milestone ); this.reviewers = reviewers; this.oldAssigneeName = oldAssigneeName; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java index 74134d5..fe79ebe 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java @@ -27,7 +27,8 @@ public class NewMrForReview extends NewMrNotify { String targetBranch, String sourceBranch, Set labels, - String assignee + String assignee, + String milestone ) { super( mrId, @@ -38,7 +39,8 @@ public class NewMrForReview extends NewMrNotify { projectName, targetBranch, sourceBranch, - labels + labels, + milestone ); this.assignee = assignee; } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrNotify.java index 20c17ca..2183231 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrNotify.java @@ -22,9 +22,10 @@ public abstract class NewMrNotify extends MrNotify { String projectName, String targetBranch, String sourceBranch, - Set labels + Set labels, + String milestone ) { - super(mrId, projectName, title, url); + super(mrId, projectName, title, url, milestone); this.description = description; this.author = author; this.targetBranch = targetBranch; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrNotify.java index 743473c..22c80d4 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrNotify.java @@ -23,9 +23,10 @@ public class StatusMrNotify extends MrNotify { String url, String projectName, MergeRequestState oldStatus, - MergeRequestState newStatus + MergeRequestState newStatus, + String milestone ) { - super(mrId, projectName, name, url); + super(mrId, projectName, name, url, milestone); this.oldStatus = oldStatus; this.newStatus = newStatus; } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java index bb6bd54..61ec84f 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java @@ -30,9 +30,10 @@ public class UpdateMrNotify extends MrNotify { Long allResolvedTasks, Long personTasks, Long personResolvedTasks, - String comment + String comment, + String milestone ) { - super(mrId, projectName, name, url); + super(mrId, projectName, name, url, milestone); this.author = author; this.allTasks = allTasks; this.allResolvedTasks = allResolvedTasks; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java index cdbd037..86d0d05 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java @@ -22,6 +22,7 @@ public class Icons { public static final String BUILD = "⚙️"; public static final String LINK = "\uD83D\uDD17"; public static final String REVIEWER = "\uD83D\uDD0E"; + public static final String MILESTONE = "\uD83C\uDFAF"; public static final String PROJECT = "\uD83C\uDFD7"; public static final String DISABLE_NOTIFY = "\uD83D\uDD15"; public static final String YES = "✅"; diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java index 243b531..d966b17 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/convert/MergeRequestJsonConverter.java @@ -43,6 +43,10 @@ public class MergeRequestJsonConverter implements Converter optAssignee = getAssignee(mergeRequest); final Person author = mergeRequest.getAuthor(); - if (checkNotNull(assignee)) { + if (optAssignee.isPresent()) { + final Person assignee = optAssignee.get(); if (gitlabUserId.equals(assignee.getId()) && !isAuthorSameAssignee(author, assignee)) { return true; } @@ -116,20 +118,27 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { } private void sendNotifyNewMrReview(MergeRequest mergeRequest, String projectName) { - notifyService.send( - NewMrForReview.builder() - .mrId(mergeRequest.getId()) - .projectName(projectName) - .labels(mergeRequest.getLabels()) - .author(mergeRequest.getAuthor().getName()) - .description(mergeRequest.getDescription()) - .title(mergeRequest.getTitle()) - .url(mergeRequest.getWebUrl()) - .targetBranch(mergeRequest.getTargetBranch()) - .sourceBranch(mergeRequest.getSourceBranch()) - .assignee(mergeRequest.getAssignee().getName()) - .build() - ); + final NewMrForReview.NewMrForReviewBuilder builder = NewMrForReview.builder() + .mrId(mergeRequest.getId()) + .projectName(projectName) + .labels(mergeRequest.getLabels()) + .author(mergeRequest.getAuthor().getName()) + .milestone(mergeRequest.getMilestone()) + .description(mergeRequest.getDescription()) + .title(mergeRequest.getTitle()) + .url(mergeRequest.getWebUrl()) + .targetBranch(mergeRequest.getTargetBranch()) + .sourceBranch(mergeRequest.getSourceBranch()); + + getAssignee(mergeRequest) + .map(Person::getName) + .ifPresent(builder::assignee); + + notifyService.send(builder.build()); + } + + private Optional getAssignee(MergeRequest mergeRequest) { + return Optional.ofNullable(mergeRequest.getAssignee()); } private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName, String oldAssigneeName) { @@ -139,18 +148,20 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { .labels(mergeRequest.getLabels()) .author(mergeRequest.getAuthor().getName()) .description(mergeRequest.getDescription()) + .milestone(mergeRequest.getMilestone()) .title(mergeRequest.getTitle()) .url(mergeRequest.getWebUrl()) .targetBranch(mergeRequest.getTargetBranch()) .sourceBranch(mergeRequest.getSourceBranch()) + .milestone(mergeRequest.getMilestone()) .reviewers(mergeRequest.getReviewers().stream().map(Person::getName).toList()); if (checkNotNull(oldAssigneeName)) { builder.oldAssigneeName(oldAssigneeName); - if (checkNotNull(mergeRequest.getAssignee())) { - builder.newAssigneeName(mergeRequest.getAssignee().getName()); - } + getAssignee(mergeRequest) + .map(Person::getName) + .ifPresent(builder::newAssigneeName); } notifyService.send(builder.build()); @@ -165,7 +176,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { mergeRequest.setNotification(oldMergeRequest.isNotification()); final Long gitlabUserId = personInformation.getId(); - final AssigneeChanged assigneeChanged = AssigneeChanged.valueOf(gitlabUserId, oldMergeRequest.getAssignee(), mergeRequest.getAssignee()); + final AssigneeChanged assigneeChanged = AssigneeChanged.valueOf(gitlabUserId, getAssignee(oldMergeRequest), getAssignee(mergeRequest)); final ReviewerChanged reviewerChanged = ReviewerChanged.valueOf(gitlabUserId, oldMergeRequest.getReviewers(), mergeRequest.getReviewers()); mergeRequest.setUserAssignee(assigneeChanged.getNewStatus(oldMergeRequest.isUserAssignee())); @@ -173,8 +184,9 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { final boolean isChangedMr = !oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate()) || oldMergeRequest.isConflict() != mergeRequest.isConflict(); final boolean isChangedLinkedEntity = reviewerChanged.isChanged() || assigneeChanged.isChanged(); + final boolean isMilestone = !Objects.equals(oldMergeRequest.getMilestone(), mergeRequest.getMilestone()); - if (isChangedMr || isChangedLinkedEntity) { + if (isChangedMr || isChangedLinkedEntity || isMilestone) { if (oldMergeRequest.isNotification()) { final Project project = projectService.getByIdOrThrow(mergeRequest.getProjectId()); @@ -191,6 +203,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { notifyAssignee(assigneeChanged, oldMergeRequest, mergeRequest, project); } } + return repository.save(mergeRequest); } @@ -202,7 +215,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { private void notifyAssignee(AssigneeChanged assigneeChanged, MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) { switch (assigneeChanged) { case BECOME -> - sendNotifyNewAssignee(mergeRequest, project.getName(), Optional.ofNullable(oldMergeRequest.getAssignee()).map(Person::getName).orElse(null)); + sendNotifyNewAssignee(mergeRequest, project.getName(), getAssignee(oldMergeRequest).map(Person::getName).orElse(null)); } } //TODO [05.12.2022|uPagge]: Добавить уведомление, если происходит удаление ревьювера @@ -319,6 +332,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { .projectName(project.getName()) .url(oldMergeRequest.getWebUrl()) .allTasks(allTask) + .milestone(mergeRequest.getMilestone()) .allResolvedTasks(resolvedTask) .personTasks(allYouTasks) .personResolvedTasks(resolvedYouTask); @@ -345,6 +359,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { .name(mergeRequest.getTitle()) .url(mergeRequest.getWebUrl()) .projectKey(project.getName()) + .milestone(mergeRequest.getMilestone()) .build() ); } @@ -365,6 +380,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { .name(mergeRequest.getTitle()) .url(mergeRequest.getWebUrl()) .projectKey(project.getName()) + .milestone(mergeRequest.getMilestone()) .build() ); } @@ -388,6 +404,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { .projectName(project.getName()) .newStatus(newStatus) .oldStatus(oldStatus) + .milestone(newMergeRequest.getMilestone()) .build() ); } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java index 3c5d17b..739eab4 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java @@ -101,8 +101,9 @@ public class PipelineServiceImpl implements PipelineService { private boolean isNeedNotifyNewPipeline(@NonNull Pipeline pipeline) { final Person personPipelineCreator = pipeline.getPerson(); return notificationStatus.contains(pipeline.getStatus()) // Пайплайн имеет статус необходимый для уведомления - && checkNotNull(personPipelineCreator) // Создатель пайплайна не null - && personInformation.getId().equals(personPipelineCreator.getId()); // Пользователь приложения является инициатором пайплайна + && checkNotNull(personPipelineCreator) // Создатель пайплайна не null + && personInformation.getId().equals(personPipelineCreator.getId()) // Пользователь приложения является инициатором пайплайна + && LocalDateTime.now().minusDays(1).isBefore(pipeline.getCreated()); // Пайплан был создан не более 24 часов назад } @Override @@ -128,7 +129,7 @@ public class PipelineServiceImpl implements PipelineService { @Override public void cleanOld() { log.debug("Старт очистки старых пайплайнов"); - repository.deleteByCreatedBefore(LocalDateTime.now().minusDays(1L)); + repository.deleteByCreatedBefore(LocalDateTime.now().minusDays(7L)); log.debug("Конец очистки старых пайплайнов"); } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java index 7db61fc..4e25be2 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java @@ -35,6 +35,7 @@ import static dev.struchkov.haiti.utils.Checker.checkFalse; import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResult; import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResults; +import static java.util.stream.Collectors.toMap; /** * Парсер пайплайнов. @@ -79,7 +80,7 @@ public class PipelineParser { final Set projectIds = projectService.getAllIdByProcessingEnable(); final Map pipelineProjectMap = getPipelineShortJsons(projectIds).stream() - .collect(Collectors.toMap(PipelineShortJson::getId, PipelineShortJson::getProjectId)); + .collect(toMap(PipelineShortJson::getId, PipelineShortJson::getProjectId)); if (checkNotEmpty(pipelineProjectMap)) { final ExistContainer existContainer = pipelineService.existsById(pipelineProjectMap.keySet()); @@ -99,14 +100,16 @@ public class PipelineParser { log.debug("Конец обработки новых пайплайнов"); } - private List getNewPipelines(Map pipelineProjectMap, Set idsNotFound) { + private List getNewPipelines(Map pipelineIdAndProjectId, Set idsNotFound) { final List>> tasks = idsNotFound.stream() - .map(pipelineId -> new GetPipelineTask( - gitlabProperty.getPipelineUrl(), - pipelineProjectMap.get(pipelineId), - pipelineId, - personProperty.getToken() - )) + .map( + pipelineId -> GetPipelineTask.builder() + .pipelineId(pipelineId) + .projectId(pipelineIdAndProjectId.get(pipelineId)) + .urlPipeline(gitlabProperty.getPipelineUrl()) + .gitlabToken(personProperty.getToken()) + .build() + ) .map(forkJoinPool::submit) .collect(Collectors.toList()); @@ -117,7 +120,7 @@ public class PipelineParser { } private List getPipelineShortJsons(Set projectIds) { - LocalDateTime newLastUpdate = LocalDateTime.now(); + final LocalDateTime newLastUpdate = LocalDateTime.now(); final List>> tasks = projectIds.stream() .map(projectId -> new GetPipelineShortTask( gitlabProperty.getPipelinesUrl(), @@ -141,12 +144,13 @@ public class PipelineParser { final List>> tasks = pipelines.stream() .map( - pipeline -> new GetPipelineTask( - gitlabProperty.getPipelineUrl(), - pipeline.getProjectId(), - pipeline.getId(), - personProperty.getToken() - ) + pipeline -> + GetPipelineTask.builder() + .projectId(pipeline.getProjectId()) + .pipelineId(pipeline.getId()) + .urlPipeline(gitlabProperty.getPipelineUrl()) + .gitlabToken(gitlabProperty.getPipelineUrl()) + .build() ) .map(forkJoinPool::submit) .collect(Collectors.toList()); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetPipelineTask.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetPipelineTask.java index 8e43d22..5da19dc 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetPipelineTask.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetPipelineTask.java @@ -3,7 +3,10 @@ package dev.struchkov.bot.gitlab.core.service.parser.forktask; import dev.struchkov.bot.gitlab.core.utils.HttpParse; import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.bot.gitlab.sdk.domain.PipelineJson; -import lombok.RequiredArgsConstructor; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -15,13 +18,15 @@ import static dev.struchkov.bot.gitlab.core.utils.HttpParse.ACCEPT; @Slf4j -@RequiredArgsConstructor +@Builder +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class GetPipelineTask extends RecursiveTask> { - private final String urlPipeline; - private final long projectId; - private final long pipelineId; - private final String gitlabToken; + private String urlPipeline; + private long projectId; + private long pipelineId; + private String gitlabToken; @Override @SneakyThrows diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/HttpParse.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/HttpParse.java index f3e8866..e86fed1 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/HttpParse.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/utils/HttpParse.java @@ -3,6 +3,7 @@ package dev.struchkov.bot.gitlab.core.utils; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import dev.struchkov.haiti.utils.Inspector; +import jakarta.validation.constraints.NotNull; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -15,6 +16,7 @@ import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.concurrent.TimeUnit; import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Inspector.isNotNull; @@ -77,7 +79,7 @@ public class HttpParse { final HttpUrl url = httpUrlBuilder.build(); final Request request = requestBuilder.url(url).build(); log.trace("Выполняется okhttp3 запрос | {}", url); - final OkHttpClient httpClient = new OkHttpClient(); + final OkHttpClient httpClient = getNewClient(); try (final Response execute = httpClient.newCall(request).execute()) { log.trace("Запрос выполнен | {}", url); if (execute.isSuccessful() && checkNotNull(execute.body())) { @@ -96,7 +98,7 @@ public class HttpParse { final HttpUrl url = httpUrlBuilder.build(); final Request request = requestBuilder.url(url).build(); log.trace("Выполняется okhttp3 запрос | {}", url); - final OkHttpClient httpClient = new OkHttpClient(); + final OkHttpClient httpClient = getNewClient(); try (Response execute = httpClient.newCall(request).execute()) { log.trace("Запрос выполнен | {}", url); ResponseBody body = execute.body(); @@ -111,4 +113,13 @@ public class HttpParse { return Collections.emptyList(); } + @NotNull + private static OkHttpClient getNewClient() { + return new OkHttpClient().newBuilder() + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .build(); + } + } \ No newline at end of file diff --git a/gitlab-app/src/main/resources/application.yml b/gitlab-app/src/main/resources/application.yml index 746ad05..d264543 100644 --- a/gitlab-app/src/main/resources/application.yml +++ b/gitlab-app/src/main/resources/application.yml @@ -19,7 +19,8 @@ spring: logging: level: - "dev.struchkov": ${LOG_LEVEL:info} + "dev.struchkov": ${LOG_LEVEL:INFO} + "dev.struchkov.bot.gitlab": ${APP_LOG_LEVEL:INFO} telegram: bot: @@ -39,9 +40,9 @@ gitlab-bot: version: 1.0.0 cron: scan: - general: "0 */1 * * * *" - new-project: "0 0 */1 * * *" - new-merge-request: "0 */15 * * * *" + general: ${CRON_GENERAL:0 */1 * * * *} + new-project: ${CRON_NEW_PROJECTS:0 0 */1 * * *} + new-merge-request: ${CRON_NEW_MR:0 */15 * * * *} person: telegram-id: ${TELEGRAM_PERSON_ID} token: ${GITLAB_PERSONAL_TOKEN} diff --git a/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-02-06-change-varchar.xml b/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-02-06-change-varchar.xml new file mode 100644 index 0000000..7c35c85 --- /dev/null +++ b/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-02-06-change-varchar.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-08-21-add-milestone.xml b/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-08-21-add-milestone.xml new file mode 100644 index 0000000..0686992 --- /dev/null +++ b/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-08-21-add-milestone.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml b/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml index 67c13df..26c582a 100644 --- a/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml +++ b/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml @@ -3,10 +3,12 @@ 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"> - + + + \ No newline at end of file diff --git a/gitlab-sdk/src/main/java/dev/struchkov/bot/gitlab/sdk/domain/MergeRequestJson.java b/gitlab-sdk/src/main/java/dev/struchkov/bot/gitlab/sdk/domain/MergeRequestJson.java index 73b125f..aec5c0b 100644 --- a/gitlab-sdk/src/main/java/dev/struchkov/bot/gitlab/sdk/domain/MergeRequestJson.java +++ b/gitlab-sdk/src/main/java/dev/struchkov/bot/gitlab/sdk/domain/MergeRequestJson.java @@ -41,6 +41,7 @@ public class MergeRequestJson { private PersonJson author; private PersonJson assignee; + private MilestoneJson milestone; private List reviewers; @JsonProperty("web_url") diff --git a/gitlab-sdk/src/main/java/dev/struchkov/bot/gitlab/sdk/domain/MilestoneJson.java b/gitlab-sdk/src/main/java/dev/struchkov/bot/gitlab/sdk/domain/MilestoneJson.java new file mode 100644 index 0000000..dd8c889 --- /dev/null +++ b/gitlab-sdk/src/main/java/dev/struchkov/bot/gitlab/sdk/domain/MilestoneJson.java @@ -0,0 +1,9 @@ +package dev.struchkov.bot.gitlab.sdk.domain; + +import lombok.Data; + +@Data +public class MilestoneJson { + private Long id; + private String title; +} diff --git a/pom.xml b/pom.xml index 6c13369..59dd236 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ 1.0.0-SNAPSHOT - 3.0.2 + 3.0.3 1.1.1 0.0.5 @@ -53,12 +53,12 @@ 3.2.0-M1 - 33.0.0-jre + 33.3.0-jre - 3.12.1 + 3.13.0 - 3.0.1 + 3.1.1 diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java index 0711799..f185440 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java @@ -8,6 +8,7 @@ import dev.struchkov.godfather.simple.domain.BoxAnswer; import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; @@ -20,6 +21,7 @@ import java.util.stream.Collectors; * * @author upagge 17.09.2020 */ +@Slf4j @Service public class MessageSendTelegramService implements MessageSendService { @@ -45,6 +47,7 @@ public class MessageSendTelegramService implements MessageSendService { final BoxAnswer answer = generator.generate(notify); answer.setRecipientIfNull(personInformation.getTelegramId()); answer.addPayload(BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW, true); + log.debug("Будет отправлено следующее уведомление: {}. Текст: {}", answer, answer.getMessage()); return answer; }) .ifPresent(sending::send); diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java index d4f91a3..78756ac 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java @@ -5,27 +5,21 @@ import dev.struchkov.bot.gitlab.context.utils.Icons; import dev.struchkov.bot.gitlab.core.config.properties.AppProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.godfather.simple.domain.BoxAnswer; -import dev.struchkov.godfather.simple.domain.SentBox; import dev.struchkov.godfather.telegram.domain.ClientBotCommand; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import dev.struchkov.godfather.telegram.simple.context.service.TelegramService; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; import org.springframework.stereotype.Component; import java.util.List; -import java.util.Optional; -import java.util.UUID; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE; import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.domain.keyboard.button.SimpleButton.simpleButton; import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW; -import static dev.struchkov.haiti.utils.Checker.checkNotBlank; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN; /** * @author upagge 19.01.2021 @@ -35,8 +29,6 @@ import static dev.struchkov.haiti.utils.Checker.checkNotBlank; @RequiredArgsConstructor public class StartNotify { - private final OkHttpClient client = new OkHttpClient(); - private final TelegramSending sending; private final TelegramService telegramService; @@ -62,56 +54,10 @@ public class StartNotify { simpleButton("Open Menu", "/start") ) ) - .payload(DISABLE_WEB_PAGE_PREVIEW, true) + .payload(ENABLE_MARKDOWN) + .payload(DISABLE_WEB_PAGE_PREVIEW) .build(); sending.send(boxAnswer); - sendNotice(); - } - registrationForStatistic(); - } - - - /** - * Отправляет service_key для сбора анонимной статистики использования. - */ - private void registrationForStatistic() { - final UUID serviceKey = settingService.getServiceKey(); - final boolean firstStart = settingService.isFirstStart(); - final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/registration?key=" + serviceKey + "&initFlow=" + firstStart; - final Request request = new Request.Builder().get().url(requestUrl).build(); - try { - client.newCall(request).execute(); - } catch (Exception e) { - log.warn(e.getMessage()); - } - } - - /** - * Используется для уведомления пользователя о выходе новой версии. - */ - private void sendNotice() { - final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/start-notice"; - final Request request = new Request.Builder().get().url(requestUrl).build(); - try { - final Response response = client.newCall(request).execute(); - if (response.code() == 200) { - final String noticeMessage = response.body().string(); - if (checkNotBlank(noticeMessage)) { - final BoxAnswer notice = BoxAnswer.builder() - .message(noticeMessage) - .recipientPersonId(personProperty.getTelegramId()) - .payload(DISABLE_WEB_PAGE_PREVIEW, true) - .build(); - final Optional optSentBox = sending.send(notice); - if (optSentBox.isPresent()) { - final SentBox sentBox = optSentBox.get(); - final String messageId = sentBox.getMessageId(); - telegramService.pinMessage(personProperty.getTelegramId(), messageId); - } - } - } - } catch (Exception e) { - log.warn(e.getMessage()); } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java index d616bba..4066383 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java @@ -9,11 +9,12 @@ import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_CONFIRMAT import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_DISABLE_NOTIFY_MR_ID; import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_VALUE_FALSE; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE; -import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.domain.keyboard.SimpleKeyBoardLine.keyBoardLine; import static dev.struchkov.godfather.telegram.domain.keyboard.button.SimpleButton.simpleButton; import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; @Component @@ -26,20 +27,28 @@ public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator reviewers = notify.getReviewers(); if (checkNotEmpty(reviewers)) { builder.append(Icons.REVIEWER).append(": ").append(String.join(", ", reviewers)).append("\n"); diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java index cb4ab76..de9bc7b 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java @@ -11,11 +11,11 @@ import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_CONFIRMAT import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_DISABLE_NOTIFY_MR_ID; import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_VALUE_FALSE; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE; -import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.domain.keyboard.SimpleKeyBoardLine.keyBoardLine; import static dev.struchkov.godfather.telegram.domain.keyboard.button.SimpleButton.simpleButton; import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN; import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; @@ -31,7 +31,7 @@ public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator> notes) { diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java index 7ba36ef..87b2871 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java @@ -11,11 +11,11 @@ import org.springframework.stereotype.Service; import java.util.Optional; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE; -import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.domain.keyboard.SimpleKeyBoardLine.keyBoardLine; import static dev.struchkov.godfather.telegram.domain.keyboard.button.SimpleButton.simpleButton; import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN; @Service @RequiredArgsConstructor @@ -42,15 +42,16 @@ public class PipelineNotifyGenerator implements NotifyBoxAnswerGeneratorbuilder() .triggerCheck( mail -> { - final List forwardMails = mail.getForwardMail(); - if (Checker.checkNotNull(forwardMails) && forwardMails.size() == 1) { - final Mail forwardMail = forwardMails.get(0); - final boolean isLink = Attachments.findFirstLink(forwardMail.getAttachments()) - .isPresent(); + final Mail replay = mail.getReplayMail(); + if (checkNotNull(replay)) { + final boolean isLink = Attachments.findFirstLink(replay.getAttachments()).isPresent(); if (isLink) { final boolean isAccess = personInformation.getTelegramId().equals(mail.getFromPersonId()); final boolean firstStart = settingService.isFirstStart(); @@ -56,7 +53,7 @@ public class AnswerNoteUnit implements PersonUnitConfiguration { ) .answer( mail -> { - final String noteUrl = Attachments.findFirstLink(mail.getForwardMail().get(0).getAttachments()) + final String noteUrl = Attachments.findFirstLink(mail.getReplayMail().getAttachments()) .map(LinkAttachment::getUrl) .orElseThrow(); final Matcher matcher = NOTE_LINK.matcher(noteUrl); diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DeleteMessageUnit.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DeleteMessageUnit.java index 0c3af65..eb7cbba 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DeleteMessageUnit.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DeleteMessageUnit.java @@ -44,7 +44,8 @@ public class DeleteMessageUnit implements PersonUnitConfiguration { }) .answer(mail -> { final ButtonClickAttachment clickButton = Attachments.findFirstButtonClick(mail.getAttachments()).orElseThrow(); - telegramSending.deleteMessage(mail.getFromPersonId(), clickButton.getMessage().getId()); + //TODO [21.08.2024|uPagge]: fixme + telegramSending.deleteMessage(mail.getFromPersonId(), clickButton.getMessage().get().getId()); }) .build(); } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyMrUnit.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyMrUnit.java index 71fc377..909ab97 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyMrUnit.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyMrUnit.java @@ -77,7 +77,8 @@ public class DisableNotifyMrUnit implements PersonUnitConfiguration { if (confirmation) { mergeRequestsService.notification(false, mrId); - scheduledExecutorService.schedule(() -> telegramSending.deleteMessage(mail.getFromPersonId(), clickButton.getMessage().getId()), 5, TimeUnit.SECONDS); + //TODO [21.08.2024|uPagge]: fixme + scheduledExecutorService.schedule(() -> telegramSending.deleteMessage(mail.getFromPersonId(), clickButton.getMessage().get().getId()), 5, TimeUnit.SECONDS); return replaceBoxAnswer(SUCCESSFULLY_DISABLED); } else { return replaceBoxAnswer( diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyThreadUnit.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyThreadUnit.java index 075802d..ce8d2f2 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyThreadUnit.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/command/DisableNotifyThreadUnit.java @@ -73,7 +73,8 @@ public class DisableNotifyThreadUnit implements PersonUnitConfiguration { if (confirmation) { discussionService.notification(false, discussionId); - scheduledExecutorService.schedule(() -> telegramSending.deleteMessage(mail.getFromPersonId(), clickButton.getMessage().getId()), 5, TimeUnit.SECONDS); + //TODO [21.08.2024|uPagge]: fixme + scheduledExecutorService.schedule(() -> telegramSending.deleteMessage(mail.getFromPersonId(), clickButton.getMessage().get().getId()), 5, TimeUnit.SECONDS); return replaceBoxAnswer(SUCCESSFULLY_DISABLED); } else { return replaceBoxAnswer( diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/flow/InitSettingFlow.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/flow/InitSettingFlow.java index 84a5d5c..bf035d7 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/flow/InitSettingFlow.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/flow/InitSettingFlow.java @@ -24,6 +24,7 @@ import dev.struchkov.godfather.telegram.starter.PersonUnitConfiguration; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -218,6 +219,8 @@ public class InitSettingFlow implements PersonUnitConfiguration { final String personId = mail.getFromPersonId(); final String messageId = Attachments.findFirstButtonClick(mail.getAttachments()) .map(ButtonClickAttachment::getMessage) + //TODO [21.08.2024|uPagge]: fixme + .map(Optional::get) .map(Mail::getId) .orElseThrow(); sending.send( @@ -407,6 +410,8 @@ public class InitSettingFlow implements PersonUnitConfiguration { final String personId = mail.getFromPersonId(); final String messageId = Attachments.findFirstButtonClick(mail.getAttachments()) .map(ButtonClickAttachment::getMessage) + //TODO [21.08.2024|uPagge]: fixme + .map(Optional::get) .map(Message::getId) .orElseThrow(); sending.send(