Skip to content

Commit

Permalink
Developer notifications: Slack bot with weekly post (#129)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Felix T.J. Dietrich <[email protected]>
Co-authored-by: Felix T.J. Dietrich <[email protected]>
  • Loading branch information
4 people authored Nov 11, 2024
1 parent ee0d907 commit 13bf668
Show file tree
Hide file tree
Showing 24 changed files with 490 additions and 88 deletions.
18 changes: 14 additions & 4 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ paths:
parameters:
- name: after
in: query
required: false
required: true
schema:
type: string
format: date
format: date-time
- name: before
in: query
required: false
required: true
schema:
type: string
format: date
format: date-time
- name: repository
in: query
required: false
Expand Down Expand Up @@ -258,12 +258,20 @@ components:
htmlUrl:
type: string
MetaData:
required:
- repositoriesToMonitor
- scheduledDay
- scheduledTime
type: object
properties:
repositoriesToMonitor:
type: array
items:
type: string
scheduledDay:
type: string
scheduledTime:
type: string
PullRequestBaseInfo:
required:
- htmlUrl
Expand Down Expand Up @@ -319,6 +327,8 @@ components:
format: int64
login:
type: string
email:
type: string
avatarUrl:
type: string
name:
Expand Down
5 changes: 5 additions & 0 deletions server/application-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
<artifactId>jnats</artifactId>
<version>2.20.2</version>
</dependency>
<dependency>
<groupId>com.slack.api</groupId>
<artifactId>bolt</artifactId>
<version>1.44.1</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GitHubConfig {

private static final Logger logger = LoggerFactory.getLogger(GitHubConfig.class);

@Value("${github.authToken}")
@Value("${github.auth-token}")
private String ghAuthToken;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.tum.in.www1.hephaestus.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.slack.api.bolt.App;
import com.slack.api.bolt.AppConfig;

@Configuration
public class SlackAppConfig {
@Value("${slack.token}")
private String botToken;

@Value("${slack.signing-secret}")
private String signingSecret;

@Bean
public App initSlackApp() {
if (botToken == null || signingSecret == null || botToken.isEmpty() || signingSecret.isEmpty()) {
return new App();
}
return new App(AppConfig.builder().singleTeamBotToken(botToken).signingSecret(signingSecret).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public record UserInfoDTO(
@NonNull Long id,
@NonNull String login,
String email,
@NonNull String avatarUrl,
@NonNull String name,
@NonNull String htmlUrl) {
Expand All @@ -15,6 +16,7 @@ public static UserInfoDTO fromUser(User user) {
return new UserInfoDTO(
user.getId(),
user.getLogin(),
user.getEmail(),
user.getAvatarUrl(),
user.getName(),
user.getHtmlUrl());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package de.tum.in.www1.hephaestus.leaderboard;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -23,8 +24,8 @@ public LeaderboardController(LeaderboardService leaderboardService) {

@GetMapping
public ResponseEntity<List<LeaderboardEntryDTO>> getLeaderboard(
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Optional<LocalDate> after,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Optional<LocalDate> before,
@RequestParam @DateTimeFormat(iso = ISO.DATE_TIME) OffsetDateTime after,
@RequestParam @DateTimeFormat(iso = ISO.DATE_TIME) OffsetDateTime before,
@RequestParam Optional<String> repository) {
return ResponseEntity.ok(leaderboardService.createLeaderboard(after, before, repository));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.util.stream.IntStream;
import java.util.Map;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -43,19 +40,13 @@ public LeaderboardService(
}

@Transactional
public List<LeaderboardEntryDTO> createLeaderboard(Optional<LocalDate> after, Optional<LocalDate> before,
public List<LeaderboardEntryDTO> createLeaderboard(OffsetDateTime after, OffsetDateTime before,
Optional<String> repository) {
logger.info("Creating leaderboard dataset");

LocalDateTime afterCutOff = after.isPresent() ? after.get().atStartOfDay()
: LocalDate.now().minusDays(timeframe).atStartOfDay();
Optional<LocalDateTime> beforeCutOff = before.map(date -> date.plusDays(1).atStartOfDay());

var afterOffset = afterCutOff.atOffset(ZoneOffset.UTC);
var beforeOffset = beforeCutOff.map(b -> b.atOffset(ZoneOffset.UTC)).orElse(OffsetDateTime.now());
List<PullRequestReview> reviews = pullRequestReviewRepository.findAllInTimeframe(afterOffset, beforeOffset,
logger.info("Timeframe: {} - {}", after, before);
List<PullRequestReview> reviews = pullRequestReviewRepository.findAllInTimeframe(after, before,
repository);
List<IssueComment> issueComments = issueCommentRepository.findAllInTimeframe(afterOffset, beforeOffset,
List<IssueComment> issueComments = issueCommentRepository.findAllInTimeframe(after, before,
repository, true);

Map<Long, User> usersById = reviews.stream().map(PullRequestReview::getAuthor)
Expand Down
Loading

0 comments on commit 13bf668

Please sign in to comment.