Skip to content

Commit

Permalink
feat: Implement second step if automatic action GitHub events - MEED-…
Browse files Browse the repository at this point in the history
…2964 - Meeds-io/MIPs#105 (#148)

Fix feedbacks
  • Loading branch information
AzmiTouil authored Jan 11, 2024
1 parent 1fd8e0b commit 1d7f615
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import java.util.*;
import java.util.stream.Collectors;

import io.meeds.gamification.model.EventDTO;
import io.meeds.gamification.service.EventService;
import io.meeds.gamification.model.RuleDTO;
import io.meeds.gamification.model.filter.RuleFilter;
import io.meeds.gamification.service.RuleService;
import io.meeds.gamification.utils.Utils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -58,13 +59,17 @@ public class WebhookServiceImpl implements WebhookService {
private final WebHookStorage webHookStorage;

private final GithubConsumerService githubServiceConsumer;

private final RuleService ruleService;

public WebhookServiceImpl(SettingService settingService,
WebHookStorage webHookStorage,
GithubConsumerService githubServiceConsumer) {
GithubConsumerService githubServiceConsumer,
RuleService ruleService) {
this.settingService = settingService;
this.webHookStorage = webHookStorage;
this.githubServiceConsumer = githubServiceConsumer;
this.ruleService = ruleService;
}

public List<WebHook> getWebhooks(String currentUser, int offset, int limit, boolean forceUpdate) throws IllegalAccessException {
Expand Down Expand Up @@ -174,6 +179,15 @@ public void deleteWebhookHook(long organizationId, String currentUser) throws Il

public void deleteWebhook(long organizationId) {
webHookStorage.deleteWebHook(organizationId);
RuleFilter ruleFilter = new RuleFilter(true);
ruleFilter.setEventType(CONNECTOR_NAME);
ruleFilter.setIncludeDeleted(true);
List<RuleDTO> rules = ruleService.getRules(ruleFilter, 0, -1);
rules.stream()
.filter(r -> !r.getEvent().getProperties().isEmpty()
&& r.getEvent().getProperties().get(ORGANIZATION_ID).equals(String.valueOf(organizationId)))
.map(RuleDTO::getId)
.forEach(ruleService::deleteRuleById);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class Utils {
public static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";

public static final String ORGANIZATION = "organization";

public static final String ORGANIZATION_ID = "organizationId";

public static final String REPOSITORY = "repository";

Expand Down

0 comments on commit 1d7f615

Please sign in to comment.