Dockerfile

This commit is contained in:
uPagge 2021-01-15 23:52:32 +03:00
parent 0e15b27095
commit e71f767fce
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
10 changed files with 53 additions and 101 deletions

View File

@ -1,6 +1,24 @@
FROM openjdk:8-jdk-alpine FROM openjdk:8-jdk-alpine
MAINTAINER uPagge MAINTAINER uPagge <me@upagge.ru>
RUN addgroup -S bitbucketbot && adduser -S bitbucketbot -G bitbucketbot RUN apk add --no-cache bash && \
USER bitbucketbot:bitbucketbot addgroup -S gitlabbot && \
COPY target/bitbucketbot.jar app.jar adduser -S gitlabbot -G gitlabbot && \
ENTRYPOINT ["java", "-jar", "", "app.jar"] mkdir -p /bot && \
chown -R gitlabbot:gitlabbot /bot
WORKDIR /bot
USER gitlabbot:gitlabbot
COPY target/gitlab-notification.jar app.jar
VOLUME logs
ENV TELEGRAM_PERSON_ID=TELEGRAM_PERSON_ID DATASOURCE_URL=DATASOURCE_URL \
DATASOURCE_PASSWORD=DATASOURCE_PASSWORD DATASOURCE_USERNAME=DATASOURCE_USERNAME \
GITLAB_PERSONAL_TOKEN=GITLAB_PERSONAL_TOKEN TELEGRAM_BOT_TOKEN=TELEGRAM_BOT_TOKEN \
TELEGRAM_BOT_USERNAME=TELEGRAM_BOT_USERNAME GITLAB_URL=GITLAB_URL
ENTRYPOINT java -DTELEGRAM_BOT_USERNAME=${TELEGRAM_BOT_USERNAME} \
-DTELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN \
-DTELEGRAM_PERSON_ID=$TELEGRAM_PERSON_ID \
-DDATASOURCE_URL=$DATASOURCE_URL \
-DDATASOURCE_PASSWORD=$DATASOURCE_PASSWORD \
-DDATASOURCE_USERNAME=$DATASOURCE_USERNAME \
-DGITLAB_PERSONAL_TOKEN=$GITLAB_PERSONAL_TOKEN \
-DGITLAB_URL=$GITLAB_URL \
-jar app.jar

View File

@ -1,29 +0,0 @@
package org.sadtech.bot.gitlab.app.scheduler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* Позволяет задать время парсинга для ПРов.
*
* @author upagge 06.09.2020
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PullRequestParserScheduler {
// private final PullRequestParser pullRequestParser;
//
// @Scheduled(cron = "0 */1 * * * *")
// public void parsingOldPullRequest() {
// pullRequestParser.parsingOldPullRequest();
// }
//
// @Scheduled(cron = "0 */1 * * * *")
// public void parsingNewPullRequest() {
// pullRequestParser.parsingNewPullRequest();
// }
}

View File

@ -30,4 +30,9 @@ public class SchedulerService {
mergeRequestParser.parsingNewMergeRequest(); mergeRequestParser.parsingNewMergeRequest();
} }
@Scheduled(cron = "*/30 * * * * *")
public void oldMergeRequest() {
mergeRequestParser.parsingOldMergeRequest();
}
} }

View File

