-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from Broscorp-net/trigger-pull-request-check
Trigger pull request check
- Loading branch information
Showing
23 changed files
with
621 additions
and
268 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
bot/src/main/java/com/community/tools/controller/GitHubHookEventController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
30 changes: 0 additions & 30 deletions
30
bot/src/main/java/com/community/tools/controller/GithubHookController.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
bot/src/main/java/com/community/tools/dto/events/tasks/TaskStatusChangeEventDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mmunity/tools/model/stats/UserTaskId.java → ...munity/tools/model/status/UserTaskId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
.../repository/stats/UserTaskRepository.java → ...repository/status/UserTaskRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
bot/src/main/java/com/community/tools/service/MentorNotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.