Skip to content

Commit

Permalink
Merge pull request #311 from Broscorp-net/trigger-pull-request-check
Browse files Browse the repository at this point in the history
Trigger pull request check
  • Loading branch information
VsevladHort authored Feb 1, 2024
2 parents b8396af + 9fb7ba0 commit e533033
Show file tree
Hide file tree
Showing 23 changed files with 621 additions and 268 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.community.tools.controller;

import com.community.tools.service.github.event.GitHubHookEventService;
import com.community.tools.service.github.event.TaskStatusChangeEventDispatcher;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/gitHook")
@Slf4j
public class GitHubHookEventController {

private final TaskStatusChangeEventDispatcher eventDispatcher;
private final GitHubHookEventService gitHubHookEventService;

/**
* Method receives and processes webhook event data from GitHub in JSON format.
*
* @param body event body
* @param eventType header indicating event type
*/
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
public void getHookData(@RequestHeader("X-GitHub-Event") String eventType,
@RequestBody String body) {
JSONObject eventJson = new JSONObject(body);
gitHubHookEventService.processGitHubHookEventData(eventJson, eventType)
.ifPresent(eventDispatcher::dispatchEvent);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.community.tools.dto.events.tasks;

import com.community.tools.model.TaskStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@Builder
public class TaskStatusChangeEventDto {

@NonNull
private String taskName;
@NonNull
private String traineeGitName;
@NonNull
private String pullUrl;
private boolean withNewChanges;
@NonNull
private TaskStatus taskStatus;
private String reviewerGitName;
}
7 changes: 5 additions & 2 deletions bot/src/main/java/com/community/tools/model/Mentors.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package com.community.tools.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "mentors")
public class Mentors {

@Id
private String gitNick;
@Column(unique = true)
private String discordName;
private String slackId;

public Mentors() {}

}
4 changes: 4 additions & 0 deletions bot/src/main/java/com/community/tools/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.time.LocalDate;
import java.util.Date;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import lombok.Getter;
Expand All @@ -22,6 +24,8 @@ public class User {
private String gitName;
private LocalDate dateRegistration;
private LocalDate dateLastActivity;
@OneToMany
private Set<Mentors> mentors;
@JsonIgnore
private byte[] stateMachine;
private Integer karma = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.community.tools.model.stats;
package com.community.tools.model.status;

import java.time.LocalDate;
import javax.persistence.Entity;
Expand All @@ -22,4 +22,5 @@ public class UserTask {
private LocalDate lastActivity;
private String pullUrl;
private String taskStatus;
private String headCommitId;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.community.tools.model.stats;
package com.community.tools.model.status;

import java.io.Serializable;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

@Repository
public interface MentorsRepository extends JpaRepository<Mentors, Long> {

Optional<Mentors> findByGitNick(String gitNick);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.community.tools.repository.stats;
package com.community.tools.repository.status;

import com.community.tools.model.stats.UserTask;
import com.community.tools.model.stats.UserTaskId;
import com.community.tools.model.status.UserTask;
import com.community.tools.model.status.UserTaskId;
import java.time.LocalDate;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.community.tools.service;

import com.community.tools.model.User;
import com.community.tools.repository.MentorsRepository;
import com.community.tools.repository.UserRepository;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class MentorNotificationService {

private final MessageService<MessageEmbed> messageService;
private final MentorsRepository mentorsRepository;
private final UserRepository userRepository;

/**
* Sends notifications to all mentors of the trainee identified by the given git name. If no
* mentor is associated with the trainee, the notification message is sent to all mentors the
* system is aware of.
*
* @param traineeGitName git login of the trainee.
* @param message message to be sent to mentors associated with the trainee.
*/
public void notifyAllTraineeMentors(String traineeGitName, String message) {
Optional<User> maybeTrainee = userRepository.findByGitName(traineeGitName);
maybeTrainee.ifPresent(trainee -> {
if (trainee.getMentors().isEmpty()) {
notifyAllMentors(message);
} else {
trainee.getMentors().forEach(
mentor -> mentorsRepository.findByGitNick(mentor.getGitNick())
.ifPresent(it -> messageService.sendPrivateMessage(it.getDiscordName(), message)));
}
});
}

/**
* Sends notification with a specified message to all mentors.
*
* @param message message to be sent to mentors.
*/
public void notifyAllMentors(String message) {
mentorsRepository.findAll().forEach(mentor -> {
if (mentor.getDiscordName() != null) {
messageService.sendPrivateMessage(mentor.getDiscordName(),
message);
}
});
}

/**
* Attempts to send a message to the mentor identified by the given mentorGitName is such mentor
* can be found on the record.
*
* @param mentorGitName mentor to be notified.
* @param message message to be sent to the mentor.
*/
public void notifyMentor(String mentorGitName, String message) {
mentorsRepository.findByGitNick(mentorGitName)
.ifPresent(mentors -> messageService.sendPrivateMessage(mentors.getDiscordName(), message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.community.tools.dto.UserForTaskStatusDto;
import com.community.tools.model.TaskNameAndStatus;
import com.community.tools.model.TaskStatus;
import com.community.tools.model.stats.UserTask;
import com.community.tools.repository.stats.UserTaskRepository;
import com.community.tools.model.status.UserTask;
import com.community.tools.repository.status.UserTaskRepository;
import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ private String getLastPullUrl(GHRepository repository) {

private Optional<GHWorkflowRun> getWorkflowRun(GHRepository repository) {
try {
log.info(repository.getName());
Iterator<GHWorkflowRun> workflowRunIterator = repository
.getWorkflow(classroomWorkflow)
.listRuns()
Expand Down
Loading

0 comments on commit e533033

Please sign in to comment.