@ -2,6 +2,7 @@ package org.sadtech.bot.gitlab.app.service.parser;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState; import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.entity.Project; import org.sadtech.bot.gitlab.context.domain.entity.Project;
@ -11,6 +12,7 @@ import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson; import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson;
import org.sadtech.haiti.context.domain.ExistsContainer; import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.context.exception.NotFoundException;
import org.sadtech.haiti.context.page.Sheet; import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.core.page.PaginationImpl; import org.sadtech.haiti.core.page.PaginationImpl;
import org.sadtech.haiti.utils.network.HttpHeader; import org.sadtech.haiti.utils.network.HttpHeader;
@ -45,8 +47,19 @@ public class MergeRequestParser {
private final ConversionService conversionService; private final ConversionService conversionService;
private final PersonProperty personProperty; private final PersonProperty personProperty;
public void parsingOldPullRequest() { public void parsingOldMergeRequest() {
// processingOldPullRequests(gitlabProperty.getUrlPullRequestOpen(), gitlabProperty.getUrlPullRequestClose()); final Set<IdAndStatusPr> existIds = mergeRequestsService.getAllId(OLD_STATUSES);
for (IdAndStatusPr existId : existIds) {
final MergeRequest mergeRequest = HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequest(), existId.getProjectId(), existId.getTwoId()))
.header(ACCEPT)
.header(AUTHORIZATION, BEARER + personProperty.getToken())
.execute(MergeRequestJson.class)
.map(json -> conversionService.convert(json, MergeRequest.class))
.orElseThrow(() -> new NotFoundException("МержРеквест не найден, возможно удален"));
mergeRequestsService.update(mergeRequest);
}
} }
public void parsingNewMergeRequest() { public void parsingNewMergeRequest() {
@ -88,51 +101,4 @@ public class MergeRequestParser {
} }
// private Set<Long> getExistsPullRequestIds(String bitbucketUrl) {
// Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(url, token, PullRequestSheetJson.class);
// Set<Long> ids = new HashSet<>();
// while (sheetJson.isPresent() && sheetJson.get().hasContent()) {
// final PullRequestSheetJson jsonSheet = sheetJson.get();
// final List<PullRequest> existsPr = getExistsPr(jsonSheet.getValues());
//
// ids.addAll(
// pullRequestsService.updateAll(existsPr).stream()
// .map(PullRequest::getId)
// .collect(Collectors.toSet())
// );
//
// if (jsonSheet.getNextPageStart() != null) {
// sheetJson = Utils.urlToJson(url + jsonSheet.getNextPageStart(), token, PullRequestSheetJson.class);
// } else {
// break;
// }
// }
// return ids;
// }
//
// public void processingOldPullRequests(@NonNull String urlPullRequestOpen, @NonNull String urlPullRequestClose) {
// final Set<Long> existsId = pullRequestsService.getAllId(OLD_STATUSES).stream()
// .map(IdAndStatusPr::getId)
// .collect(Collectors.toSet());
// final Set<Long> openId = getExistsPullRequestIds(urlPullRequestOpen);
// final Set<Long> closeId = getExistsPullRequestIds(urlPullRequestClose);
// final Set<Long> newNotExistsId = existsId.stream()
// .filter(id -> !openId.contains(id) && !closeId.contains(id))
// .collect(Collectors.toSet());
// log.info("Открыты: " + Arrays.toString(openId.toArray()));
// log.info("Закрыты: " + Arrays.toString(closeId.toArray()));
// log.info("Не найдены: " + Arrays.toString(newNotExistsId.toArray()));
// if (!newNotExistsId.isEmpty() && !openId.isEmpty()) {
// pullRequestsService.deleteAllById(newNotExistsId);
// }
// }
//
// private List<PullRequest> getExistsPr(@NonNull List<PullRequestJson> pullRequestJsons) {
// return pullRequestJsons.stream()
// .filter(json -> pullRequestsService.exists(bitbucketIdAndPullRequestId(json)))
// .map(json -> conversionService.convert(json, PullRequest.class))
// .collect(Collectors.toList());
// }
//
} }

View File

@ -36,7 +36,7 @@ gitlab-bot:
url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened
url-pull-request-close: ${GITLAB_URL} url-pull-request-close: ${GITLAB_URL}
url-pull-request-comment: ${GITLAB_URL} url-pull-request-comment: ${GITLAB_URL}
url-pull-request: ${GITLAB_URL} url-pull-request: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests/{1}
user-url: ${GITLAB_URL}/api/v4/user user-url: ${GITLAB_URL}/api/v4/user
users-url: ${GITLAB_URL}/api/v4/users users-url: ${GITLAB_URL}/api/v4/users
teamcity: teamcity:

View File

@ -10,6 +10,8 @@ import lombok.Setter;
public class IdAndStatusPr { public class IdAndStatusPr {
private Long id; private Long id;
private Long twoId;
private Long projectId;
private MergeRequestState status; private MergeRequestState status;
} }

View File

@ -13,7 +13,7 @@ import java.util.Set;
public interface MergeRequestRepository extends SimpleManagerRepository<MergeRequest, Long>, FilterOperation<MergeRequest> { public interface MergeRequestRepository extends SimpleManagerRepository<MergeRequest, Long>, FilterOperation<MergeRequest> {
Set<IdAndStatusPr> findAllIdByStatusIn(Set<MergeRequestState> statuses); Set<IdAndStatusPr> findAllIdByStateIn(Set<MergeRequestState> states);
Optional<MergeRequestMini> findMiniInfoById(@NonNull Long id); Optional<MergeRequestMini> findMiniInfoById(@NonNull Long id);

View File

@ -85,7 +85,8 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
@Override @Override
public MergeRequest update(@NonNull MergeRequest mergeRequest) { public MergeRequest update(@NonNull MergeRequest mergeRequest) {
final MergeRequest oldMergeRequest = findAndFillId(mergeRequest); final MergeRequest oldMergeRequest = mergeRequestRepository.findById(mergeRequest.getId())
.orElseThrow(() -> new NotFoundException("МержРеквест не найден"));
// forgottenNotification(oldMergeRequest); // forgottenNotification(oldMergeRequest);
@ -163,7 +164,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
@Override @Override
public Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses) { public Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses) {
return null; return mergeRequestRepository.findAllIdByStateIn(statuses);
} }
@Override @Override
@ -191,15 +192,4 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
return filterService.count(pullRequestFilter); return filterService.count(pullRequestFilter);
} }
protected MergeRequest findAndFillId(@NonNull MergeRequest mergeRequest) {
// return pullRequestsRepository.findFirst(
// CriteriaFilter.create().and(
// CriteriaQuery.create()
// .matchPhrase("hyita", mergeRequest.getBitbucketId())
// .matchPhrase("hyita", mergeRequest.getRepositoryId())
// )
// ).orElseThrow(() -> new UpdateException("ПР с таким id не существует"));
return null;
}
} }

View File

@ -27,7 +27,7 @@ public class MergeRequestRepositoryImpl extends FilterManagerRepository<MergeReq
} }
@Override @Override
public Set<IdAndStatusPr> findAllIdByStatusIn(Set<MergeRequestState> statuses) { public Set<IdAndStatusPr> findAllIdByStateIn(Set<MergeRequestState> statuses) {
return repositoryJpa.findAllIdByStateIn(statuses); return repositoryJpa.findAllIdByStateIn(statuses);
} }

View File

@ -21,8 +21,8 @@ public interface MergeRequestJpaRepository extends JpaRepositoryImplementation<M
void deleteAllByIdIn(Collection<Long> id); void deleteAllByIdIn(Collection<Long> id);
@Query("SELECT new org.sadtech.bot.gitlab.context.domain.IdAndStatusPr(p.id, p.state) FROM MergeRequest p WHERE p.state IN :statuses") @Query("SELECT new org.sadtech.bot.gitlab.context.domain.IdAndStatusPr(p.id, p.twoId, p.projectId, p.state) FROM MergeRequest p WHERE p.state IN :states")
Set<IdAndStatusPr> findAllIdByStateIn(@Param("statuses") Set<MergeRequestState> statuses); Set<IdAndStatusPr> findAllIdByStateIn(@Param("states") Set<MergeRequestState> states);
@Query("SELECT p.id from MergeRequest p") @Query("SELECT p.id from MergeRequest p")
Set<Long> findAllIds(); Set<Long> findAllIds();